fwPDF Object

Description

The fwPDF object provides functionality that helps produce and stream PDF files to the browser. There are two methods of delivering PDF files from FoxWeb:

Stream the file directly to the browser
This method involves the use of the SendPDF method to generate a PDF file and stream it directly to the browser from the FoxWeb script. In general, this is a much cleaner option and works better in most circumstances.

Create the file in the web tree and access it via a static link
This method involves using the PS2PDF method to generate and store a PDF file in a temporary, web-addressable folder and sending back to the browser a link, pointing to the file. This technique may be preferable if the files are really large, but it requires that you also establish an external process to clean up older PDF files at regular intervals.

By itself, fwPDF does not have the ability to generate PDF files, but must rather be used with 3rd-party software, such as Adobe Acrobat, or Ghostscript. For additional information on PDF file creation, please refer to the Creating PDF Files topic.

Properties

PS2PDFOptions Can be used to specify command line options for the conversion of Postscript files to PDF format.
PS2PDFPresets Can be used to override the PS to PDF Presets option, specified in the FoxWeb Control Center.
PS2PDFTimeout Can be used to override the PS to PDF Command Timeout, specified in the FoxWeb Control Center.

Methods

GetTempFile Returns the full path and file name to a temporary file in FoxWeb's temporary folder.
PS2PDF Converts a Postscript file to PDF format.
SendPDF Streams a Postscript, or PDF file to the browser. If the file is in Postscript format, it is first converted to PDF format.

PS2PDFOptions Property

Description

The PS2PDFOptions property can be used to specify conversion options for situations, where a command line application is used for the conversion from Postscript to PDF format. The content of this property is inserted in the location specified by the %OPTIONS% tag in the PS to PDF command Line, specified in the FoxWeb Control Center. For example, consider the following situation:

PS to PDF Command Line:"C:\Program Files\PDF\PS2PDF.exe" %OPTIONS% /o "%PDFFILE%" "%PSFILE%"
fwPDF.PS2PDFOptions:/h /f:book
Command Line used:"C:\Program Files\PDF\PS2PDF.exe" /h /f:book /o "%PDFFILE%" "%PSFILE%"

PS2PDFPresets Property

Description

The PS2PDFPresets property can be used to override the PS to PDF Presets option that was specified in the FoxWeb Control Center. This property is only used when the PS to PDF Converter option is set to 'Ghostscript', or 'Adobe Acrobat Distiller'. Valid values will depend on the converter used. Both Ghostscript and Adobe Acrobat allow the creation of user-defined presets. For details, please refer to the documentation of your PDF software.


PS2PDFTimeout Property

Description

The PS2PDFTimeout property can be used to override the PS to PDF Command Timeout that was specified in the FoxWeb Control Center. This property is only used when the PS to PDF Converter option is set to 'Command Line'.


GetTempFile Method

Description

The fwPDF.GetTempFile method returns the full path and file name to a temporary file in FoxWeb's temporary folder. The file name is a randomly-generated, 32-character string of letters and numbers, which makes it suitable for obfuscating PDF files stored in the Web tree for static download. For sample code illustrating the use of GetTempFile, refer to the examples under the PS2PDF and SendPDF sections.

Syntax

TempFile = fwPDF.GetTempFile()

Return Value

Character string: The full path and file name to a temporary file.


PS2PDF Method

Description

The fwPDF.PS2PDF method can be used to convert a Postscript file to PDF format. Typically, you would only use this method in situations where the resulting PDF file would be stored in a temporary web-addressable folder for direct download as a static file. In some rare cases -- especially if the generated PDF files are really large -- this technique is preferable to using the SendPDF method to stream the file to the browser from your FoxWeb scripts.

Syntax

Success = fwPDF.PS2PDF(PSFile, PDFFile, DeleteOriginal)

Parameters

PSFile

Character string, specifying the full path of the Postscript file to be converted to PDF format.

PDFFile

Character string, specifying the full path of the resulting PDF file.

DeleteOriginal

Boolean value, specifying whether the method should delete the source Postscript file after a successful conversion.

Return Value

Boolean: The PS2PDF method returns .T. if the conversion was successful.

Example

<html>
<head><title>fwPDF Sample Script</title></head>
<body>
<%
M.PSFile = fwPDF.GetTempFile()
USE address SHARED
* Generate the PS file
REPORT FORM address NOWAIT NOCONSOLE TO FILE (M.PSFile)
* Construct a temporary file name in the downloads folder
M.PDFFile = "c:\InetPub\wwwroot\download\" + ForceExt(JustFName(M.PSFile), 'pdf')
* Covert the file to PDF format and save it to the downloads folder
IF fwPDF.PS2PDF(M.PSFile, M.PDFFile, .T.)
    %>
<a href="/download/<%=M.PDFFile%>">Click to retrieve PDF file</a><%
ELSE
    %>
Error during PDF file creation<%
ENDIF
%>

</body>
</html>

SendPDF Method

Description

The fwPDF.SendPDF method Streams a Postscript, or PDF file to the browser. If the file is in Postscript format, it is first converted to PDF format.

Syntax

fwPDF.SendPDF(SourceFile, FileName, DeleteOriginal, Convert, Download)

Parameters

SourceFile

Character string, specifying the full path to the file to be streamed to the browser.

FileName

Optional character string, specifying the file name that gets sent to the browser. Used by browsers as the default file name in the Save As dialog. If this parameter is not specified, then the source file name is used instead.

DeleteOriginal

Boolean value, specifying whether the SendPDF method should delete the original file after successful streaming to the browser. If this parameter is not specified, or is set to .F., SendPDF does not delete the source file.

Convert

Optional boolean value, specifying whether SendPDF should call the PS2PDF method to convert the original file from Postscript to PDF format, before streaming the PDF file to the browser. If this parameter is not specified, or is set to .F., SendPDF assumes that the source file is already in PDF format and does not perform a conversion.

Download

This optional boolean value controls the value of the Content Disposition HTTP header, which controls how the browser will handle the PDF file. If this value is not specified, or is set to False, then the file gets displayed inline in the browser window, using the Acrobat plug-in. If Download is set to .T. then the file is sent as an attachment, causing the browser to display the Open/Save dialog.

Example

<%
M.TempFile = fwPDF.GetTempFile()
USE address SHARED
* Generate the PS, or PDF file
REPORT FORM address NOWAIT NOCONSOLE TO FILE (M.TempFile)
* Send the file to the browser for in-browser display
fwPDF.SendPDF(M.TempFile, , .T., fwPDF.PS2PDFMethod <> 0, .F.)
%>

© Aegis Group