Stream to PDF creates a corrupt or damaged file
I am creating PDF files from stream:
using (Stream file = File.Create($"C:\test.pdf"))
{
CopyStream(myStream, file);
}
public static void CopyStream(Stream input, Stream output)
{
byte[] buffer = new byte[8 * 1024];
int len;
while ((len = input.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, len);
}
}
The files created, but when i can't open it with any program, i get the message that file is not valid, or is corrupted.
What i am doing wrong here?
Thanks in advance