Reputation: 41
I am trying to create a pdf file using file stream and while the file is being created in the specified folder of the path, when I try to open the file Adobe Reader is throwing the error that I mentioned above in the title. I am not sure what I am doing wrong but I would greatly appreciate it if someone could look into it and help me out. Thank you!. Here is my code for the filestream:
System.IO.FileStream wFile;
byte[] byteData = null;
byteData = Encoding.ASCII.GetBytes("FileStream Test");
string filePath = $"{_ApplicationPath}PrintedResults\\StreamTest5.pdf";
wFile = new FileStream(filePath, FileMode.Create);
wFile.Write(byteData, 0, byteData.Length);
wFile.Close();
using (var fileStream = new FileStream(filePath, FileMode.Open))
{
Console.WriteLine("This is a test stream file");
}
System.Diagnostics.Process.Start(filePath);
Upvotes: 0
Views: 983
Reputation: 121
This is not an answer but I don't have enough reputation to add it as a comment:
You might want to look to 3rd party library offered by http://www.dynamicpdf.com/ Their free evaluation version is quite capable and it is not time limited as they say on their website. With a little more effort you can create quite complicated PDFs with only the evaluation version!
Upvotes: 1
Reputation: 6060
You are writing a text file with the contents "FileStream Test" but naming it with a file extension of ".PDF". This is not a PDF file. It is a text file with a misleading name. Adobe Reader is correctly reporting that it is not a valid PDF.
Upvotes: 2