Whatever message this page gives is out now! Go check it out!

pdf

Last update:
May 18, 2026
Note:
In ColdFusion (2018 release), script functions implemented as CFCs are deprecated in ColdFusion.

Description

Provides services to manipulate existing PDF documents in CFScript.

Syntax

ModeSyntax
Creating the service
new pdf()}}or {{createObject("component", "pdf")
Initializing the attributes
Any one of the following:
  • pdfService=new pdf(attribute-value pair)
  • pdfService.setAttributes(attribute-value pair)
  • pdfService.set_AttributeName(attribute_value_)
  • pdfService.action_method(attribute-value pair)
Executing the service action
pdfService.action_method(attribute-value pair)

Properties

addQuads
algo
align
ascending
bottomMargin
compressTiffs
copyFrom
ddxfile
destination
directory
encodeAll
encrypt
flatten
foreground
format
height
hires
honourSpaces
hScale
image
imagePrefix
info
inputFiles
isBase64
jpgDpi
keepBookmark
leftMargin
maxBreadth
maxLength
maxScale
name
newOwnerPassword
newUserPassword
noAttachments
noBookmarks
noComments
noJavascripts
noLinks
noMetadata
noThumbnails
numberFormat
opacity
order
outputFiles
overridePage
overwrite
package
pages
password
permissions
position
resolution
rightMargin
rotation
saveOption
scale
showOnPrint
source
stopOnError
text
topMargin
transparent
type
useStructure
version
vscale
width
All attributes supported by the tag cfpdf can be used as attribute-value pairs. For example,
<cfpdf action="getInfo" source="myBook.pdf" name="PDFInfo">
can be used as
pdfInfo = pdfService.getPdfInfo(source="myBook.pdf", name="pdfinfo");
For details, see the Attributes section for the  cfpdf  tag__.

Methods

  • addParam
    Description
    Used in CFScript to add cfpdfparam tags. Applicable only to action="merge".
    Returns
    Nothing
    Syntax
    pdfService.addParam(attribute-value pair)
    Arguments
    All attributes supported by the cfpdfparam tag can be used as attribute-value pairs.
  • The following PDF actions are available as methods. All these methods have similar arguments and syntax.
    addWatermark
    removeWatermark
    deletePages
    getPDFInfo
    setPDFInfo
    merge
    processDDX
    protect
    read
    write
    thumbnail
    transform
    optimize
    extractImage
    extractText
    addHeader
    addFooter
    removeHeaderFooter
    Note: In the list, setPDFInfo and getPDFInfo do not have identical actions in cfpdf. cfpdf action="setinfo" and cfpdf action="getinfo" represent them respectively.
Description
All methods correspond to the PDF actions specified for the tag cfpdf. For details of each method, refer to the corresponding section for cfpdf .
Returns
Depends on the action. If the name attribute is specified, the result of the pdf operation is returned. Else, an empty string. For example, the following code returns a structure containing the pdf information for "book.pdf": pdfinfo = pdfService.getPDFInfo(source="book.pdf",name="var")}}PDF manipulation is done using the {{cfpdf tag. This is why, you must specify the name attribute. Accessing "var" directly does not work since "var" does not exist in the page variables scope.
Syntax
serviceName.methodName(attribute-value pair)
Arguments
All attributes supported by the cfpdf tag for a given action are supported.
  • setAttributes
    Description
    Sets attributes for the pdf function.
    Returns
    Nothing
    Syntax
    pdfService.setAttributes (attribute-value pair)
    Arguments
    All attributes supported by the cfpdf tag.
  • getAttributes
    Description
    Gets the attributes that were set for the pdf function.
    Returns
    Returns a struct with all or some of the attribute values.
    Syntax
    pdfService.get_Attributes_ (attributelist)
    Arguments
    A comma-separated list of attributes. If no list is specified, all defined attributes are returned.
  • clearAttributes
    Description
    Removes all attributes added for the pdf function.
    Returns
    Nothing
    Syntax
    pdfService.clearAttributes(attribute_list)
    Arguments
    A comma-separated list of attributes that must be removed.
  • clearParams
    Description
    Removes params that were added using addParam method.
    Returns
    Nothing
    Syntax
    pdfService.clearParams()
    Arguments
    None
  • clear
    Description
    Removes all attributes and params added using the addParam method.
    Returns
    Nothing
    Syntax
    pdfService.clear()
    Arguments
    None

See also

History

ColdFusion 9: Added this function.

Usage

This function corresponds to the cfpdf tag. For usage details, refer to the Usage section for  cfpdf .

Example

<h3>PDF Thumbnail</h3> <cfscript> // Create a variable for the name of the PDF document. mypdf = "book"; thumbnailsDirectory = ExpandPath(".") & "\" & "#mypdf#_thumbnails"; //create new PDF service pdfService = new pdf(); //set attributes using implicit setters pdfService.setSource(expandpath('./#mypdf#.pdf')); //Use the getPdfInfo action to retrieve the total page count for the PDF document. PDFInfo = pdfService.getPdfInfo(name="pdfinfo"); pageCount = PDFInfo.TotalPages; WriteOutput("pageCount=" & pageCount); //Generate a thumbnail image for each page in the PDF source document, //create a directory (if it does not exist) in the web root that is //a concatenation of the PDF source name and the word "thumbnails", and //save the thumbnail images in that directory. pdfService.thumbnail(destination=thumbnailsDirectory, scale=60, overwrite=true); //Loop through the images in the thumbnail directory and generate a link //from each image to the corresponding page in the PDF document. for(i="1";i lte pageCount;i++) { //Click the thumbnail image to navigate to the page in the PDF document. WriteOutput("<a href='#mypdf#.pdf##page=#i#' target='_blank'><img src='#mypdf#_thumbnails/#mypdf#_page_#i#.jpg'></a>"); } </cfscript

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page