Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
![]() |
Creating PDF Streaming (no saving file to disk) |
Post Reply ![]() |
Author | |
Dan ![]() Team Player ![]() ![]() Joined: 21 Oct 11 Location: US Status: Offline Points: 23 |
![]() ![]() ![]() ![]() ![]() Posted: 21 Oct 11 at 2:43PM |
Hi,
Does anyone have a VB or C# example of how I can send a pdf directly to the response stream? All the examples I see save the pdf to disk using code such as: Dim pdf As New QuickPDF.Client pdf.Connect(ConnectURL, ConnectPort) pdf.UnlockKey(QuickPDFKey) pdf.SetOrigin(origin) pdf.DrawText(100, 100, "Testing 123") pdf.SaveToFile("../pdf/HelloWorld.pdf") I'd like to just return the dynamically created pdf when a user opens a certain URL. Is this possible? Thanks, Dan Edit: What I want to do is very similar to what they do with itextsharp here: http://alandennis.blogspot.com/2005/07/streaming-pdf-using-itextsharp-and.html, just with quick pdf. Edited by Dan - 21 Oct 11 at 3:00PM |
|
![]() |
|
samb ![]() Beginner ![]() Joined: 09 Feb 11 Status: Offline Points: 8 |
![]() ![]() ![]() ![]() ![]() |
Assuming you're using the .net dll wrapper C# would be:
byte[] pdfContents = http://www.quickpdflibrary.com/help/quickpdf/SaveToString.php In the .net wrapper, SaveToString requires no arguments and actually returns a byte array, not a string. Edited by samb - 24 Oct 11 at 6:51PM |
|
![]() |
|
Dan ![]() Team Player ![]() ![]() Joined: 21 Oct 11 Location: US Status: Offline Points: 23 |
![]() ![]() ![]() ![]() ![]() |
According to the docs, http://www.quickpdflibrary.com/help/quickpdf/SaveToStream.php SaveToStream() is only available in the Delphi version of quick pdf.
I will try the SaveToString() method. Thanks, Dan |
|
![]() |
|
Dan ![]() Team Player ![]() ![]() Joined: 21 Oct 11 Location: US Status: Offline Points: 23 |
![]() ![]() ![]() ![]() ![]() |
Works
![]() Here is the rest of the code (VB.Net): Dim filename As String = "Testing.pdf" Dim bytes As Byte() = pdf.SaveToString() Dim m As System.IO.MemoryStream = New System.IO.MemoryStream(bytes, 0, bytes.Length, False, True) Response.Clear() Response.ContentType = "application/pdf" Response.AddHeader("Content-Disposition", "attachment; filename=" & filename) Response.OutputStream.Write(m.GetBuffer(), 0, m.GetBuffer.Length) Response.OutputStream.Flush() Response.OutputStream.Close() Response.End() |
|
![]() |
|
Dan ![]() Team Player ![]() ![]() Joined: 21 Oct 11 Location: US Status: Offline Points: 23 |
![]() ![]() ![]() ![]() ![]() |
Not sure if it's best to leave out the MemoryStream and just use the byte array, but this also works:
Dim pdf As New QuickPDF.Client pdf.Connect(ConnectURL, ConnectPort) pdf.UnlockKey(QuickPDFKey) pdf.SetOrigin(origin) pdf.DrawText(100, 100, "Testing 123") Dim filename As String = "Testing.pdf" Dim bytes As Byte() = pdf.SaveToString() Response.Clear() Response.ContentType = "application/pdf" Response.AddHeader("Content-Disposition", "attachment; filename=" & filename) Response.OutputStream.Write(bytes, 0, bytes.Length) Response.OutputStream.Flush() Response.OutputStream.Close() Response.End() |
|
![]() |
|
samb ![]() Beginner ![]() Joined: 09 Feb 11 Status: Offline Points: 8 |
![]() ![]() ![]() ![]() ![]() |
Sorry, you are correct: SaveToString is what I meant to type.
![]() As for the Memory Stream, you're usually supposed to dispose them when you're done (either wrap it in a using block, or explicitly call dispose). Otherwise, resources may not be freed up when you think they do. Since your getting a byte array and streaming a byte array, there's no reason to convert it to a memory stream in the middle. Also, since the byte array doesn't need any cleanup, you don't have to worry about resources. Edited by samb - 24 Oct 11 at 7:00PM |
|
![]() |
|
Dan ![]() Team Player ![]() ![]() Joined: 21 Oct 11 Location: US Status: Offline Points: 23 |
![]() ![]() ![]() ![]() ![]() |
Sounds good. Thanks for the help!
|
|
![]() |
Post Reply ![]() |
|
Tweet
|
Forum Jump | Forum Permissions ![]() 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 |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store