PDFServices.NET.SDK.Samples
This .NET sample solution helps you get started with the Adobe PDF Services SDK.
Install / Use
/learn @adobe/PDFServices.NET.SDK.SamplesREADME
Samples for the PDF Services .NET SDK
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.
Prerequisites
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.
Authentication Setup
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>
Client Configurations
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.
Quota Exhaustion
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.
Build with .NET Core CLI
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.
A Note on Logging
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.
Running the samples
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.
Create a PDF File
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.
Create a PDF File From a DOCX File
The sample project CreatePDFFromDocx creates a PDF file from a DOCX file.
cd CreatePDFFromDocx/
dotnet run CreatePDFFromDocx.csproj
Create a PDF File From a DOCX File with options
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
Create a PDF File From a PPTX File
The sample project CreatePDFFromPPTX creates a PDF file from a PPTX file.
cd CreatePDFFromPPTX/
dotnet run CreatePDFFromPPTX.csproj
Create a PDF File From HTML
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.
Create a PDF File From Static HTML (via Zip Archive)
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
Create a PDF File From Dynamic HTML (via Zip Archive)
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
Create a PDF File From a Static HTML file with inline CSS
The sample project HTMLWithInlineCSSToPDF creates a PDF file from an input HTML file with inline CSS.
cd HTMLWithInlineCSSToPDF/
dotnet run HTMLWithInlineCSSToPDF.csproj
Create a PDF File From HTML specified via URL
The sample project HTMLToPDFFromURL creates a PDF file from an HTML specified via URL.
cd HTMLToPDFFromURL/
dotnet run HTMLToPDFFromURL.csproj
Export PDF To Other Formats
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.
Export a PDF File To a DOCX File
The sample project ExportPDFToDocx converts a PDF file to a DOCX file.
cd ExportPDFToDocx/
dotnet run ExportPDFToDocx.csproj
Export a PDF file to a DOCX file (apply OCR on the PDF file)
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
Export a PDF File To an Image Format (JPEG)
The sample project ExportPDFToJPEG converts a PDF file's pages to a list of JPEG images.
cd ExportPDFToJPEG/
dotnet run ExportPDFToJPEG.csproj
Export a PDF File To a Zip of Images (JPEG)
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
Combine PDF Files
These samples illustrate how to combine multiple PDF files into a single PDF file.
Combine Multiple PDF Files
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
Combine Specific Pages of Multiple PDF Files
The sample project CombineFilesWithPageOptions combines specific pages of multiple PDF files into into a single PDF file.
cd CombinePDFWithPageRanges/
dotnet run CombinePDFWithPageRanges.csproj
OCR PDF File
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.
Convert a PDF File into a Searchable PDF File
The sample project OcrPDF converts a PDF file into a searchable PDF file.
cd OcrPDF/
dotnet run OcrPDF.csproj
Convert a PDF File into a Searchable PDF File while keeping the original image
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
Compress PDF File
The sample illustrates how to reduce the size of a PDF file.
Reduce PDF File Size
The sample project CompressPDF reduces the size of a PDF file.
cd CompressPDF/
dotnet run CompressPDF.csproj
Reduce PDF File Size on the basis of Compression Level
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
PDF Form Data Operations
These samples illustrate how to work with form data in PDF files.
Export Form Data from a PDF File
The sample project ExportPDFFormData extracts form data from a PDF file into a JSON file.
cd ExportPDFFormData/
dotnet run ExportPDFFormData.csproj
Import Form Data into a PDF File
The sample project ImportPDFFormData imports form data from a JSON file into a PDF form.
cd ImportPDFFormData/
dotnet run ImportPDFFormData.csproj
Linearize PDF File
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.
Convert a PDF File into a Web Optimized File
The sample project LinearizePDF optimizes the PDF file for a faster Web View.
cd LinearizePDF/
dotnet run LinearizePDF.csproj
Protect PDF File
These samples illus
