I'm trying to create a PDF file from binary data retrieved from a webservice. The data is successfully retrieved but it is displayed on the page in binary instead of being converted into a PDF file. I am not sure how to make the data appear in the form of a PDF file instead of just as a string. I tried using iTextSharp to create a PDF but am not sure how to get the PDFWriter to write the data from the BinaryWriter??!
protected void GenerateArchivePDF(int value)
// Retrieve data
PDFbinary = archives[value].PDFBitArray;
// Create a new temp file called "test.dat" which contains data imported from webservice
FileStream readStream = File.Create(Server.MapPath("test.dat"));
BinaryWriter binaryWriter = new BinaryWriter(readStream);
// Write the binary data to the file
// Create a new PDF document
doc = new Document(PageSize.A4, 80, 50, 30, 65);
FileStream pdfStream = new FileStream("~/Beurteilungsbogen.pdf", FileMode.Create);
PdfWriter pdfWriter = PdfWriter.GetInstance(doc, pdfStream);
// Import data from newly created file named "test.dat"
stream = File.OpenRead(Server.MapPath("test.dat"));
binaryReader = new BinaryReader(stream);
// Read from file - INSTEAD OF WRITING ON PAGE SHOULD WRITE IN PDF!
//pdfWriter.Add(Response.Write(binaryReader.ReadInt32())); // trying to write to PDF!
catch (DocumentException de)
catch (IOException ioe)
Yes it is. So it's not possible to use my code then? Instead of using a byte buffer (as I originally wanted to do) I imported binary data in the form of an integer and then wrote it to a new file using the BinaryWriter. I then tried to read this file using the BinaryReader but I dont know how to make this appear in the PDF I created??