cfpdf
Description
Manipulates existing PDF documents. The following list describes some of the tasks you can perform with the cfpdf tag:
Categories
Related
cfdocument cfdocumentsection cfpdfform cfpdfformparam cfpdfparam cfpdfsubform cfprint isDDX isPDFFile isPDFObject
History
ColdFusion
8: Added this tag.
ColdFusion 9: Added new attributes: jpgdpi, maxBreadth, noAttachments, leftMargin, algo, noMetadata, noBookMarks, noJavaScripts, useStructure, noFonts, text, noComments, encodeAll,numberFormat, compressTIFFs, addQuads, rightMargin, topMargin, bottomMargin, noThumbnails, align, noLinks, maxLength, hires, hScale, overridepage, honourspaces, maxScale, package, vScale
Syntax
Add a watermark to a PDF document
<cfpdf
required
action = "addwatermark"
source = "absolute or relative pathname to a PDF file|PDF document variable|
cfdocument variable"
one of the following:
copyfrom = "absolute or relative pathname to a PDF file from which the first page is
used as a watermark"
image = "absolute or relative pathname to image file|image variable used as a
watermark"
optional
foreground = "yes|no"
isBase64 = "yes|no"
opacity = "watermark opacity"
overwrite = "yes|no"
pages = "page or pages to add the watermark"
password = "user or owner password for the PDF source file"
position = "position on the page where the watermark is placed"
rotation = "degree of rotation of the watermark"
showonprint = "yes|no">
\\one of the following:
destination = "PDF output file pathname"
name = "PDF document variable name"
image = "image file name to be used as the footer"
text = "text to be used in the footer"
Add headers
<cfpdf
required
action = "addheader"
source = "absolute or relative pathname to a PDF file|PDF document variable|
cfdocument variable"
pages = "page or pages to add the footer"
optional
isBase64 = "yes|no"
overwrite = "yes|no"
password = "user or owner password for the PDF source file"
showonprint = "yes|no">
align = "left|right|center"
leftmargin = "value of the header left marign"
rightmargin = "value of the header right margin"
numberformat = "LOWERCASEROMAN|NUMERIC|UPPERCASEROMAN" <!---used with either
_PAGENUMBER or _LASTPAGENUMBER--->
opacity = "header opacity"
topmargin = "value of the top margin of the header"
\\one of the following:
destination = "PDF output file pathname"
name = "PDF document variable name"
text = _PAGELABEL: add current page label|_LASTPAGELABEL: add last page label|
_PAGENUMBER: add current page number|_LASTPAGENUMBER: add last page
number \\text for the header. You can also add a normal text string.
image = "image file name to be used as the header"
Add footer
<cfpdf
required
action = "addfooter"
source = "absolute or relative pathname to a PDF file|PDF document variable|
cfdocument variable"
pages = "page or pages to add the footer"
optional
isBase64 = "yes|no"
overwrite = "yes|no"
password = "user or owner password for the PDF source file"
showonprint = "yes|no">
destination = "PDF output file pathname"
name = "PDF document variable name"
align = "left|right|center"
one of the following:
image = "image file name to be used as the footer"
text = _PAGELABEL: add current page label|_LASTPAGELABEL: add last page label|
_PAGENUMBER: add current page number|_LASTPAGENUMBER: add last page
number \\text for the header
leftmargin = "value of the footer left marign"
rightmargin = "value of the footer right margin"
numberformat
opacity = "footer opacity"
bottommargin = "value of the bottom margin"
Delete pages from a PDF document
<cfpdf
required
action = "deletepages"
pages = "page or pages to delete"
source = "absolute or relative pathname to a PDF file|PDF document variable|
cfdocument variable"
optional
overwrite = "yes|no"
password = "PDF source file password"
one of the following:
destination = "PDF output file pathname"
name = "PDF document variable name">
Delete headers and footers
<cfpdf
required
action = "removeheaderfooter"
source = "absolute or relative pathname to a PDF file|PDF document variable|
cfdocument variable"
optional
overwrite = "yes|no"
pages = "page or pages to add the watermark"
password = "user or owner password for the PDF source file"
one of the following:
destination = "PDF output file pathname"
name = "PDF document variable name"
Retrieve information about a PDF document
<cfpdf
required
action = "getinfo"
name = "structure variable name"
source = "absolute or relative pathname to a PDF file|PDF document variable|
cfdocument variable"
optional
password = "PDF source file password">
Merge PDF documents into an output PDF file
<cfpdf
required
action = "merge"
one of the following:
directory = "directory of PDF files to merge"
source = "comma-separated list of PDF source files|absolute or relative pathname
to a PDF file|PDF document variable|cfdocument variable"
<cfpdfparam>
\\required only when package is specified as true
order = "name|time"
one of the following if <cfpdfparam> is specified:
name = "PDF document variable name"
destination = "PDF output file pathname"
optional
package = "true|false" <!---create PDF packages if set to true. You can provide
description in cfpdfparam tag, such as <cfpdfparam file="filename desc="">--->
ascending = "yes|no"
keepBookmark = "yes|no"
overwrite = "yes|no"
pages = "pages to merge in PDF source file"
password = "PDF source file password"
stopOnError = "yes|no"
\\one of the following:
destination = "PDF output file pathname"
name = "PDF document variable name">
Use DDX instructions to manipulate PDF documents
<cfpdf
required
ddxfile = "DDX filepath|DDX string"
inputfiles = "#inputStruct#"
outputfiles = "#outputStruct#"
name = "structure name">
optional
action="processddx"
Set passwords and encrypt PDF documnets
<cfpdf
required
action = "protect"
source = "absolute or relative pathname to a PDF file|PDF document variable|
cfdocument variable"
at least one of the following:
newUserPassword = "password"
newOwnerPassword = "password"
if newOwnerPassword is specified:
permissions = "All|AllowAssembly|AllowDegradedPrinting|AllowCopy|AllowFillIn|AllowModifyAnnotations|
AllowModifyContents|AllowPrinting|AllowScreenReaders|AllowSecure|None|
comma-separated list"
optional
destination = "PDF output file pathname"
encrypt = "RC4_40|RC4_128|RC4_128M|AES_128|none"
overwrite = "yes|no"
password = "source file password">
Name a PDF document variable
<cfpdf
required
action = "read"
name = "PDF document variable name"
source = "absolute or relative pathname to a PDF file|PDF document variable|
cfdocument variable"
optional
password = "PDF source file password">
Remove a watermark from a PDF document
<cfpdf
required
action = "removeWatermark"
source = "absolute or relative pathname to a PDF file|PDF document variable|
cfdocument variable"
optional
overwrite = "yes|no"
pages = "page or pages from which to remove the watermark"
password = "PDF source file password">
one of the following:
destination = "PDF output file pathname"
name = "PDF document variable name"
Set information about a PDF document
<cfpdf
required
action = "setinfo"
info = "#structure variable name#"
source = "absolute or relative pathname to a PDF file|PDF document variable|
cfdocument variable"
optional
destination = "PDF output file pathname"
overwrite = "yes|no"
password = "PDF source file password">
Generate thumbnails from pages in a PDF document
<cfpdf
required
action = "thumbnail"
source = "absolute or relative pathname to a PDF file|PDF document variable|
cfdocument variable"
optional
destination = "directory path where the thumbnail images are written"
format = "png|jpeg|tiff"
imagePrefix = "string used as a prefix in the output filename"
overwrite = "yes|no"
password = "PDF source file password">
pages = "page or pages to make into thumbnails"
resolution= "low|high"
scale = "percentage between 1 and 100"
transparent = "yes|no">
hires = "yes|no"
overridepage = "yes|no"
compresstiffs = "yes|no"
maxscale = "maximum scale of the thumbnail"
maxlength = "maximum length of the thumbnail"
maxbreadth = "maximum width of the thumbnail"
Write a PDF document to an output file
<cfpdf
required
action = "write"
source = "absolute or relative pathname to a PDF file|PDF document variable|
cfdocument variable"
\\one of the following
destination = "PDF output file pathname"
name = #PDF variable# <!---new variable support added now--->
optional
flatten = "yes|no"
overwrite = "yes|no"
password = "PDF source file password"
saveOption = "linear|incremental|full"
version = "1.1|1.2|1.3|1.4|1.5|1.6">
encodeall = "yes|no"
Reduce the quality of a PDF document
<cfpdf
required
action = "optimize"
source = "absolute or relative path of the PDF file|PDF document variable|
cfdocument variable"
algo = "bilinear|bicubic|nearest_neighbor" <!---algorithm for image
downsampling--->
pages = "*" <!----page numbers associated with the objects in the PDF document--->
optional
vscale= "Vertical scale of the image to be modified. Valid values are vscale>0"
hscacle="Horizontal scale of the image to be modified. Valid values are hscale<1"
destination = "PDF output file pathname"
name = "PDF document variable"
noattachments = "Discard all attachments"
nobookmarks = "Discard all bookmarks"
nocomments = "Discard all comments"
nofonts = "Discard all fonts"
nojavascript = "Discard all JavaScript actions"
nolinks = "Discard external cross-references"
nometadata = "Discard document information and metadata"
nothumbnails = "Discard embedded page thumbnails"
overwrite = "true" <!---Overwrite the specified object in the PDF document--->
password = "" <!--- PDF document password--->
Extract text
<cfpdf
required
action="extracttext" <!---extract all the words in the PDF.--->
source= "absolute or relative path of the PDF file|PDF document variable|
cfdocument variable"
pages = "*" <!----page numbers from where the text needs to be extracted from the
PDF document--->
optional
addquads = "add the position or quadrants for the text in the PDF"
honourspaces = "true|false"
overwrite = "true" <!---Overwrite the specified object in the PDF document--->
password = "" <!--- PDF document password--->
type = "string|xml" <!---format in which the text needs to be extracted--->
one of the following:
destination = "PDF output file pathname"
name = "PDF document variable"
usestructure = "true|false"
Extract image
<cfpdf
required
action = "extractimage" <!---extract images and save it to a directory--->
source = "absolute or relative path of the PDF file|PDF document variable|
cfdocument variable"
pages = "*" <!---page numbers from where the images need to be extracted--->
optional
overwrite = "true|false" <!---overwrite any existing image when set to true--->
format = "png|tiff|jpg" <!---format in which the images should be extracted--->
imageprefix = "*" <!---the string that you want to prefix with the image name--->
password = "" <!--- PDF document password--->
destination = "PDF output file pathname"
Page level transformations
<cfpdf
required
action = "transform"
source = "absolute or relative path of the PDF file|PDF document variable|
cfdocument variable"
pages = "page or pages to be transformed"
optional
hscale = "value of the horizontal scale of the page"
overwrite = "yes|no"
password = "PDF source file password"
position = "x, y" <!---value in pixels--->
rotation = "0|90|180|270"
vscale = "length of the page to be transformed"
one of the following:
destination = ""Path of the directory where the PDF document will be saved"
name = "PDF document variable"
Note: You
can specify this tag’s attributes in an attributeCollection attribute
whose value is a structure. Specify the structure name in the attributeCollection attribute
and use the tag’s attribute names as structure keys.
Attributes
| Attribute | Description | Required | Default |
|---|---|---|---|
| action | N/A | ||
| addquads | thumbnail | ||
| algo | optimize | ||
| align | addheader addfooter | ||
| ascending | merge | ||
| bottomMargin | addfooter | ||
| compresstiffs | thumbnail | ||
| copyFrom | addWatermark | ||
| ddxfile | processddx | ||
| destination | addWatermark deletePages merge protect removeWatermark setInfo thumbnail write optimize extracttext extractimage addheader addfooter removeheaderfooter transform | ||
| directory | merge | ||
| encodeall | write | ||
| encrypt | protect | ||
| flatten | write | ||
| foreground | addWatermark | ||
| format | thumbnail | ||
| hires | thumbnail | ||
| honourspaces | extracttext | ||
| hscale | optimize | ||
| image | addWatermark | ||
| imagePrefix | thumbnail | ||
| info | setInfo | ||
| inputFiles | processddx | ||
| isBase64 | addWatermark | ||
| keepBookmark | merge | ||
| leftmargin | addheader | ||
| maxbreadth | thumbnail | ||
| maxlength | thumbnail | ||
| maxscale | thumbnail | ||
| name | addWatermark deletePages getInfo merge processddx protect read removeWatemark write tranform addheader addfooter removeheaderfooter | ||
| newOwnerPassword | protect | ||
| newUserPassword | protect | ||
| noattachments | thumbnail | ||
| noattachments | optimize | ||
| nobookmarks | optimize | ||
| nocomments | optimize | ||
| nofonts | optimize | ||
| nojavascript | optimize | ||
| nolinks | optimize | ||
| nometadata | optimize | ||
| nothumbnails | optimize | ||
| numberformat | addfooter | ||
| opacity | addWatermark addheader addfooter | ||
| order | merge | ||
| outputFiles | processddx | ||
| overwrite | addWatermark deletePages merge protect removeWatermark setInfo thumbnail write tranform addheader addfooter removeheaderfooter | ||
| package | merge | ||
| pages | addWatermark deletePages merge removeWatermark optimize extracttext extractimage addheader addfooter removeheaderfooter transform | ||
| password | addWatermark deletePages getInfo merge protect read removeWatermark setInfo thumbnail write optimize extracttext extractimage addheader addfooter removeheaderfooter transform | ||
| permissions | protect | ||
| position | addWatermark | ||
| resolution | thumbnail | ||
| rotation | addWatermark transform | ||
| saveOption | write | ||
| scale | thumbnail | ||
| showOnPrint | addWatermark | ||
| source | addWatermark deletePages getInfo merge protect read removeWatermark setInfo thumbnail write optimize extracttext extractimage addheader addfooter removeheaderfooter transform | ||
| stopOnError | merge | ||
| transparent | thumbnail | ||
| useStructure | extracttext | ||
| version | write |
Usage
You use the cfpdf tag to manipulate and assemble existing PDF documents. Although the cfpdf tag provides much of the functionality available in Acrobat, you cannot use this tag to generate a PDF document from another file format. To create PDF output from HTML and CFML content, use the cfdocument tag.
You cannot embed a cfpdf tag within a cfdocument tag or embed a cfdocument tag within a cfdpdf tag; however, you can write the output of a cfdocument tag to a variable and pass the variable to the cfpdf tag. The following example shows how to use the cfdocument tag to create a cover page and add it to a merged PDF document:
<!--- Use the cfdocument tag to create a cover page and write the output to a variable called cfdoc. ---> <cfdocument format="PDF" name="cfdoc"> <html> <body> <h1>Here is a cover page</h1> </body> </html> </cfdocument> <!--- Use the cfpdf tag and cfpdfparam tags to merge individual PDF documents into a new PDF document called new.pdf. Notice that the cfdoc variable created by using the cfdocument tag is the source value of the first cfpdfparam tag. ---> <cfpdf action="merge" destination="/samtemp/pdfs/new.pdf" overwrite="yes"> <cfpdfparam source="cfdoc"> <cfpdfparam source="/samtemp/pdfs/pdf2.pdf"> <cfpdfparam source="/samtemp/pdfs/pdf1.pdf"> </cfpdf> You can use the cfpdf tag to assemble interactive PDF form files into a single PDF document and flatten forms created in Acrobat (by using the flatten attribute with the write action); however, to process PDF form data, use the cfpdfform and related tags. You cannot use the cfpdf tag to flatten forms created in Adobe LiveCycle Designer ES.
You cannot embed a cfpdf tag within a cfdocument tag or embed a cfdocument tag within a cfdpdf tag; however, you can write the output of a cfdocument tag to a variable and pass the variable to the cfpdf tag. The following example shows how to use the cfdocument tag to create a cover page and add it to a merged PDF document:
<!--- Use the cfdocument tag to create a cover page and write the output to a variable called cfdoc. ---> <cfdocument format="PDF" name="cfdoc"> <html> <body> <h1>Here is a cover page</h1> </body> </html> </cfdocument> <!--- Use the cfpdf tag and cfpdfparam tags to merge individual PDF documents into a new PDF document called new.pdf. Notice that the cfdoc variable created by using the cfdocument tag is the source value of the first cfpdfparam tag. ---> <cfpdf action="merge" destination="/samtemp/pdfs/new.pdf" overwrite="yes"> <cfpdfparam source="cfdoc"> <cfpdfparam source="/samtemp/pdfs/pdf2.pdf"> <cfpdfparam source="/samtemp/pdfs/pdf1.pdf"> </cfpdf> You can use the cfpdf tag to assemble interactive PDF form files into a single PDF document and flatten forms created in Acrobat (by using the flatten attribute with the write action); however, to process PDF form data, use the cfpdfform and related tags. You cannot use the cfpdf tag to flatten forms created in Adobe LiveCycle Designer ES.
Example
The
following example generates thumbnail images from pages in a PDF document
and links the thumbnail images to the pages in the PDF document:
<h3>PDF Thumbnail Demo</h3>
<!--- Create a variable for the name of the PDF document. --->
<cfset mypdf="myBook">
<cfset thisPath=ExpandPath(".")>
<!--- Use the getInfo action to retrieve the total page count for the
PDF document. --->
<cfpdf action="getInfo" source="#mypdf#.pdf" name="PDFInfo">
<cfset pageCount="#PDFInfo.TotalPages#">
<!--- Generate a thumbnail image for each page in the PDF source document,
create a directory (if it doesn't already 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. --->
<cfpdf action="thumbnail" source="#mypdf#.pdf" overwrite="yes"
destination="#mypdf#_thumbnails" scale=60>
<!--- Loop through the images in the thumbnail directory and generate a link
from each image to the corresponding page in the PDF document. --->
<cfloop index="LoopCount" from ="1" to="#pageCount#" step="1">
<cfoutput>
<!--- Click the thumbnail image to navigate to the page in the PDF
document. --->
<a href="#mypdf#.pdf##page=#LoopCount#" target="_blank">
<img src="#mypdf#_thumbnails/#mypdf#_page_#LoopCount#.jpg"></a>
</cfoutput>
</cfloop>