Based on the official Java sample project by Adobe found here.
This sample project helps you get started with the PDF Services Java SDK for use with Adobe's Document Services API.
The sample ColdFusion Components illustrate how to perform PDF-related actions (such as converting to and from the PDF format) using the SDK. Please note that the PDF Services Java SDK supports only server side use cases.
The sample application has the following requirements:
- Java JDK: Version 8 or above.
- A CFML Engine: Adobe ColdFusion 2016+ (default) or Lucee 5+, as either a standalone install or via CommandBox (recommended).
The credentials file and corresponding private key file for the samples is pdfservices-api-credentials.json
and private.key
respectively. Before the samples can be run, replace both the files with the ones present in the downloaded zip file at
the end of creation of credentials via Get Started workflow.
The SDK also supports providing the authentication credentials at runtime, without storing them in a config file. Please refer this section to know more.
The SDK supports setting up custom socket timeout or connect timeout for the API calls. Please refer this section to know more.
The SDK also supports setting up Proxy Server configurations which helps in successful API calls for network where all outgoing calls have to go through a proxy else, they are blocked. Please refer this section to know more.
If you receive ServiceUsageException during the Samples run, it means that trial credentials have exhausted their quota of 5000 pages. Contact Adobe to get paid credentials.
Maven must be installed in order to properly pull in the JAR dependencies. Maven installation instructions can be found here.
Run the following command to build the project dependencies into a usable JAR and placed into the /lib directory:
mvn clean install
Note: The PDF Services SDK is listed as a dependency in the pom.xml and will be downloaded automatically. The project JAR is already built with the necessary dependencies and included in the project for use. If you need to re-build the project dependencies, you may run the build process described above.
Javadocs for the current and previous versions of the PDF Services library can be obtained from the official Java sample project.
Unlike the Java samples which use the slf4j API with a log4j2-slf4j binding, logging in the example CFCs is handled through the native CFML writeLog()
function. To avoid any classpath conflicts, the pom.xml excludes the slf4j API JAR dependency.
To execute the samples, you will need to run the project from a local installation of a ColdFusion server or stand up a server instance on the fly via CommandBox.
To start a server using CommandBox, run box start
in your terminal while pointing to the project working directory. The server will start on port 8520
and be available in the browser at http://127.0.0.1:8520
. Note that by default the server will start using the latest version of Adobe ColdFusion 2021
. To use a different version/engine, update the cfengine
in server.json
.
The following sub-sections describe how to run the samples. Prior to running the samples, check that the configuration file is set up as described above and that the project has been built.
The code itself is in the components
folder. The CFCs are executed in the browser via CFM pages found in samples
. Test files used by the CFCs can be found in resources
. When executed, all samples create an output
folder under the working directory to store their results.
These samples illustrate how to convert files of some formats to PDF.
The sample CFC CreatePDFFromDOCX creates a PDF file from a DOCX file.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=createpdf.CreatePDFFromDOCX
CommandBox:
box task run taskFile=Exec :cfcPath=createpdf.CreatePDFFromDOCX
The sample CFC CreatePDFFromDOCXWithOptions creates a PDF file from a DOCX file by setting documentLanguage as the language of input file.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=createpdf.CreatePDFFromDOCXWithOptions
CommandBox:
box task run taskFile=Exec :cfcPath=createpdf.CreatePDFFromDOCXWithOptions
The sample CFC CreatePDFFromDOCXInputStream creates a PDF file from a DOCX input stream.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=createpdf.CreatePDFFromDOCXInputStream
CommandBox:
box task run taskFile=Exec :cfcPath=createpdf.CreatePDFFromDOCXInputStream
The sample CFC CreatePDFFromDOCXToOutputStream creates a PDF file from a DOCX file. Instead of saving the result to a local file, it writes the result to an output stream.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=createpdf.CreatePDFFromDOCXToOutputStream
CommandBox:
box task run taskFile=Exec :cfcPath=createpdf.CreatePDFFromDOCXToOutputStream
The sample CFC CreatePDFFromPPTX creates a PDF file from a PPTX file.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=createpdf.CreatePDFFromPPTX
CommandBox:
box task run taskFile=Exec :cfcPath=createpdf.CreatePDFFromPPTX
The sample CFC CreatePDFFromStaticHTML creates a PDF file from a zip file containing the input HTML file and its resources.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=createpdf.CreatePDFFromStaticHTML
CommandBox:
box task run taskFile=Exec :cfcPath=createpdf.CreatePDFFromStaticHTML
The sample CFC CreatePDFFromHTMLWithInlineCSS creates a PDF file from an input HTML file with inline CSS.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=createpdf.CreatePDFFromHTMLWithInlineCSS
CommandBox:
box task run taskFile=Exec :cfcPath=createpdf.CreatePDFFromHTMLWithInlineCSS
The sample CFC CreatePDFFromURL creates a PDF file rom an HTML specified via URL.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=createpdf.CreatePDFFromURL
CommandBox:
box task run taskFile=Exec :cfcPath=createpdf.CreatePDFFromURL
The sample CFC CreatePDFFromDynamicHTML converts a zip file, containing the input HTML file and its resources, along with the input data to a PDF file. The input data is used by the JavaScript in the HTML file to manipulate the HTML DOM, thus effectively updating the source HTML file. This mechanism can be used to provide data to the template HTML dynamically and then, convert it into a PDF file.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=createpdf.CreatePDFFromDynamicHTML
CommandBox:
box task run taskFile=Exec :cfcPath=createpdf.CreatePDFFromDynamicHTML
The sample CFC CreatePDFWithInMemoryAuthCredentials
highlights how to provide in-memory auth credentials for performing an operation. This enables the clients to fetch the credentials from a secret server during runtime, instead of storing them in a file.
Before running the sample, authentication credentials need to be updated as per the instructions in the CFC.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=createpdf.CreatePDFWithInMemoryAuthCredentials
CommandBox:
box task run taskFile=Exec :cfcPath=createpdf.CreatePDFWithInMemoryAuthCredentials
The sample project CreatePDFWithCustomTimeouts highlights how to provide the custom value for connection timeout and socket timeout.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=createpdf.CreatePDFWithCustomTimeouts
CommandBox:
box task run taskFile=Exec :cfcPath=createpdf.CreatePDFWithCustomTimeouts
The sample project CreatePDFWithPorxyServer highlights how to provide Proxy Server configurations to allow all API calls via that proxy Server.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=createpdf.CreatePDFWithProxyServer
CommandBox:
box task run taskFile=Exec :cfcPath=createpdf.CreatePDFWithProxyServer
These samples illustrate how to export PDF files to other formats.
The sample CFC ExportPDFToDOCX converts a PDF file to a DOCX file.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=exportpdf.ExportPDFToDOCX
CommandBox:
box task run taskFile=Exec :cfcPath=exportpdf.ExportPDFToDOCX
The sample CFC ExportPDFToDOCXWithOCROption converts a PDF file to a DOCX file. OCR processing is also performed on the input PDF file to extract text from images in the document.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=exportpdf.ExportPDFToDOCXWithOCROption
CommandBox:
box task run taskFile=Exec :cfcPath=exportpdf.ExportPDFToDOCXWithOCROption
The sample CFC ExportPDFToJPEG converts a PDF file's pages to a list of JPEG images.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=exportpdftoimages.ExportPDFToJPEG
CommandBox:
box task run taskFile=Exec :cfcPath=exportpdftoimages.ExportPDFToJPEG
The sample CFC ExportPDFToJPEGZip converts a PDF file's pages to JPEG images. The resulting file is a ZIP archive containing one image per page of the source PDF file.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=exportpdftoimages.ExportPDFToJPEGZip
CommandBox:
box task run taskFile=Exec :cfcPath=exportpdftoimages.ExportPDFToJPEGZip
These samples illustrate how to combine multiple PDF files into a single PDF file.
The sample CFC CombinePDF combines multiple PDF files into a single PDF file. The combined PDF file contains all pages of the source files.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=combinepdf.CombinePDF
CommandBox:
box task run taskFile=Exec :cfcPath=combinepdf.CombinePDF
The sample CFC CombinePDFWithPageRanges combines specific pages of multiple PDF files into into a single PDF file.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=combinepdf.CombinePDFWithPageRanges
CommandBox:
box task run taskFile=Exec :cfcPath=combinepdf.CombinePDFWithPageRanges
These samples illustrate how to apply OCR(Optical Character Recognition) to a PDF file and convert it to a searchable copy of your PDF. The supported input format is application/pdf.
The sample CFC OcrPDF converts a PDF file into a searchable PDF file.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=ocrpdf.OcrPDF
CommandBox:
box task run taskFile=Exec :cfcPath=ocrpdf.OcrPDF
The sample CFC OcrPDFWithOptions converts a PDF file to a searchable PDF file with maximum fidelity to the original image and default en-us locale. Refer to the documentation of OCRSupportedLocale and OCRSupportedType to see the list of supported OCR locales and OCR types.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=ocrpdf.OcrPDFWithOptions
CommandBox:
box task run taskFile=Exec :cfcPath=ocrpdf.OcrPDFWithOptions
These samples illustrate how to reduce the size of a PDF file.
The sample CFC CompressPDF reduces the size of a PDF file.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=compresspdf.CompressPDF
CommandBox:
box task run taskFile=Exec :cfcPath=compresspdf.CompressPDF
The sample CFC CompressPDFWithOptions reduces the size of a PDF file on the basis of provided compression level. Refer to the documentation of CompressionLevel to see the list of supported compression levels.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=compresspdf.CompressPDFWithOptions
CommandBox:
box task run taskFile=Exec :cfcPath=compresspdf.CompressPDFWithOptions
The sample illustrates how to convert a PDF file into a Linearized (also known as "web optimized") PDF file. Such PDF files are optimized for incremental access in network environments.
The sample CFC LinearizePDF optimizes the PDF file for a faster Web View.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=linearizepdf.LinearizePDF
CommandBox:
box task run taskFile=Exec :cfcPath=linearizepdf.LinearizePDF
The sample illustrates how to secure a PDF file with a password.
The sample CFC ProtectPDF converts a PDF file into a password protected PDF file.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=protectpdf.ProtectPDF
CommandBox:
box task run taskFile=Exec :cfcPath=protectpdf.ProtectPDF
The sample CFC ProtectPDFWithOwnerPassword secures an input PDF file with owner password and allows certain access permissions such as copying and editing the contents, and printing of the document at low resolution.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=protectpdf.ProtectPDFWithOwnerPassword
CommandBox:
box task run taskFile=Exec :cfcPath=protectpdf.ProtectPDFWithOwnerPassword
The sample illustrates how to remove a password security from a PDF document.
The sample CFC RemoveProtection removes a password security from a secured PDF document.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=removeprotection.RemoveProtection
CommandBox:
box task run taskFile=Exec :cfcPath=removeprotection.RemoveProtection
The sample illustrates how to rotate pages in a PDF file.
The sample CFC RotatePDFPages rotates specific pages in a PDF file.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=rotatepages.RotatePDFPages
CommandBox:
box task run taskFile=Exec :cfcPath=rotatepages.RotatePDFPages
The sample illustrates how to delete pages in a PDF file.
The sample CFC DeletePDFPages removes specific pages from a PDF file.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=deletepages.DeletePDFPages
CommandBox:
box task run taskFile=Exec :cfcPath=deletepages.DeletePDFPages
The sample illustrates how to reorder the pages in a PDF file.
The sample CFC ReorderPDFPages rearranges the pages of a PDF file according to the specified order.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=reorderpages.ReorderPDFPages
CommandBox:
box task run taskFile=Exec :cfcPath=reorderpages.ReorderPDFPages
The sample illustrates how to insert pages in a PDF file.
The sample CFC InsertPDFPages inserts pages of multiple PDF files into a base PDF file.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=insertpages.InsertPDFPages
CommandBox:
box task run taskFile=Exec :cfcPath=insertpages.InsertPDFPages
The sample illustrates how to replace pages of a PDF file.
The sample CFC ReplacePDFPages replaces specific pages in a PDF file with pages from multiple PDF files.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=replacepages.ReplacePDFPages
CommandBox:
box task run taskFile=Exec :cfcPath=replacepages.ReplacePDFPages
These samples illustrate how to split PDF file into multiple PDF files.
The sample CFC SplitPDFByNumberOfPages splits input PDF into multiple PDF files on the basis of the maximum number of pages each of the output files can have.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=splitpdf.SplitPDFByNumberOfPages
CommandBox:
box task run taskFile=Exec :cfcPath=splitpdf.SplitPDFByNumberOfPages
The sample CFC SplitPDFIntoNumberOfFiles splits input PDF into multiple PDF files on the basis of the number of documents.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=splitpdf.SplitPDFIntoNumberOfFiles
CommandBox:
box task run taskFile=Exec :cfcPath=splitpdf.SplitPDFIntoNumberOfFiles
The sample CFC SplitPDFByPageRanges splits input PDF into multiple PDF files on the basis of page ranges. Each page range corresponds to a single output file having the pages specified in the page range.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=splitpdf.SplitPDFByPageRanges
CommandBox:
box task run taskFile=Exec :cfcPath=splitpdf.SplitPDFByPageRanges
Adobe Document Merge Operation allows you to produce high fidelity PDF and Word documents with dynamic data inputs. Using this operation, you can merge your JSON data with Word templates to create dynamic documents for contracts and agreements, invoices, proposals, reports, forms, branded marketing documents and more.
To know more about document generation and document templates, please checkout the documentation
The sample CFC MergeDocumentToDOCX merges the Word based document template with the input JSON data and fragments JSON to generate the output document in the DOCX format.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=documentmerge.MergeDocumentToDOCXWithFragments
CommandBox:
box task run taskFile=Exec :cfcPath=documentmerge.MergeDocumentToDOCXWithFragments
The sample CFC MergeDocumentToDOCX merges the Word based document template with the input JSON data to generate the output document in the DOCX format.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=documentmerge.MergeDocumentToDOCX
CommandBox:
box task run taskFile=Exec :cfcPath=documentmerge.MergeDocumentToDOCX
The sample CFC MergeDocumentToPDF merges the Word based document template with the input JSON data to generate the output document in the PDF format.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=documentmerge.MergeDocumentToPDF
CommandBox:
box task run taskFile=Exec :cfcPath=documentmerge.MergeDocumentToPDF
These samples illustrate extracting content of PDF in a structured JSON format along with the renditions inside PDF. The output of SDK extract operation is Zip package. The Zip package consists of following:
- The structuredData.json file with the extracted content & PDF element structure. See the JSON schema. Please refer the Styling JSON schema for a description of the output when the styling option is enabled.
- A renditions folder(s) containing renditions for each element type selected as input. The folder name is either "tables" or "figures" depending on your specified element type. Each folder contains renditions with filenames that correspond to the element information in the JSON file.
The sample CFC ExtractTextInfoFromPDF.cfc extracts text elements from PDF document.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=extractpdf.ExtractTextInfoFromPDF
CommandBox:
box task run taskFile=Exec :cfcPath=extractpdf.ExtractTextInfoFromPDF
The sample CFC ExtractTextTableInfoFromPDF extracts text, table elements from PDF document.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=extractpdf.ExtractTextTableInfoFromPDF
CommandBox:
box task run taskFile=Exec :cfcPath=extractpdf.ExtractTextTableInfoFromPDF
The sample CFC ExtractTextTableInfoWithRenditionsFromPDF extracts text, table elements along with table renditions from PDF document. Note that the output is a zip containing the structured information along with renditions as described in section.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=extractpdf.ExtractTextTableInfoWithRenditionsFromPDF
CommandBox:
box task run taskFile=Exec :cfcPath=extractpdf.ExtractTextTableInfoWithRenditionsFromPDF
The sample CFC ExtractTextTableInfoWithFiguresTablesRenditionsFromPDF extracts text, table elements along with figure and table element's renditions from PDF document. Note that the output is a zip containing the structured information along with renditions as described in section.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=extractpdf.ExtractTextTableInfoWithFiguresTablesRenditionsFromPDF
CommandBox:
box task run taskFile=Exec :cfcPath=extractpdf.ExtractTextTableInfoWithFiguresTablesRenditionsFromPDF
The sample CFC ExtractTextInfoWithCharBoundsFromPDF extracts text elements and bounding boxes for characters present in text blocks. Note that the output is a zip containing the structured information along with renditions as described in section.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=extractpdf.ExtractTextInfoWithCharBoundsFromPDF
CommandBox:
box task run taskFile=Exec :cfcPath=extractpdf.ExtractTextInfoWithCharBoundsFromPDF
Extract Text, Table Elements and bounding boxes for Characters present in text blocks with Renditions of Table Elements
The sample CFC ExtractTextTableInfoWithCharBoundsFromPDF extracts text, table elements, bounding boxes for characters present in text blocks and table element's renditions from PDF document. Note that the output is a zip containing the structured information along with renditions as described in section.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=extractpdf.ExtractTextTableInfoWithCharBoundsFromPDF
CommandBox:
box task run taskFile=Exec :cfcPath=extractpdf.ExtractTextTableInfoWithCharBoundsFromPDF
The sample CFC ExtractTextTableInfoWithTableStructureFromPdf extracts text, table elements, table structures as CSV and table element's renditions from PDF document. Note that the output is a zip containing the structured information along with renditions as described in section.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=extractpdf.ExtractTextTableInfoWithTableStructureFromPdf
CommandBox:
box task run taskFile=Exec :cfcPath=extractpdf.ExtractTextTableInfoWithTableStructureFromPdf
The sample CFC ExtractTextTableInfoWithStylingFromPDF extracts text and table elements along with the styling information of the text blocks. Note that the output is a zip containing the structured information along with renditions as described in section.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=extractpdf.ExtractTextTableInfoWithStylingFromPDF
CommandBox:
box task run taskFile=Exec :cfcPath=extractpdf.ExtractTextTableInfoWithStylingFromPDF
This sample illustrates how to fetch properties of a PDF file.
The sample CFC GetPDFProperties fetches the properties of an input PDF.
Browser:
http://127.0.0.1:8520/components/proxy.cfc?method=run&cfcPath=pdfproperties.GetPDFProperties
CommandBox:
box task run taskFile=Exec :cfcPath=pdfproperties.GetPDFProperties
This project is licensed under the MIT License to stay in compliance with the official Java sample project from Adobe. See LICENSE for more information.
Each sample CFC in this project was based on the original classes in the official Java project created by Adobe. All credit goes to the original creators/contributors. Thank you!