|
-
January 22nd, 2010, 08:06 AM
#1
[RESOLVED] Generate PDF from binary?
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??!
Code:
protected void GenerateArchivePDF(int value)
{
try {
// 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
binaryWriter.Write(PDFbinary);
binaryWriter.Close();
readStream.Close();
// 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!
Response.Write(binaryReader.ReadInt32());
//pdfWriter.Add(Response.Write(binaryReader.ReadInt32())); // trying to write to PDF!
// Close
binaryReader.Close();
stream.Close();
}
catch (DocumentException de)
{
errorPage.DisplayErrorMsg(de.Message);
}
catch (IOException ioe)
{
errorPage.DisplayErrorMsg(ioe.Message);
}
finally
{
doc.Close();
Response.Redirect("~/Beurteilungsbogen.pdf");
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|