This sample solution helps you get started with the PDF Services .NET SDK.
The sample projects illustrate how to perform PDF-related actions (such as converting to and from the PDF format) using the PDF Services .NET SDK. Please note that the PDF Services .NET SDK supports only server side use cases.
The sample solution has the following requirements:
- .NET: version 8.0 or above
- Build Tool: The solution requires Visual studio or .NET Core CLI to be installed to be able to run the sample projects.
The credentials file for the samples is pdfservices-api-credentials.json
.
Before the samples can be run, set the environment variables PDF_SERVICES_CLIENT_ID
and PDF_SERVICES_CLIENT_SECRET
from the pdfservices-api-credentials.json
file downloaded at the end of creation of credentials via Get Started workflow by running the following commands :
- For MacOS/Linux Users :
export PDF_SERVICES_CLIENT_ID=<YOUR CLIENT ID>
export PDF_SERVICES_CLIENT_SECRET=<YOUR CLIENT SECRET>
- For Windows Users :
set PDF_SERVICES_CLIENT_ID=<YOUR CLIENT ID>
set PDF_SERVICES_CLIENT_SECRET=<YOUR CLIENT SECRET>
The SDK supports setting up custom 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.
Additionally, SDK can be configured to process the documents in the specified region. Please refer this section to know more.
If you receive ServiceUsageException during the Samples run, it means that trial credentials have exhausted their usage quota. Please contact us to get paid credentials.
Run the following command to build the project:
dotnet build
Note that the PDF Services SDK is listed as a dependency and will be downloaded automatically.
Following component is being used by SDK:
- LibLog (MIT) as bridge between different logging frameworks.
Log4net is used as a logging provider in the sample projects and the logging configurations are provided in log4net.config
.
Note: Add the configuration for your preferred provider and set up the necessary appender as required for logging to work.
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 is in the different sample projects under the solution folder. Test files used by the samples can be found in the project directory itself. When executed, all samples create an output
child folder under the working directory to store their results.
These samples illustrate how to convert files of some formats to PDF. Refer the documentation of CreatePDFOperation.cs to see the list of all supported media types which can be converted to PDF.
The sample project CreatePDFFromDocx creates a PDF file from a DOCX file.
cd CreatePDFFromDocx/
dotnet run CreatePDFFromDocx.csproj
The sample project CreatePDFFromDocxWithOptions creates a PDF file from a DOCX file by setting documentLanguage as the language of input file.
cd CreatePDFFromDocxWithOptions/
dotnet run CreatePDFFromDocxWithOptions.csproj
The sample project CreatePDFFromPPTX creates a PDF file from a PPTX file.
cd CreatePDFFromPPTX/
dotnet run CreatePDFFromPPTX.csproj
These samples illustrate how to convert HTML to PDF. Refer the HTML to PDF API documentation to see instructions on the structure of the zip file.
The sample project StaticHTMLToPDF creates a PDF file from a zip file containing the input HTML file and its resources.
cd StaticHTMLToPDF/
dotnet run StaticHTMLToPDF.csproj
The sample project DynamicHTMLToPDF 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.
cd DynamicHTMLToPDF/
dotnet run CreatePDFFromDynamicHtml.csproj
The sample project HTMLWithInlineCSSToPDF creates a PDF file from an input HTML file with inline CSS.
cd HTMLWithInlineCSSToPDF/
dotnet run HTMLWithInlineCSSToPDF.csproj
The sample project HTMLToPDFFromURL creates a PDF file from an HTML specified via URL.
cd HTMLToPDFFromURL/
dotnet run HTMLToPDFFromURL.csproj
These samples illustrate how to export PDF files to other formats. Refer to the documentation of ExportPDFOperation.cs and ExportPDFToImagesOperation.cs for supported export formats.
The sample project ExportPDFToDocx converts a PDF file to a DOCX file.
cd ExportPDFToDocx/
dotnet run ExportPDFToDocx.csproj
The sample project 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.
cd ExportPDFToDocxWithOCROption/
dotnet run ExportPDFToDocxWithOCROption.csproj
The sample project ExportPDFToJPEG converts a PDF file's pages to a list of JPEG images.
cd ExportPDFToJPEG/
dotnet run ExportPDFToJPEG.csproj
The sample project 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
cd ExportPDFToJPEGZip/
dotnet run ExportPDFToJPEGZip.csproj
These samples illustrate how to combine multiple PDF files into a single PDF file.
The sample project CombineFiles combines multiple PDF files into a single PDF file. The combined PDF file contains all pages of the source files.
cd CombinePDF/
dotnet run CombinePDF.csproj
The sample project CombineFilesWithPageOptions combines specific pages of multiple PDF files into into a single PDF file.
cd CombinePDFWithPageRanges/
dotnet run CombinePDFWithPageRanges.csproj
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 project OcrPDF converts a PDF file into a searchable PDF file.
cd OcrPDF/
dotnet run OcrPDF.csproj
The sample project 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.cs and OCRSupportedType.cs to see the list of supported OCR locales and OCR types.
cd OcrPDFWithOptions/
dotnet run OcrPDFWithOptions.csproj
The sample illustrates how to reduce the size of a PDF file.
The sample project CompressPDF reduces the size of a PDF file.
cd CompressPDF/
dotnet run CompressPDF.csproj
The sample project CompressPDFWithOptions reduces the size of a PDF file on the basis of provided compression level. Refer to the documentation of CompressionLevel.cs to see the list of supported compression levels.
cd CompressPDFWithOptions/
dotnet run CompressPDFWithOptions.csproj
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 project LinearizePDF optimizes the PDF file for a faster Web View.
cd LinearizePDF/
dotnet run LinearizePDF.csproj
These samples illustrate how to secure a PDF file with a password.
The sample project ProtectPDF converts a PDF file into a password protected PDF file.
cd ProtectPDF/
dotnet run ProtectPDF.csproj
The sample project 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.
cd ProtectPDFWithOwnerPassword/
dotnet run ProtectPDFWithOwnerPassword.csproj
The sample illustrates how to remove a password security from a PDF document.
The sample project RemoveProtection removes a password security from a secured PDF document.
cd RemoveProtection/
dotnet run RemoveProtection.csproj
The sample illustrates how to rotate pages in a PDF file.
The sample project RotatePDFPages rotates specific pages in a PDF file.
cd RotatePDFPages/
dotnet run RotatePDFPages.csproj
The sample illustrates how to delete pages in a PDF file.
The sample project DeletePDFPages removes specific pages from a PDF file.
cd DeletePDFPages/
dotnet run DeletePDFPages.csproj
The sample illustrates how to reorder the pages in a PDF file.
The sample project ReorderPDFPages rearranges the pages of a PDF file according to the specified order.
cd ReorderPDFPages/
dotnet run ReorderPDFPages.csproj
The sample illustrates how to insert pages in a PDF file.
The sample project InsertPDFPages inserts pages of multiple PDF files into a base PDF file.
cd InsertPDFPages/
dotnet run InsertPDFPages.csproj
The sample illustrates how to replace pages of a PDF file.
The sample project ReplacePDFPages replaces specific pages in a PDF file with pages from multiple PDF files.
cd ReplacePDFPages/
dotnet run ReplacePDFPages.csproj
These samples illustrate how to split PDF file into multiple PDF files.
The sample project SplitPDFByNumberOfPages splits input PDF into multiple PDF files on the basis of the maximum number of pages each of the output files can have.
cd SplitPDFByNumberOfPages/
dotnet run SplitPDFByNumberOfPages.csproj
The sample project SplitPDFIntoNumberOfFiles splits input PDF into multiple PDF files on the basis of the number of documents.
cd SplitPDFIntoNumberOfFiles/
dotnet run SplitPDFIntoNumberOfFiles.csproj
The sample project 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.
cd SplitPDFByPageRanges/
dotnet run SplitPDFByPageRanges.csproj
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 project MergeDocumentToDocx merges the Word based document template with the input JSON data to generate the output document in the DOCX format.
cd MergeDocumentToDocx/
dotnet run MergeDocumentToDocx.csproj
The sample project MergeDocumentToPDF merges the Word based document template with the input JSON data to generate the output document in the PDF format.
cd MergeDocumentToPDF/
dotnet run MergeDocumentToPDF.csproj
The sample project MergeDocumentToDocxFragments merges the Word based document template with the input JSON data and Fragments JSON to generate the output document in the Docx format.
cd MergeDocumentToDocxFragments/
dotnet run MergeDocumentToDocxFragments.csproj
These samples illustrate how to perform electronic seal over PDF documents like agreements, invoices, proposals, reports, forms, branded marketing documents and more. To know more about PDF Electronic Seal, please see the documentation. The following details needs to updated while executing these samples: PROVIDER_NAME, ACCESS_TOKEN, CREDENTIAL_ID and PIN.
The sample project ElectronicSeal uses the sealing options with default appearance options to apply electronic seal over the PDF document.
cd ElectronicSeal/
dotnet run ElectronicSeal.csproj
The sample project ElectronicSealWithAppearanceOptions uses the sealing options with custom appearance options to apply electronic seal over the PDF document.
cd ElectronicSealWithAppearanceOptions/
dotnet run ElectronicSealWithAppearanceOptions.csproj
The sample project ElectronicSealWithTimeStampAuthority uses a time stamp authority to apply electronic seal with trusted timestamp over the PDF document.
cd ElectronicSealWithTimeStampAuthority/
dotnet run ElectronicSealWithTimeStampAuthority.csproj
These samples illustrate extracting content of PDF in a structured JSON format along with the renditions inside PDF.
- The structuredData.json file with the extracted content & PDF element structure.
- 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 project ExtractTextInfoFromPDF extracts text elements from PDF document.
cd ExtractTextInfoFromPDF/
dotnet run ExtractTextInfoFromPDF.csproj
The sample project ExtractTextInfoWithCharBoundsFromPDF extracts text elements and bounding boxes for characters present in text blocks.
cd ExtractTextInfoWithCharBoundsFromPDF/
dotnet run ExtractTextInfoWithCharBoundsFromPDF.csproj
The sample project ExtractTextTableInfoFromPDF extracts text, table elements from PDF document.
cd ExtractTextTableInfoFromPDF/
dotnet run ExtractTextTableInfoFromPDF.csproj
Extract Text, Table Elements and bounding boxes for Characters present in text blocks with Renditions of Table Elements
The sample project ExtractTextTableInfoWithCharBoundsFromPDF extracts text, table elements, bounding boxes for characters present in text blocks and table element's renditions from PDF document.
cd ExtractTextTableInfoWithCharBoundsFromPDF/
dotnet run ExtractTextTableInfoWithCharBoundsFromPDF.csproj
The sample project ExtractTextTableInfoWithFiguresTablesRenditionsFromPDF extracts text, table elements along with figure and table element's renditions from PDF document.
cd ExtractTextTableInfoWithFiguresTablesRenditionsFromPDF/
dotnet run ExtractTextTableInfoWithFiguresTablesRenditionsFromPDF.csproj
The sample project ExtractTextTableInfoWithRenditionsFromPDF extracts text, table elements along with table renditions from PDF document.
cd ExtractTextTableInfoWithRenditionsFromPDF/
dotnet run ExtractTextTableInfoWithRenditionsFromPDF.csproj
The sample project ExtractTextTableInfoWithStylingFromPDF extracts text and table elements along with the styling information of the text blocks.
cd ExtractTextTableInfoWithStylingFromPDF/
dotnet run ExtractTextTableInfoWithStylingFromPDF.csproj
The sample project ExtractTextTableInfoWithTableStructureFromPdf extracts text, table elements, table structures as CSV and table element's renditions from PDF document.
cd ExtractTextTableInfoWithTableStructureFromPDF/
dotnet run ExtractTextTableInfoWithTableStructureFromPDF.csproj
This sample illustrates how to fetch properties of a PDF file
The sample project GetPDFProperties fetches the properties of an input PDF.
cd GetPDFProperties/
dotnet run GetPDFProperties.csproj
These samples illustrate how to add a watermark in PDF document.
The sample project PDFWatermark adds watermarking with default appearance options to apply watermark on the PDF document.
cd PDFWatermark/
dotnet run PDFWatermark.csproj
The sample project PDFWatermarkWithOptions adds watermarking with custom appearance options to apply watermark on the PDF document.
cd PDFWatermarkWithOptions/
dotnet run PDFWatermarkWithOptions.csproj
These samples illustrate how to provide a custom client configurations(timeouts, proxy and region).
The sample project CreatePDFWithCustomTimeouts highlights how to provide the custom value for timeout and read write timeout.
cd CreatePDFWithCustomTimeouts/
dotnet run CreatePDFWithCustomTimeouts.csproj
The sample project CreatePDFWithProxyServer highlights how to provide Proxy Server configurations to allow all API calls via that proxy Server.
cd CreatePDFWithProxyServer/
dotnet run CreatePDFWithProxyServer.csproj
The sample project CreatePDFWithAuthenticatedProxyServer highlights how to provide Proxy Server configurations to allow all API calls via that proxy Server that requires authentication.
cd CreatePDFWithAuthenticatedProxyServer/
dotnet run CreatePDFWithAuthenticatedProxyServer.csproj
The sample project ExportPDFWithSpecifiedRegion highlights how to configure the SDK to process the documents in the specified region.
cd ExportPDFWithSpecifiedRegion/
dotnet run ExportPDFWithSpecifiedRegion.csproj
These samples illustrate how to create a PDF document with enhanced readability from existing PDF document. All tags from the input file will be removed except for existing alt-text images and a new tagged PDF will be created as output. However, the generated PDF is not guaranteed to comply with accessibility standards such as WCAG and PDF/UA as you may need to perform further downstream remediation to meet those standards.
The sample project AutotagPDF highlights how to add tags to PDF document to make the PDF more accessible.
cd AutotagPDF/
dotnet run AutotagPDF.csproj
The sample project AutotagPDFWithOptions highlights how to add tags to PDF documents to make the PDF more accessible and also shift the headings in the output PDF file. Also, it generates a tagging report which contains the information about the tags that the tagged output PDF document contains.
cd AutotagPDFWithOptions/
dotnet run AutotagPDFWithOptions.csproj
The sample project AutotagPDFParameterised highlights how to add tags to PDF documents to make the PDF more accessible by setting options through command line arguments.
Here is a sample list of command line arguments and their description:
--input < input file path >
--output < output file path >
--report { If this argument is present then the output will be generated with the tagging report }
--shift_headings { If this argument is present then the headings will be shifted in the output PDF document }
cd AutotagPDFParameterised/
dotnet run AutotagPDFParameterised.csproj --report --shift_headings --input autotagPdfInput.pdf --output output/
This samples illustrate how to check PDF files to see if they meet the machine-verifiable requirements of PDF/UA and WCAG 2.0.
The sample project PDFAccessibilityChecker illustrates how to run accessibility Checker on input PDF file.
cd PDFAccessibilityChecker/
dotnet run PDFAccessibilityChecker.csproj
The sample project PDFAccessibilityCheckerWithOptions illustrates how to run accessibility Checker on input PDF file for given page start and page end.
cd PDFAccessibilityCheckerWithOptions/
dotnet run PDFAccessibilityCheckerWithOptions.csproj
These samples illustrate how to use external input and output storage for the supported operations.
The sample project ExternalInputCreatePDFFromDOCX creates a PDF file from a DOCX file stored at external storage.
cd ExternalInputCreatePDFFromDOCX/
dotnet run ExternalInputCreatePDFFromDOCX.csproj
Create a PDF File From a DOCX File Using External Input Storage and Store the Result in External Output Storage
The sample project ExternalInputAndOutputCreatePDFFromDOCX creates a PDF file from a DOCX file stored at external storage and stores the result in external output storage.
cd ExternalInputAndOutputCreatePDFFromDOCX/
dotnet run ExternalInputAndOutputCreatePDFFromDOCX.csproj
This project is licensed under the MIT License. See LICENSE for more information.