You might need to specify 'content-length' in the header.
Note that server-side debugging can sometimes insert extra data into the content stream. While this would not cause a problem for HTML, it can corrupt a PDF.
HTTP compression can also compressed the content stream in ways that web browsers understand, but might cause problems for Acrobat.
To diagnose corruption you could try changing the 'content-disposition' to 'attachment', then download the file to see if it will open in Acrobat.
Here is some example code I use for ABCpdf - perhaps you could adapt it to suit your purpose?
Can you tell me more details about the form element "data". because you used Request.Form["data"]
and
if the buffer is a byte array of your image then what are you trying to do with stream.Read() . you can pass the buffer to Response.BinaryWrite straightly..right?.
After presaving data you can use
PDF Duo .NET converter/creator .NET component. It converts HTML to PDF. It up to you how you want to represent the PDF file. You can save the PDF on the disk or convert HTML to PDF and show PDF in the browser window with saving.
So you can use image tag with your picture as a parameter.
// create an instance of converter object
DuoDimension.HtmlToPdf conv = new DuoDimension.HtmlToPdf();
string sHtml = "<img src='yourimage.jpg' width=500 height=300 />";
conv.ImageInfo.ImageScale = 0.8f;
// open the html string and convert it into the pdf
conv.OpenHTML(sHtml );
// that string saves pdf on the disk
// conv.SavePDF("testfifle.pdf");
// show pdf without saving on the disd
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "inline; filename=testfifle.pdf");
Response.BinaryWrite(conv.SavePdf());
Response.Flush();
Response.End();
Response.Close();
Actualy I have generated a report in Flex. On click of Export to PDF button, I am taking snapshot of the report in Flex and converting it into ByteArray. I am sending the resulting ByteArray to my .net application. In my .net application I am getting the
results as Request.Form["data"] as bytearray. Later I am trying to display this bytearray in PDF.
bhappy
Member
28 Points
221 Posts
export byte array to PDF
Apr 13, 2010 12:01 PM|LINK
Hi All,
I am trying to export a byte array to PDF. I can't find the problem but, I am getting a blank PDF page? My code is
response.ClearContent(); response.ClearHeaders(); response.ContentType = "application/pdf"; response.AddHeader("Content-Disposition", "inline; filename=my.pdf"); int count = 0; do { count = stream.Read(buffer, 0, buffer.Length); response.BinaryWrite(buffer); response.Flush(); } while (count!=0); stream.Close(); response.End(); response.Close();Plz some one help me...
ASP.NET
rnivash
Member
312 Points
62 Posts
Re: export byte array to PDF
Apr 13, 2010 02:28 PM|LINK
I have no idea abt your stream object,,try the following code
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> Response.ClearContent();</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> Response.ClearHeaders();</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> Response.ContentType = "application/pdf";</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> Response.AddHeader("Content-Disposition", "inline; filename=my.pdf");</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> int StreamLength;</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> StreamLength = (int)stream.Length;</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> Byte[] buffer = new Byte[StreamLength];</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> stream.Read(buffer, 0, StreamLength);</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> Response.BinaryWrite(buffer);</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> Response.Flush();</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> stream.Close();</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> Response.End();</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> Response.Close();</div>Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "inline; filename=my.pdf");
int StreamLength;
StreamLength = (int)stream.Length;
Byte[] buffer = new Byte[StreamLength];
stream.Read(buffer, 0, StreamLength);
Response.BinaryWrite(buffer);
Response.Flush();
stream.Close();
Response.End();
Response.Close();
bhappy
Member
28 Points
221 Posts
Re: export byte array to PDF
Apr 14, 2010 05:22 AM|LINK
Hi,
I am getting an image in the form of byte array and i need to export that image into PDF.
byte[] buffer = null; MemoryStream stream = new MemoryStream(); buffer = ToByteArray(Request.Form["data"]); Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = "application/pdf"; Response.AddHeader("Content-Disposition", "inline; filename=my.pdf"); int count = 0; do { count = stream.Read(buffer, 0, buffer.Length); Response.BinaryWrite(buffer); Response.Flush(); } while (count!=0); stream.Close(); Response.End(); Response.Close();The above code is not working!!!. I am getting a blank screen?
Plz help me...
AffineMesh94...
Member
6 Points
3 Posts
Re: export byte array to PDF
Apr 16, 2010 07:08 AM|LINK
You might need to specify 'content-length' in the header.
Note that server-side debugging can sometimes insert extra data into the content stream. While this would not cause a problem for HTML, it can corrupt a PDF.
HTTP compression can also compressed the content stream in ways that web browsers understand, but might cause problems for Acrobat.
To diagnose corruption you could try changing the 'content-disposition' to 'attachment', then download the file to see if it will open in Acrobat.
Here is some example code I use for ABCpdf - perhaps you could adapt it to suit your purpose?
<% @Page Language="C#" %> <% @Import Namespace="WebSupergoo.ABCpdf7" %> <% Doc theDoc = new Doc(); theDoc.FontSize = 96; theDoc.AddText("Hello World"); byte[] theData = theDoc.GetData(); Response.Clear(); Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "inline; filename=MyPDF.PDF"); Response.AddHeader("content-length", theData.Length.ToString()); Response.BinaryWrite(theData); Response.End(); %>bhappy
Member
28 Points
221 Posts
Re: export byte array to PDF
Apr 16, 2010 12:54 PM|LINK
Hi,
I tried your code by specifying content-length but, I got the error 'File does not begin with %PDF-'.
Please help me.
rnivash
Member
312 Points
62 Posts
Re: export byte array to PDF
Apr 16, 2010 03:40 PM|LINK
Hi,
Can you tell me more details about the form element "data". because you used Request.Form["data"]
and
if the buffer is a byte array of your image then what are you trying to do with stream.Read() . you can pass the buffer to Response.BinaryWrite straightly..right?.
Regards,
Nivash R
DuoDimension
Member
32 Points
35 Posts
Re: export byte array to PDF
Apr 19, 2010 03:10 AM|LINK
Try to google PDF creator. I think it will be more easier way to put image into the pdf file.
DuoDimension
Member
32 Points
35 Posts
Re: export byte array to PDF
Apr 19, 2010 03:14 AM|LINK
After presaving data you can use PDF Duo .NET converter/creator .NET component. It converts HTML to PDF. It up to you how you want to represent the PDF file. You can save the PDF on the disk or convert HTML to PDF and show PDF in the browser window with saving.
So you can use image tag with your picture as a parameter.
// create an instance of converter object DuoDimension.HtmlToPdf conv = new DuoDimension.HtmlToPdf(); string sHtml = "<img src='yourimage.jpg' width=500 height=300 />"; conv.ImageInfo.ImageScale = 0.8f; // open the html string and convert it into the pdf conv.OpenHTML(sHtml ); // that string saves pdf on the disk // conv.SavePDF("testfifle.pdf"); // show pdf without saving on the disd Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = "application/pdf"; Response.AddHeader("Content-Disposition", "inline; filename=testfifle.pdf"); Response.BinaryWrite(conv.SavePdf()); Response.Flush(); Response.End(); Response.Close();Home page of the component: http://www.duodimension.com/html_pdf_asp.net/component_html_pdf.aspx
bhappy
Member
28 Points
221 Posts
Re: export byte array to PDF
Apr 19, 2010 09:03 AM|LINK
Hi,
Actualy I have generated a report in Flex. On click of Export to PDF button, I am taking snapshot of the report in Flex and converting it into ByteArray. I am sending the resulting ByteArray to my .net application. In my .net application I am getting the results as Request.Form["data"] as bytearray. Later I am trying to display this bytearray in PDF.
Plz help me...