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!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > I need help - I can help
  New Posts New Posts RSS Feed - Creating PDF Streaming (no saving file to disk)
  FAQ FAQ  Forum Search   Register Register  Login Login

Creating PDF Streaming (no saving file to disk)

 Post Reply Post Reply
Author
Message
Dan View Drop Down
Team Player
Team Player
Avatar

Joined: 21 Oct 11
Location: US
Status: Offline
Points: 23
Post Options Post Options   Thanks (0) Thanks(0)   Quote Dan Quote  Post ReplyReply Direct Link To This Post Topic: Creating PDF Streaming (no saving file to disk)
    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
Back to Top
samb View Drop Down
Beginner
Beginner


Joined: 09 Feb 11
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote samb Quote  Post ReplyReply Direct Link To This Post Posted: 21 Oct 11 at 6:18PM
Assuming you're using the .net dll wrapper  C# would be:
byte[] pdfContents = pdf.SaveToStream() pdf.SaveToString()

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
Back to Top
Dan View Drop Down
Team Player
Team Player
Avatar

Joined: 21 Oct 11
Location: US
Status: Offline
Points: 23
Post Options Post Options   Thanks (0) Thanks(0)   Quote Dan Quote  Post ReplyReply Direct Link To This Post Posted: 21 Oct 11 at 9:58PM
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
Back to Top
Dan View Drop Down
Team Player
Team Player
Avatar

Joined: 21 Oct 11
Location: US
Status: Offline
Points: 23
Post Options Post Options   Thanks (0) Thanks(0)   Quote Dan Quote  Post ReplyReply Direct Link To This Post Posted: 24 Oct 11 at 4:23PM
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()
Back to Top
Dan View Drop Down
Team Player
Team Player
Avatar

Joined: 21 Oct 11
Location: US
Status: Offline
Points: 23
Post Options Post Options   Thanks (0) Thanks(0)   Quote Dan Quote  Post ReplyReply Direct Link To This Post Posted: 24 Oct 11 at 4:56PM
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()
Back to Top
samb View Drop Down
Beginner
Beginner


Joined: 09 Feb 11
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote samb Quote  Post ReplyReply Direct Link To This Post Posted: 24 Oct 11 at 7:00PM
Sorry, you are correct: SaveToString is what I meant to type. Embarrassed

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
Back to Top
Dan View Drop Down
Team Player
Team Player
Avatar

Joined: 21 Oct 11
Location: US
Status: Offline
Points: 23
Post Options Post Options   Thanks (0) Thanks(0)   Quote Dan Quote  Post ReplyReply Direct Link To This Post Posted: 24 Oct 11 at 8:39PM
Sounds good. Thanks for the help!
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store