Print Page | Close Window

Streaming the PDF document directly to the browser

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: Sample Code
Forum Description: Share Debenu Quick PDF Library sample code with other forum members
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=1210
Printed Date: 07 May 24 at 1:13PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Streaming the PDF document directly to the browser
Posted By: Rowan
Subject: Streaming the PDF document directly to the browser
Date Posted: 09 Sep 09 at 2:07AM
This sample shows you how to stream the PDF document directly to the browser in ASP.

The http://www.quickpdflibrary.com/help/quickpdf/SaveToVariant.php - SaveToVariant function returns a byte array which can be sent directly to the browser. This method means that you do not need to create a physical file for your users to download, the file can be sent directly to the user's browser.

Visit the setup http://www.quickpdf.org/forum/using-the-activex-version-with-asp_topic1209.html - Quick PDF Library for ASP  tutorial before you begin this tutorial.

Now write an ASP script to generate your PDF document, and stream it to the browser:

<%
Dim QP
Set QP = Server.CreateObject("QuickPDFAX0715.PDFLibrary")
Call QP.UnlockKey("type your license key here")
Call QP.DrawText(100, 500, "ASP stream to browser test")
Call QP.CompressContent()
Response.ContentType = "application/pdf"
Response.AddHeader "Content-disposition", _
"attachment; filename=test.pdf"
Response.BinaryWrite QP.SaveToVariant()
Response.End
Set QP = Nothing
%>

The following line compresses the PDF document, this results in a faster download of the document. The CompressContent function should obviously be called before the SaveToVariant function.

Call QP.CompressContent()

Now the HTTP headers are set up to tell the browser that the information is a PDF document:

Response.ContentType = "application/pdf"
Response.AddHeader "Content-disposition", _
"attachment; filename=test.pdf"

Finally, the binary PDF data is generated using the SaveToVariant function, and the resulting byte stream is sent to the browser.

Response.BinaryWrite QP.SaveToVariant()
Response.End



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk