Sending PDF files directly to the browser

If you are using PDFReport on a Web Browser with ASP pages, you can send the PDF file generated in memory to the browser directly, without having to save it somewhere on the server.

This feature is particularly precious as you don't waster space, you haven't to give "Read/Write" access to any folder and you don't have to manage old temp files.

Sending back the PDF is absolutely easy:

Here's an example of an ASP page:

<%
Dim PDFRPT
Set PDFRPT = CreateObject("PDFReport_XP.PDFDocument")
PDFRPT.NewPDF "Prova"
PDFRPT.ParagraphAlignment = "left"
PDFRPT.TextOut "prova" & vbCrLf & "a capo", 10, 10
PDFRPT.FontHeight = 18
PDFRPT.FontName = "Helvetica"
PDFRPT.ParagraphAlignment = "lEFT"
PDFRPT.TextOut "prova" & vbCrLf & "a capo", 100, 100
PDFRPT.ParagraphAlignment = "Center"
PDFRPT.ParagraphLeading = 30
PDFRPT.TextOut "prova" & vbCrLf & "a capo", 100, 140
PDFRPT.UnitOfMeasure = "PDFU"
PDFRPT.ParagraphLeading = 30
PDFRPT.ParagraphAlignment = "RIGHT"
PDFRPT.FontName = "Helvetica" < f
PDFRPT.TextOut "prova" & vbCrLf & "a capo RIGHT", 100, 180

PDFRPT.UnitOfMeasure = "mm"
PDFRPT.AddOutline 2, 50, 0, 0, "prova"

PDFRPT.TextOut Request.QueryString("yourtext"), 30, 42
PDFRPT.AddPage
PDFRPT.UnitOfMeasure = "cm"
PDFRPT.SetPageDimensions 29.7, 21
PDFRPT.TextOut "pagina 2", 10, 10
PDFRPT.SetCurrentPage 1
PDFRPT.SetLineColor 0, 0, 255
PDFRPT.SetFillColor 255, 0, 0
PDFRPT.TextRendering = 2
PDFRPT.TextOut "pagina uno di nuovo", 20, 20

PDFRPT.UnitOfMeasure = "mm"
PDFRPT.SetCurrentPage 1
PDFRPT.CreateLink_Internal 10, 10, 287, 200, 0, 255, 0, 0, 2

PDFRPT.SetCurrentPage 2
PDFRPT.CreateLink_External 10, 10, 20, 20, 1, 255, 0, 0, "c:\provanew.pdf"
PDFRPT.CreateLink_Internet 20, 20, 287, 200, 1, 255, 0, 0, "http://www.dreamscape.it"
  Response.ContentType = "application/pdf"
  Response.BinaryWrite PDFRPT.GetPDFContent
  Response.End
  Set PDFObj = Nothing ' free
%>

The Line in BOLD uses the only method you need,: "GetPDFContent"; you should simply cut and paste this line everytime you need to generate on the fly an IN-MEMORY PDF file and send back it to the browser.

The previous line:

Response.ContentType = "application/pdf"

instructs the browser to treat the receiving bytes as a PDF file, so IE or Mozilla open Acrobat to manage it.

The PDF opens in the browser as you can see below: