Welcome Guest Search | Active Topics | Sign In | Register

PDF to Byte() Options
Adam
Posted: Tuesday, May 8, 2012 10:53:24 AM
Rank: Member
Groups: Member

Joined: 5/8/2012
Posts: 13
I am currently using your ASPXToPDF Product and was wondering if there is any way to get the pdf as a byte array in memory rather than rendering it to the browser every time. I need to convert it to a byte() so I can BLOB it into a database.

The only thing that I see in the documentation is the RenderAsPDF Sub that will render it to browser. It would be nice if there was a GetBytes() function or something similar to that.

Do you have any suggestions?

Thanks,

Adam
eo_support
Posted: Tuesday, May 8, 2012 10:58:46 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

You can do that by handling AfterRender event and then save the result PdfDocument to a MemoryStream. You would then call the MemoryStream object's ToArray method to get your byte array.

You can find detailed steps and sample code here:

http://www.essentialobjects.com/doc/4/web/aspxtopdf.aspx

Look for "Save Conversion Result into a File" section. The sample code saves the result PDF document into a file. You would need just change the file name argument (which is a string) to a MemoryStream object. This would call another overloaded version of the Save method and save the result into your MemoryStream.

Hope this helps. Please feel free to let us know if you still have any questions.

Thanks!
Adam
Posted: Tuesday, May 8, 2012 11:24:15 AM
Rank: Member
Groups: Member

Joined: 5/8/2012
Posts: 13
That is pretty slick. I figured you had something like that.

Thanks a lot for you help and your prompt reply.

Here is a little code snippet for anyone else that has this issue.

Code: Visual Basic.NET
Private Sub atpForm_AfterRender(sender As Object, e As System.EventArgs) Handles atpForm.AfterRender
    Dim result As HtmlToPdfResult = CType(atpForm.Result, HtmlToPdfResult)
    Dim ms As IO.MemoryStream = New IO.MemoryStream
    result.PdfDocument.Save(ms)
    Dim bPDFBytes As Byte() = ms.ToArray


  End Sub


Thanks again!

Adam
eo_support
Posted: Tuesday, May 8, 2012 11:44:41 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Glad to hear that you got it working. Thanks for sharing!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.