export byte array to PDFhttp://forums.asp.net/t/1546703.aspx/1?export+byte+array+to+PDFMon, 19 Apr 2010 09:03:40 -040015467033782167http://forums.asp.net/p/1546703/3782167.aspx/1?export+byte+array+to+PDFexport byte array to PDF <p>Hi All,</p> <p>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 </p> <p><pre class="prettyprint">response.ClearContent(); response.ClearHeaders(); response.ContentType = &quot;application/pdf&quot;; response.AddHeader(&quot;Content-Disposition&quot;, &quot;inline; filename=my.pdf&quot;); 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();</pre><br> Plz some one help me...<br> </p> 2010-04-13T12:01:55-04:003782457http://forums.asp.net/p/1546703/3782457.aspx/1?Re+export+byte+array+to+PDFRe: export byte array to PDF <p>I have no idea abt your stream object,,try the following code</p> <p><br> </p> <p><br> </p> &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;Response.ClearContent();&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Response.ClearHeaders();&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Response.ContentType = &quot;application/pdf&quot;;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Response.AddHeader(&quot;Content-Disposition&quot;, &quot;inline; filename=my.pdf&quot;);&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;int StreamLength;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;StreamLength = (int)stream.Length;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Byte[] buffer = new Byte[StreamLength];&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;stream.Read(buffer, 0, StreamLength);&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Response.BinaryWrite(buffer);&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Response.Flush();&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;stream.Close();&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Response.End();&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Response.Close();&lt;/div&gt; <p></p> <p style="padding-left:30px">Response.ClearContent();</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Response.ClearHeaders();</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Response.ContentType = &quot;application/pdf&quot;;</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Response.AddHeader(&quot;Content-Disposition&quot;, &quot;inline; filename=my.pdf&quot;);</p> <p><br> </p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;int StreamLength;</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;StreamLength = (int)stream.Length;</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Byte[] buffer = new Byte[StreamLength];</p> <p><br> </p> <p><br> </p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;stream.Read(buffer, 0, StreamLength);</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Response.BinaryWrite(buffer);</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Response.Flush();</p> <p><br> </p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;stream.Close();</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Response.End();</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Response.Close();</p> <p></p> <p><br> </p> <ol start="1" style="margin-top:0px!important; margin-right:0px!important; margin-bottom:1px!important; margin-left:45px!important; list-style-type:decimal; list-style-position:initial; background-color:#ffffff; color:#5c5c5c; padding:0px; border:initial none initial"> </ol> 2010-04-13T14:28:12-04:003783746http://forums.asp.net/p/1546703/3783746.aspx/1?Re+export+byte+array+to+PDFRe: export byte array to PDF <p>Hi,</p> <p>I am getting an image in the form of byte array and i need to export that image into PDF.</p> <p><pre class="prettyprint">byte[] buffer = null; MemoryStream stream = new MemoryStream(); buffer = ToByteArray(Request.Form[&quot;data&quot;]); Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = &quot;application/pdf&quot;; Response.AddHeader(&quot;Content-Disposition&quot;, &quot;inline; filename=my.pdf&quot;); 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();</pre></p> <p><br> The above code is not working!!!. I am getting a blank screen?</p> <p>Plz help me...<br> </p> <p><br> </p> 2010-04-14T05:22:26-04:003788005http://forums.asp.net/p/1546703/3788005.aspx/1?Re+export+byte+array+to+PDFRe: export byte array to PDF <p>You might need to specify 'content-length' in the header.</p> <p>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.</p> <p>HTTP compression can also compressed the content stream in ways that web browsers understand, but might cause problems for Acrobat.<br> </p> <p>To diagnose corruption you could try changing the 'content-disposition' to 'attachment', then download the file to see if it will open in Acrobat.<br> </p> <p>Here is some example code I use for ABCpdf - perhaps you could adapt it to suit your purpose?<br> </p> <p></p> <pre class="prettyprint">&lt;% @Page Language=&quot;C#&quot; %&gt; &lt;% @Import Namespace=&quot;WebSupergoo.ABCpdf7&quot; %&gt; &lt;% Doc theDoc = new Doc(); theDoc.FontSize = 96; theDoc.AddText(&quot;Hello World&quot;); byte[] theData = theDoc.GetData(); Response.Clear(); Response.ContentType = &quot;application/pdf&quot;; Response.AddHeader(&quot;content-disposition&quot;, &quot;inline; filename=MyPDF.PDF&quot;); Response.AddHeader(&quot;content-length&quot;, theData.Length.ToString()); Response.BinaryWrite(theData); Response.End(); %&gt;</pre> <p><br> </p> <p></p> <p><br> </p> 2010-04-16T07:08:48-04:003788548http://forums.asp.net/p/1546703/3788548.aspx/1?Re+export+byte+array+to+PDFRe: export byte array to PDF <p>Hi,</p> <p><br> </p> <p>I tried your code by specifying content-length but, I got the error 'File does not begin with %PDF-'.</p> <p><br> </p> <p>Please help me.<br> </p> 2010-04-16T12:54:32-04:003788822http://forums.asp.net/p/1546703/3788822.aspx/1?Re+export+byte+array+to+PDFRe: export byte array to PDF <p>Hi,</p> <p>Can you tell me more details about the form element &nbsp;&quot;data&quot;. because you used Request.Form[&quot;data&quot;]</p> <p>and&nbsp;</p> <p>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?.</p> <p><br> </p> <p>Regards,</p> <p>Nivash R</p> <p><br> </p> <p><br> </p> 2010-04-16T15:40:24-04:003791231http://forums.asp.net/p/1546703/3791231.aspx/1?Re+export+byte+array+to+PDFRe: export byte array to PDF <p>Try to google PDF creator. I think it will be more easier way to put image into the pdf file.<br> </p> 2010-04-19T03:10:07-04:003791233http://forums.asp.net/p/1546703/3791233.aspx/1?Re+export+byte+array+to+PDFRe: export byte array to PDF <p>After presaving data you can use <a href="http://www.duodimension.com/html_pdf_asp.net/component_html_pdf.aspx" title="html to pdf converter"> PDF Duo .NET converter/creator .NET component</a>. 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.</p> <p>So you can use image tag with your picture as a parameter. </p> <p></p> <pre class="prettyprint">// create an instance of converter object DuoDimension.HtmlToPdf conv = new DuoDimension.HtmlToPdf(); string sHtml = &quot;&lt;img src='yourimage.jpg' width=500 height=300 /&gt;&quot;; 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(&quot;testfifle.pdf&quot;); // show pdf without saving on the disd Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = &quot;application/pdf&quot;; Response.AddHeader(&quot;Content-Disposition&quot;, &quot;inline; filename=testfifle.pdf&quot;); Response.BinaryWrite(conv.SavePdf()); Response.Flush(); Response.End(); Response.Close();</pre> <p>Home page of the component: <a href="http://www.duodimension.com/html_pdf_asp.net/component_html_pdf.aspx" title="PDF Duo .NET home web page"> http://www.duodimension.com/html_pdf_asp.net/component_html_pdf.aspx</a></p> 2010-04-19T03:14:21-04:003791666http://forums.asp.net/p/1546703/3791666.aspx/1?Re+export+byte+array+to+PDFRe: export byte array to PDF <p>Hi,</p> <p>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[&quot;data&quot;] as bytearray. Later I am trying to display this bytearray in PDF.<br> </p> <p>Plz help me...<br> </p> 2010-04-19T09:03:40-04:00