Create PDF
Create PDFs from a variety of formats, including static and dynamic HTML; Microsoft Word, PowerPoint, and Excel; as well as text, image, Zip, and URL. Support for HTML to PDF, DOC to PDF, DOCX to PDF, PPT to PDF, PPTX to PDF, XLS to PDF, XLSX to PDF, TXT to PDF, RTF to PDF, BMP to PDF, JPEG to PDF, GIF to PDF, TIFF to PDF, PNG to PDF
REST API
See our public API Reference for :
Create a PDF
Use the sample below to create PDFs from Microsoft Office documents (Word, Excel and PowerPoint) and other supported file formats. While the example shows .docx file conversion, the SDK supports the following formats:
- Microsoft Word (DOC, DOCX)
- Microsoft PowerPoint (PPT, PPTX)
- Microsoft Excel (XLS, XLSX)
- Text (TXT, RTF)
- Image (BMP, JPEG, GIF, TIFF, PNG)
If a Microsoft Word/PowerPoint input file has an embedded TrueType font, the output pdf will also contain the same embedded TrueType font. For more information, refer Benefits of embedding custom fonts.
Please refer the API usage guide to understand how to use our APIs.
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples2// Run the sample:3// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.createpdf.CreatePDFFromDOCX45public class CreatePDFFromDOCX {67 // Initialize the logger.8 private static final Logger LOGGER = LoggerFactory.getLogger(CreatePDFFromDOCX.class);910 public static void main(String[] args) {1112 try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/createPDFInput.docx").toPath())) {13 // Initial setup, create credentials instance14 Credentials credentials = new ServicePrincipalCredentials(15 System.getenv("PDF_SERVICES_CLIENT_ID"),16 System.getenv("PDF_SERVICES_CLIENT_SECRET"));1718 // Creates a PDF Services instance19 PDFServices pdfServices = new PDFServices(credentials);2021 // Creates an asset(s) from source file(s) and upload22 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.DOCX.getMediaType());2324 // Creates a new job instance25 CreatePDFJob createPDFJob = new CreatePDFJob(asset);2627 // Submit the job and gets the job result28 String location = pdfServices.submit(createPDFJob);29 PDFServicesResponse<CreatePDFResult> pdfServicesResponse = pdfServices.getJobResult(location, CreatePDFResult.class);3031 // Get content from the resulting asset(s)32 Asset resultAsset = pdfServicesResponse.getResult().getAsset();33 StreamAsset streamAsset = pdfServices.getContent(resultAsset);3435 // Creates an output stream and copy stream asset's content to it36 File.createDirectories(Paths.get("output/"));37 OutputStream outputStream = Files.newOutputStream(new File("output/createPDFFromDOCX.pdf").toPath());38 LOGGER.info("Saving asset at output/createPDFFromDOCX.pdf");39 IOUtils.copy(streamAsset.getInputStream(), outputStream);40 outputStream.close();41 } catch (ServiceApiException | IOException | SDKException | ServiceUsageException ex) {42 LOGGER.error("Exception encountered while executing the operation", ex);43 }44 }45}
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples2// Run the sample:3// cd CreatePDFFromDocx/4// dotnet run CreatePDFFromDocx.csproj56namespace CreatePDFFromDocx7 {8 class Program9 {10 private static readonly ILog log = LogManager.GetLogger(typeof(Program));11 static void Main()12 {13 //Configure the logging14 ConfigureLogging();15 try16 {17 // Initial setup, create credentials instance.18 Credentials credentials = Credentials.ServicePrincipalCredentialsBuilder()19 .WithClientId("PDF_SERVICES_CLIENT_ID")20 .WithClientSecret("PDF_SERVICES_CLIENT_SECRET")21 .Build();2223 //Create an ExecutionContext using credentials and create a new operation instance.24 ExecutionContext executionContext = ExecutionContext.Create(credentials);25 CreatePDFOperation createPdfOperation = CreatePDFOperation.CreateNew();2627 // Set operation input from a source file.28 FileRef source = FileRef.CreateFromLocalFile(@"createPdfInput.docx");29 createPdfOperation.SetInput(source);3031 // Execute the operation.32 FileRef result = createPdfOperation.Execute(executionContext);3334 // Save the result to the specified location.35 result.SaveAs(Directory.GetCurrentDirectory() + "/output/createPdfOutput.pdf");36 }37 catch (ServiceUsageException ex)38 {39 log.Error("Exception encountered while executing operation", ex);40 }41 // Catch more errors here. . .42 }4344 static void ConfigureLogging()45 {46 ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());47 XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));48 }49 }50 }
Copied to your clipboard1// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample2// Run the sample:3// node src/createpdf/create-pdf-from-docx.js45const {6 ServicePrincipalCredentials,7 PDFServices,8 MimeType,9 CreatePDFJob,10 CreatePDFResult,11 SDKError,12 ServiceUsageError,13 ServiceApiError14} = require("@adobe/pdfservices-node-sdk");15const fs = require("fs");1617(async () => {18 let readStream;19 try {20 // Initial setup, create credentials instance21 const credentials = new ServicePrincipalCredentials({22 clientId: process.env.PDF_SERVICES_CLIENT_ID,23 clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET24 });2526 // Creates a PDF Services instance27 const pdfServices = new PDFServices({credentials});2829 // Creates an asset(s) from source file(s) and upload30 readStream = fs.createReadStream("./createPDFInput.docx");31 const inputAsset = await pdfServices.upload({32 readStream,33 mimeType: MimeType.DOCX34 });3536 // Creates a new job instance37 const job = new CreatePDFJob({inputAsset});3839 // Submit the job and get the job result40 const pollingURL = await pdfServices.submit({job});41 const pdfServicesResponse = await pdfServices.getJobResult({42 pollingURL,43 resultType: CreatePDFResult44 });4546 // Get content from the resulting asset(s)47 const resultAsset = pdfServicesResponse.result.asset;48 const streamAsset = await pdfServices.getContent({asset: resultAsset});4950 // Creates an output stream and copy result asset's content to it51 const outputFilePath = "./createPDFFromDOCX.pdf";52 console.log(`Saving asset at ${outputFilePath}`);5354 const outputStream = fs.createWriteStream(outputFilePath);55 streamAsset.readStream.pipe(outputStream);56 } catch (err) {57 if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {58 console.log("Exception encountered while executing operation", err);59 } else {60 console.log("Exception encountered while executing operation", err);61 }62 } finally {63 readStream?.destroy();64 }65})();
Copied to your clipboard1// Please refer our REST API docs for more information2// https://developer.adobe.com/document-services/docs/apis/#tag/Create-PDF34curl --location --request POST 'https://pdf-services.adobe.io/operation/createpdf' \5--header 'x-api-key: {{Placeholder for client_id}}' \6--header 'Content-Type: application/json' \7--header 'Authorization: Bearer {{Placeholder for token}}' \8--data-raw '{9 "assetID": "urn:aaid:AS:UE1:23c30ee0-2e4d-46d6-87f2-087832fca718"10}'
Create PDF with DocumentLanguage
Use the sample below to create PDFs with supported documentLanguage from Microsoft Office documents (Word, Excel and PowerPoint). The example shows .docx file conversion with english as the language of the input file, the SDK supports the following formats:
- Microsoft Word (DOC, DOCX)
- Microsoft PowerPoint (PPT, PPTX)
- Microsoft Excel (XLS, XLSX)
- Text (TXT, RTF)
Please refer the API usage guide to understand how to use our APIs.
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples2// Run the sample:3// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.createpdf.CreatePDFFromDOCXWithOptions45public class CreatePDFFromDOCXWithOptions {67 // Initialize the logger.8 private static final Logger LOGGER = LoggerFactory.getLogger(CreatePDFFromDOCXWithOptions.class);910 public static void main(String[] args) {1112 try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/createPDFInput.docx").toPath())) {13 // Initial setup, create credentials instance14 Credentials credentials = new ServicePrincipalCredentials(15 System.getenv("PDF_SERVICES_CLIENT_ID"),16 System.getenv("PDF_SERVICES_CLIENT_SECRET"));1718 // Creates a PDF Services instance19 PDFServices pdfServices = new PDFServices(credentials);2021 // Creates an asset(s) from source file(s) and upload22 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.DOCX.getMediaType());2324 // Create parameters for the job25 CreatePDFParams createPDFWordParams = CreatePDFParams.wordParamsBuilder().26 withDocumentLanguage(DocumentLanguage.EN_US).27 build();2829 // Creates a new job instance30 CreatePDFJob createPDFJob = new CreatePDFJob(asset)31 .setParams(createPDFWordParams);3233 // Submit the job and gets the job result34 String location = pdfServices.submit(createPDFJob);35 PDFServicesResponse<CreatePDFResult> pdfServicesResponse = pdfServices.getJobResult(location, CreatePDFResult.class);3637 // Get content from the resulting asset(s)38 Asset resultAsset = pdfServicesResponse.getResult().getAsset();39 StreamAsset streamAsset = pdfServices.getContent(resultAsset);4041 // Creates an output stream and copy stream asset's content to it42 File.createDirectories(Paths.get("output/"));43 OutputStream outputStream = Files.newOutputStream(new File("output/createPDFFromDOCXWithOptionsOutput.pdf").toPath());44 LOGGER.info("Saving asset at output/createPDFFromDOCXWithOptionsOutput.pdf");45 IOUtils.copy(streamAsset.getInputStream(), outputStream);46 outputStream.close();47 } catch (ServiceApiException | IOException | SDKException | ServiceUsageException ex) {48 LOGGER.error("Exception encountered while executing operation", ex);49 }50 }51 }
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples2// Run the sample:3// cd CreatePDFFromDocxWithOptions/4// dotnet run CreatePDFFromDocxWithOptions.csproj56namespace CreatePDFFromDocxWithOptions7 {8 class Program9 {10 private static readonly ILog log = LogManager.GetLogger(typeof(Program));11 static void Main()12 {13 //Configure the logging14 ConfigureLogging();15 try16 {17 // Initial setup, create credentials instance.18 Credentials credentials = Credentials.ServicePrincipalCredentialsBuilder()19 .WithClientId("PDF_SERVICES_CLIENT_ID")20 .WithClientSecret("PDF_SERVICES_CLIENT_SECRET")21 .Build();2223 //Create an ExecutionContext using credentials and create a new operation instance.24 ExecutionContext executionContext = ExecutionContext.Create(credentials);25 CreatePDFOperation createPdfOperation = CreatePDFOperation.CreateNew();2627 // Set operation input from a source file.28 FileRef source = FileRef.CreateFromLocalFile(@"createPdfInput.docx");29 createPdfOperation.SetInput(source);3031 //Provide any custom conifguration option for the operation.32 SetCustomOptions(createPdfOperation);3334 // Execute the operation.35 FileRef result = createPdfOperation.Execute(executionContext);3637 // Save the result to the specified location.38 result.SaveAs(Directory.GetCurrentDirectory() + "/output/createPDFFromDOCXWithOptionsOutput.pdf");39 }40 catch (ServiceUsageException ex)41 {42 log.Error("Exception encountered while executing operation", ex);43 }44 // Catch more errors here. . .45 }4647 private static void SetCustomOptions(CreatePDFOperation createPdfOperation)48 {49 // Select the documentLanguage for input file.50 SupportedDocumentLanguage documentLanguage = SupportedDocumentLanguage.EN_US;5152 // Set the desired Word-to-PDF conversion options.53 CreatePDFOptions createPDFOptions = CreatePDFOptions.WordOptionsBuilder()54 .WithDocumentLanguage(documentLanguage)55 .Build();56 createPdfOperation.SetOptions(createPDFOptions);57 }5859 static void ConfigureLogging()60 {61 ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());62 XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));63 }64 }65 }
Copied to your clipboard1// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample2// Run the sample:3// node src/createpdf/create-pdf-from-docx-with-options.js45const {6 ServicePrincipalCredentials,7 PDFServices,8 MimeType,9 CreatePDFJob,10 CreatePDFParams,11 CreatePDFResult,12 DocumentLanguage,13 SDKError,14 ServiceUsageError,15 ServiceApiError16} = require("@adobe/pdfservices-node-sdk");17const fs = require("fs");1819(async () => {20 let readStream;21 try {22 // Initial setup, create credentials instance23 const credentials = new ServicePrincipalCredentials({24 clientId: process.env.PDF_SERVICES_CLIENT_ID,25 clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET26 });2728 // Creates a PDF Services instance29 const pdfServices = new PDFServices({credentials});3031 // Creates an asset(s) from source file(s) and upload32 readStream = fs.createReadStream("./createPDFInput.docx");33 const inputAsset = await pdfServices.upload({34 readStream,35 mimeType: MimeType.DOCX36 });3738 // Create parameters for the job39 const params = new CreatePDFParams({40 documentLanguage: DocumentLanguage.EN_US41 });4243 // Creates a new job instance44 const job = new CreatePDFJob({inputAsset, params});4546 // Submit the job and get the job result47 const pollingURL = await pdfServices.submit({job});48 const pdfServicesResponse = await pdfServices.getJobResult({49 pollingURL,50 resultType: CreatePDFResult51 });5253 // Get content from the resulting asset(s)54 const resultAsset = pdfServicesResponse.result.asset;55 const streamAsset = await pdfServices.getContent({asset: resultAsset});5657 // Creates an output stream and copy result asset's content to it58 const outputFilePath = "./createPDFFromDOCXWithOptionsOutput.pdf";59 console.log(`Saving asset at ${outputFilePath}`);6061 const outputStream = fs.createWriteStream(outputFilePath);62 streamAsset.readStream.pipe(outputStream);63 } catch (err) {64 if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {65 console.log("Exception encountered while executing operation", err);66 } else {67 console.log("Exception encountered while executing operation", err);68 }69 } finally {70 readStream?.destroy();71 }72})();
Copied to your clipboard1// Please refer our REST API docs for more information2// https://developer.adobe.com/document-services/docs/apis/#tag/Create-PDF34curl --location --request POST 'https://pdf-services.adobe.io/operation/createpdf' \5--header 'x-api-key: {{Placeholder for client_id}}' \6--header 'Content-Type: application/json' \7--header 'Authorization: Bearer {{Placeholder for token}}' \8--data-raw '{9 "assetID": "urn:aaid:AS:UE1:23c30ee0-2e4d-46d6-87f2-087832fca718",10 "documentLanguage": "en-US"11}'
Create a PDF from static HTML
The sample below creates a PDF file from a static HTML file. The file must be local. Since HTML/web pages typically contain external assets, the input file must be a zip file containing an index.html at the top level of the archive as well as any dependencies such as images, css files, and so on.
Please refer the API usage guide to understand how to use our APIs.
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples2// Run the sample:3// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.htmltopdf.StaticHTMLToPDF45public class StaticHTMLToPDF {67 // Initialize the logger.8 private static final Logger LOGGER = LoggerFactory.getLogger(StaticHTMLToPDF.class);910 public static void main(String[] args) {1112 try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/createPDFFromStaticHtmlInput.zip").toPath())) {13 // Initial setup, create credentials instance14 Credentials credentials = new ServicePrincipalCredentials(15 System.getenv("PDF_SERVICES_CLIENT_ID"),16 System.getenv("PDF_SERVICES_CLIENT_SECRET"));1718 // Creates a PDF Services instance19 PDFServices pdfServices = new PDFServices(credentials);2021 // Creates an asset(s) from source file(s) and upload22 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.ZIP.getMediaType());2324 // Create parameters for the job25 HTMLToPDFParams htmlToPDFParams = getHTMLToPDFParams();2627 // Creates a new job instance28 HTMLToPDFJob htmLtoPDFJob = new HTMLToPDFJob(asset)29 .setParams(htmlToPDFParams);3031 // Submit the job and gets the job result32 String location = pdfServices.submit(htmLtoPDFJob);33 PDFServicesResponse<HTMLToPDFResult> pdfServicesResponse = pdfServices.getJobResult(location, HTMLToPDFResult.class);3435 // Get content from the resulting asset(s)36 Asset resultAsset = pdfServicesResponse.getResult().getAsset();37 StreamAsset streamAsset = pdfServices.getContent(resultAsset);3839 // Creates an output stream and copy stream asset's content to it40 File.createDirectories(Paths.get("output/"));41 OutputStream outputStream = Files.newOutputStream(new File("output/staticHTMLToPDFOutput.pdf").toPath());42 LOGGER.info("Saving asset at output/staticHTMLToPDFOutput.pdf");43 IOUtils.copy(streamAsset.getInputStream(), outputStream);44 outputStream.close();45 } catch (ServiceApiException | IOException | SDKException | ServiceUsageException ex) {46 LOGGER.error("Exception encountered while executing operation", ex);47 }48 }49 private static HTMLToPDFParams getHTMLToPDFParams() {50 // Define the page layout, in this case an 8 x 11.5 inch page (effectively portrait orientation)51 PageLayout pageLayout = new PageLayout();52 pageLayout.setPageSize(8, 11.5);5354 return new HTMLToPDFParams.Builder()55 .includeHeaderFooter(true).withPageLayout(pageLayout)56 .build();57 }58}
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples2// Run the sample:3// cd CreatePDFFromStaticHtml/4// dotnet run CreatePDFFromStaticHtml.csproj56namespace CreatePDFFromStaticHtml7 {8 class Program9 {10 private static readonly ILog log = LogManager.GetLogger(typeof(Program));11 static void Main()12 {13 //Configure the logging14 ConfigureLogging();15 try16 {17 // Initial setup, create credentials instance.18 Credentials credentials = Credentials.ServicePrincipalCredentialsBuilder()19 .WithClientId("PDF_SERVICES_CLIENT_ID")20 .WithClientSecret("PDF_SERVICES_CLIENT_SECRET")21 .Build();2223 //Create an ExecutionContext using credentials and create a new operation instance.24 ExecutionContext executionContext = ExecutionContext.Create(credentials);25 CreatePDFOperation htmlToPDFOperation = CreatePDFOperation.CreateNew();2627 // Set operation input from a source file.28 FileRef source = FileRef.CreateFromLocalFile(@"createPDFFromStaticHtmlInput.zip");29 htmlToPDFOperation.SetInput(source);3031 // Provide any custom configuration options for the operation.32 SetCustomOptions(htmlToPDFOperation);3334 // Execute the operation.35 FileRef result = htmlToPDFOperation.Execute(executionContext);3637 // Save the result to the specified location.38 result.SaveAs(Directory.GetCurrentDirectory() + "/output/createPdfFromStaticHtmlOutput.pdf");39 }40 catch (ServiceUsageException ex)41 {42 log.Error("Exception encountered while executing operation", ex);43 }44 // Catch more errors here. . .45 }4647 private static void SetCustomOptions(CreatePDFOperation htmlToPDFOperation)48 {49 // Define the page layout, in this case an 8 x 11.5 inch page (effectively portrait orientation).50 PageLayout pageLayout = new PageLayout();51 pageLayout.SetPageSize(8, 11.5);5253 // Set the desired HTML-to-PDF conversion options.54 CreatePDFOptions htmlToPdfOptions = CreatePDFOptions.HtmlOptionsBuilder()55 .IncludeHeaderFooter(true)56 .WithPageLayout(pageLayout)57 . Build();58 htmlToPDFOperation.SetOptions(htmlToPdfOptions);59 }6061 static void ConfigureLogging()62 {63 ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());64 XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));65 }66 }67 }
Copied to your clipboard1// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample2// Run the sample:3// node src/htmltopdf/static-html-to-pdf.js45const {6 ServicePrincipalCredentials,7 PDFServices,8 MimeType,9 PageLayout,10 HTMLToPDFParams,11 HTMLToPDFResult,12 HTMLToPDFJob,13 SDKError,14 ServiceUsageError,15 ServiceApiError16} = require("@adobe/pdfservices-node-sdk");17const fs = require("fs");1819(async () => {20 let readStream;21 try {22 // Initial setup, create credentials instance23 const credentials = new ServicePrincipalCredentials({24 clientId: process.env.PDF_SERVICES_CLIENT_ID,25 clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET26 });2728 // Creates a PDF Services instance29 const pdfServices = new PDFServices({credentials});3031 // Creates an asset(s) from source file(s) and upload32 readStream = fs.createReadStream("./createPDFFromStaticHtmlInput.zip");33 const inputAsset = await pdfServices.upload({34 readStream,35 mimeType: MimeType.ZIP36 });3738 // Create parameters for the job39 const params = getHTMLToPDFParams();4041 // Creates a new job instance42 const job = new HTMLToPDFJob({inputAsset, params});4344 // Submit the job and get the job result45 const pollingURL = await pdfServices.submit({job});46 const pdfServicesResponse = await pdfServices.getJobResult({47 pollingURL,48 resultType: HTMLToPDFResult49 });5051 // Get content from the resulting asset(s)52 const resultAsset = pdfServicesResponse.result.asset;53 const streamAsset = await pdfServices.getContent({asset: resultAsset});5455 // Creates an output stream and copy result asset's content to it56 const outputFilePath = "createPdfFromStaticHtmlOutput.pdf";57 console.log(`Saving asset at ${outputFilePath}`);5859 const outputStream = fs.createWriteStream(outputFilePath);60 streamAsset.readStream.pipe(outputStream);61 } catch (err) {62 if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {63 console.log("Exception encountered while executing operation", err);64 } else {65 console.log("Exception encountered while executing operation", err);66 }67 } finally {68 readStream?.destroy();69 }70})();7172function getHTMLToPDFParams() {73 // Define the page layout, in this case an 8 x 11.5 inch page (effectively portrait orientation)74 const pageLayout = new PageLayout({75 pageHeight: 11.5,76 pageWidth: 877 });7879 return new HTMLToPDFParams({80 pageLayout,81 includeHeaderFooter: true,82 });83}
Copied to your clipboard1// Please refer our REST API docs for more information2// https://developer.adobe.com/document-services/docs/apis/#tag/Html-To-PDF34curl --location --request POST 'https://pdf-services.adobe.io/operation/htmltopdf' \5--header 'x-api-key: {{Placeholder for client_id}}' \6--header 'Content-Type: application/json' \7--header 'Authorization: Bearer {{Placeholder for token}}' \8--data-raw '{9 "assetID": "urn:aaid:AS:UE1:23c30ee0-2e4d-46d6-87f2-087832fca718",10 "json": "{}",11 "includeHeaderFooter": true,12 "pageLayout": {13 "pageWidth": 11,14 "pageHeight": 8.515 }16}'
Create a PDF from static HTML with inline CSS
The sample below creates a PDF file from a static HTML file with inline CSS. The file must be local.
Please refer the API usage guide to understand how to use our APIs.
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples2// Run the sample:3// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.htmltopdf.HTMLWithInlineCSSToPDF45 public class HTMLWithInlineCSSToPDF {67 // Initialize the logger.8 private static final Logger LOGGER = LoggerFactory.getLogger(HTMLWithInlineCSSToPDF.class);910 public static void main(String[] args) {11 try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/createPDFFromHTMLWithInlineCSSInput.html").toPath())) {12 // Initial setup, create credentials instance13 Credentials credentials = new ServicePrincipalCredentials(14 System.getenv("PDF_SERVICES_CLIENT_ID"),15 System.getenv("PDF_SERVICES_CLIENT_SECRET"));1617 // Creates a PDF Services instance18 PDFServices pdfServices = new PDFServices(credentials);1920 // Creates an asset(s) from source file(s) and upload21 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.HTML.getMediaType());2223 // Create parameters for the job24 HTMLToPDFParams htmlToPDFParams = getHTMLToPDFParams();2526 // Creates a new job instance27 HTMLToPDFJob htmLtoPDFJob = new HTMLToPDFJob(asset)28 .setParams(htmlToPDFParams);2930 // Submit the job and gets the job result31 String location = pdfServices.submit(htmLtoPDFJob);32 PDFServicesResponse<HTMLToPDFResult> pdfServicesResponse = pdfServices.getJobResult(location, HTMLToPDFResult.class);3334 // Get content from the resulting asset(s)35 Asset resultAsset = pdfServicesResponse.getResult().getAsset();36 StreamAsset streamAsset = pdfServices.getContent(resultAsset);3738 // Creates an output stream and copy stream asset's content to it39 File.createDirectories(Paths.get("output/"));40 OutputStream outputStream = Files.newOutputStream(new File("output/htmlWithInlineCSSToPDFOutput.pdf").toPath());41 LOGGER.info("Saving asset at output/htmlWithInlineCSSToPDFOutput.pdf");42 IOUtils.copy(streamAsset.getInputStream(), outputStream);43 outputStream.close();44 } catch (ServiceApiException | IOException | SDKException | ServiceUsageException ex) {45 LOGGER.error("Exception encountered while executing operation", ex);46 }47 }4849 private static HTMLToPDFParams getHTMLToPDFParams() {50 // Define the page layout, in this case an 8 x 11.5 inch page (effectively portrait orientation)51 PageLayout pageLayout = new PageLayout();52 pageLayout.setPageSize(20, 25);5354 return new HTMLToPDFParams.Builder()55 .includeHeaderFooter(true).withPageLayout(pageLayout)56 .build();57 }58}
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples2// Run the sample:3// cd CreatePDFFromHTMLWithInlineCSS/4// dotnet run CreatePDFFromHTMLWithInlineCSS.csproj56namespace CreatePDFFromHTMLWithInlineCSS7 {8 class Program9 {10 private static readonly ILog log = LogManager.GetLogger(typeof(Program));11 static void Main()12 {13 //Configure the logging14 ConfigureLogging();15 try16 {17 // Initial setup, create credentials instance.18 Credentials credentials = Credentials.ServicePrincipalCredentialsBuilder()19 .WithClientId("PDF_SERVICES_CLIENT_ID")20 .WithClientSecret("PDF_SERVICES_CLIENT_SECRET")21 .Build();2223 //Create an ExecutionContext using credentials and create a new operation instance.24 ExecutionContext executionContext = ExecutionContext.Create(credentials);25 CreatePDFOperation htmlToPDFOperation = CreatePDFOperation.CreateNew();2627 // Set operation input from a source file.28 FileRef source = FileRef.CreateFromLocalFile(@"createPDFFromHTMLWithInlineCSSInput.html");29 htmlToPDFOperation.SetInput(source);3031 // Provide any custom configuration options for the operation.32 SetCustomOptions(htmlToPDFOperation);3334 // Execute the operation.35 FileRef result = htmlToPDFOperation.Execute(executionContext);3637 // Save the result to the specified location.38 result.SaveAs(Directory.GetCurrentDirectory() + "/output/createPDFFromHTMLWithInlineCSSOutput.pdf");39 }40 catch (ServiceUsageException ex)41 {42 log.Error("Exception encountered while executing operation", ex);43 }44 // Catch more errors here. . .45 }4647 private static void SetCustomOptions(CreatePDFOperation htmlToPDFOperation)48 {49 // Define the page layout, in this case an 20 x 25 inch page (effectively portrait orientation).50 PageLayout pageLayout = new PageLayout();51 pageLayout.SetPageSize(20, 25);5253 // Set the desired HTML-to-PDF conversion options.54 CreatePDFOptions htmlToPdfOptions = CreatePDFOptions.HtmlOptionsBuilder()55 .IncludeHeaderFooter(true)56 .WithPageLayout(pageLayout)57 . Build();58 htmlToPDFOperation.SetOptions(htmlToPdfOptions);59 }6061 static void ConfigureLogging()62 {63 ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());64 XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));65 }66 }67 }
Copied to your clipboard1// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample2// Run the sample:3// node src/htmltopdf/html-with-inline-css-to-pdf.js45const {6 ServicePrincipalCredentials,7 PDFServices,8 MimeType,9 HTMLToPDFJob,10 HTMLToPDFResult,11 PageLayout,12 HTMLToPDFParams,13 SDKError,14 ServiceUsageError,15 ServiceApiError16} = require("@adobe/pdfservices-node-sdk");17const fs = require("fs");1819(async () => {20 let readStream;21 try {22 // Initial setup, create credentials instance23 const credentials = new ServicePrincipalCredentials({24 clientId: process.env.PDF_SERVICES_CLIENT_ID,25 clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET26 });2728 // Creates a PDF Services instance29 const pdfServices = new PDFServices({credentials});3031 // Creates an asset(s) from source file(s) and upload32 readStream = fs.createReadStream("./createPDFFromHTMLWithInlineCSSInput.html");33 const inputAsset = await pdfServices.upload({34 readStream,35 mimeType: MimeType.HTML36 });3738 // Create parameters for the job39 const params = getHTMLToPDFParams();4041 // Creates a new job instance42 const job = new HTMLToPDFJob({inputAsset, params});4344 // Submit the job and get the job result45 const pollingURL = await pdfServices.submit({job});46 const pdfServicesResponse = await pdfServices.getJobResult({47 pollingURL,48 resultType: HTMLToPDFResult49 });5051 // Get content from the resulting asset(s)52 const resultAsset = pdfServicesResponse.result.asset;53 const streamAsset = await pdfServices.getContent({asset: resultAsset});5455 // Creates an output stream and copy result asset's content to it56 const outputFilePath = "./createPDFFromHTMLWithInlineCSSOutput.pdf";57 console.log(`Saving asset at ${outputFilePath}`);5859 const outputStream = fs.createWriteStream(outputFilePath);60 streamAsset.readStream.pipe(outputStream);61 } catch (err) {62 if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {63 console.log("Exception encountered while executing operation", err);64 } else {65 console.log("Exception encountered while executing operation", err);66 }67 } finally {68 readStream?.destroy();69 }70})();7172function getHTMLToPDFParams() {73 // Define the page layout, in this case an 20 x 25 inch page (effectively portrait orientation)74 const pageLayout = new PageLayout({75 pageHeight: 25,76 pageWidth: 2077 });7879 return new HTMLToPDFParams({80 pageLayout,81 includeHeaderFooter: true,82 });83}
Copied to your clipboard1// Please refer our REST API docs for more information2// https://developer.adobe.com/document-services/docs/apis/#tag/Html-To-PDF34curl --location --request POST 'https://pdf-services.adobe.io/operation/htmltopdf' \5--header 'x-api-key: {{Placeholder for client_id}}' \6--header 'Content-Type: application/json' \7--header 'Authorization: Bearer {{Placeholder for token}}' \8--data-raw '{9 "assetID": "urn:aaid:AS:UE1:23c30ee0-2e4d-46d6-87f2-087832fca718",10 "json": "{}",11 "includeHeaderFooter": true,12 "pageLayout": {13 "pageWidth": 11,14 "pageHeight": 8.515 }16}'
Create a PDF File From HTML specified via URL
The sample below creates a PDF file from a HTML file specified via URL.
Please refer the API usage guide to understand how to use our APIs.
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples2// Run the sample:3// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.htmltopdf.HTMLToPDFFromURL45 public class HTMLToPDFFromURL {67 // Initialize the logger.8 private static final Logger LOGGER = LoggerFactory.getLogger(HTMLToPDFFromURL.class);910 public static void main(String[] args) {1112 try {13 // Initial setup, create credentials instance14 Credentials credentials = new ServicePrincipalCredentials(15 System.getenv("PDF_SERVICES_CLIENT_ID"),16 System.getenv("PDF_SERVICES_CLIENT_SECRET"));1718 // Creates a PDF Services instance19 PDFServices pdfServices = new PDFServices(credentials);2021 String htmlURL = "<HTML URL>";2223 // Create parameters for the job24 HTMLToPDFParams htmlToPDFParams = getHTMLToPDFParams();2526 // Creates a new job instance27 HTMLToPDFJob htmLtoPDFJob = new HTMLToPDFJob(htmlURL)28 .setParams(htmlToPDFParams);2930 // Submit the job and gets the job result31 String location = pdfServices.submit(htmLtoPDFJob);32 PDFServicesResponse<HTMLToPDFResult> pdfServicesResponse = pdfServices.getJobResult(location, HTMLToPDFResult.class);3334 // Get content from the resulting asset(s)35 Asset resultAsset = pdfServicesResponse.getResult().getAsset();36 StreamAsset streamAsset = pdfServices.getContent(resultAsset);3738 // Creates an output stream and copy stream asset's content to it39 File.createDirectories(Paths.get("output/"));40 OutputStream outputStream = Files.newOutputStream(new File("output/htmlToPDFFromURLOutput.pdf").toPath());41 LOGGER.info("Saving asset at output/htmlToPDFFromURLOutput.pdf");42 IOUtils.copy(streamAsset.getInputStream(), outputStream);43 } catch (ServiceApiException | IOException | SDKException | ServiceUsageException ex) {44 LOGGER.error("Exception encountered while executing operation", ex);45 }46 }4748 private static HTMLToPDFParams getHTMLToPDFParams() {49 // Define the page layout, in this case an 8 x 11.5 inch page (effectively portrait orientation)50 PageLayout pageLayout = new PageLayout();51 pageLayout.setPageSize(20, 25);5253 return new HTMLToPDFParams.Builder()54 .includeHeaderFooter(true).withPageLayout(pageLayout)55 .build();56 }57}
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples2// Run the sample:3// cd CreatePDFFromURL/4// dotnet run CreatePDFFromURL.csproj56namespace CreatePDFFromURL7{8 class Program9 {10 private static readonly ILog log = LogManager.GetLogger(typeof(Program));11 static void Main()12 {13 //Configure the logging14 ConfigureLogging();15 try16 {17 // Initial setup, create credentials instance.18 Credentials credentials = Credentials.ServicePrincipalCredentialsBuilder()19 .WithClientId("PDF_SERVICES_CLIENT_ID")20 .WithClientSecret("PDF_SERVICES_CLIENT_SECRET")21 .Build();2223 //Create an ExecutionContext using credentials and create a new operation instance.24 ExecutionContext executionContext = ExecutionContext.Create(credentials);25 CreatePDFOperation htmlToPDFOperation = CreatePDFOperation.CreateNew();2627 // Set operation input from a source URL.28 FileRef source = FileRef.CreateFromURI(new Uri("https://www.adobe.io"));29 htmlToPDFOperation.SetInput(source);3031 // Provide any custom configuration options for the operation.32 SetCustomOptions(htmlToPDFOperation);3334 // Execute the operation.35 FileRef result = htmlToPDFOperation.Execute(executionContext);3637 // Save the result to the specified location.38 result.SaveAs(Directory.GetCurrentDirectory() + "/output/createPdfFromURLOutput.pdf");39 }40 catch (ServiceUsageException ex)41 {42 log.Error("Exception encountered while executing operation", ex);43 }44 // Catch more errors here. . .45 }4647 private static void SetCustomOptions(CreatePDFOperation htmlToPDFOperation)48 {49 // Define the page layout, in this case an 20 x 25 inch page (effectively portrait orientation).50 PageLayout pageLayout = new PageLayout();51 pageLayout.SetPageSize(20, 25);5253 // Set the desired HTML-to-PDF conversion options.54 CreatePDFOptions htmlToPdfOptions = CreatePDFOptions.HtmlOptionsBuilder()55 .IncludeHeaderFooter(true)56 .WithPageLayout(pageLayout)57 . Build();58 htmlToPDFOperation.SetOptions(htmlToPdfOptions);59 }6061 static void ConfigureLogging()62 {63 ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());64 XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));65 }66}67}
Copied to your clipboard1// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample2// Run the sample:3// node src/htmltopdf/html-to-pdf-from-url.js45const {6 ServicePrincipalCredentials,7 PDFServices,8 PageLayout,9 HTMLToPDFParams,10 HTMLToPDFResult,11 HTMLToPDFJob,12 SDKError,13 ServiceUsageError,14 ServiceApiError15} = require("@adobe/pdfservices-node-sdk");16const fs = require("fs");1718(async () => {19 try {20 // Initial setup, create credentials instance21 const credentials = new ServicePrincipalCredentials({22 clientId: process.env.PDF_SERVICES_CLIENT_ID,23 clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET24 });2526 // Creates a PDF Services instance27 const pdfServices = new PDFServices({credentials});2829 const inputURL = "<HTML_URL>";3031 // Create parameters for the job32 const params = getHTMLToPDFParams();3334 // Creates a new job instance35 const job = new HTMLToPDFJob({inputURL, params});3637 // Submit the job and get the job result38 const pollingURL = await pdfServices.submit({job});39 const pdfServicesResponse = await pdfServices.getJobResult({40 pollingURL,41 resultType: HTMLToPDFResult42 });4344 // Get content from the resulting asset(s)45 const resultAsset = pdfServicesResponse.result.asset;46 const streamAsset = await pdfServices.getContent({asset: resultAsset});4748 // Creates an output stream and copy result asset's content to it49 const outputFilePath = "./createPDFFromHTMLURL.pdf";50 console.log(`Saving asset at ${outputFilePath}`);5152 const outputStream = fs.createWriteStream(outputFilePath);53 streamAsset.readStream.pipe(outputStream);54 } catch (err) {55 if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {56 console.log("Exception encountered while executing operation", err);57 } else {58 console.log("Exception encountered while executing operation", err);59 }60 }61})();6263function getHTMLToPDFParams() {64 // Define the page layout, in this case an 8 x 11.5 inch page (effectively portrait orientation)65 const pageLayout = new PageLayout({66 pageHeight: 11.5,67 pageWidth: 868 });6970 return new HTMLToPDFParams({71 includeHeaderFooter: true,72 pageLayout73 });74}
Copied to your clipboard1// Please refer our REST API docs for more information2// https://developer.adobe.com/document-services/docs/apis/#tag/Html-To-PDF34curl --location --request POST 'https://pdf-services.adobe.io/operation/htmltopdf' \5--header 'x-api-key: {{Placeholder for client_id}}' \6--header 'Content-Type: application/json' \7--header 'Authorization: Bearer {{Placeholder for token}}' \8--data-raw '{9 "inputUrl": "https://developer.adobe.com/document-services/homepage",10 "json": "{}",11 "includeHeaderFooter": true,12 "pageLayout": {13 "pageWidth": 11,14 "pageHeight": 8.515 }16}'
Create a PDF from dynamic HTML
To support workflows with dynamic data, DynamicHTMLToPDF
creates PDFs from dynamic HTML. It's a common scenario for enterprise to
provide end users with an HTML template with form fields. This API
allows you to capture the users unique data entries and then save it as
PDF. Collected data is stored in a JSON file, and the source HTML file
must include <script src='./json.js' type='text/javascript'></script>
.
Refer to the API docs for usage.
The sample 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 prior to PDF conversion.
Please refer the API usage guide to understand how to use our APIs.
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples2// Run the sample:3// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.htmltopdf.DynamicHTMLToPDF4 public class DynamicHTMLToPDF {56 // Initialize the logger.7 private static final Logger LOGGER = LoggerFactory.getLogger(DynamicHTMLToPDF.class);89 public static void main(String[] args) {1011 try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/createPDFFromDynamicHtmlInput.zip").toPath())) {12 // Initial setup, create credentials instance13 Credentials credentials = new ServicePrincipalCredentials(14 System.getenv("PDF_SERVICES_CLIENT_ID"),15 System.getenv("PDF_SERVICES_CLIENT_SECRET"));1617 // Creates a PDF Services instance18 PDFServices pdfServices = new PDFServices(credentials);1920 // Creates an asset(s) from source file(s) and upload21 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.ZIP.getMediaType());2223 // Create parameters for the job24 HTMLToPDFParams htmlToPDFParams = getHTMLToPDFParams();2526 // Creates a new job instance27 HTMLToPDFJob htmLtoPDFJob = new HTMLToPDFJob(asset)28 .setParams(htmlToPDFParams);2930 // Submit the job and gets the job result31 String location = pdfServices.submit(htmLtoPDFJob);32 PDFServicesResponse<HTMLToPDFResult> pdfServicesResponse = pdfServices.getJobResult(location, HTMLToPDFResult.class);3334 // Get content from the resulting asset(s)35 Asset resultAsset = pdfServicesResponse.getResult().getAsset();36 StreamAsset streamAsset = pdfServices.getContent(resultAsset);3738 // Creates an output stream and copy stream asset's content to it39 File.createDirectories(Paths.get("output/"));40 OutputStream outputStream = Files.newOutputStream(new File("output/dynamicHTMLToPDFOutput.pdf").toPath());41 LOGGER.info("Saving asset at output/dynamicHTMLToPDFOutput.pdf");42 IOUtils.copy(streamAsset.getInputStream(), outputStream);43 outputStream.close();44 } catch (ServiceApiException | IOException | SDKException | ServiceUsageException ex) {45 LOGGER.error("Exception encountered while executing operation", ex);46 }47 }4849 private static HTMLToPDFParams getHTMLToPDFParams() {50 // Define the page layout, in this case an 8 x 11.5 inch page (effectively portrait orientation)51 PageLayout pageLayout = new PageLayout();52 pageLayout.setPageSize(8, 11.5);5354 // Sets the dataToMerge field that needs to be populated in the HTML before its conversion55 JSONObject dataToMerge = new JSONObject();56 dataToMerge.put("title","Create, Convert PDFs and More!");57 dataToMerge.put("sub_title","Easily integrate PDF actions within your document workflows.");5859 return new HTMLToPDFParams.Builder()60 .includeHeaderFooter(true).withPageLayout(pageLayout).withDataToMerge(dataToMerge)61 .build();62 }63}
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples2// Run the sample:3// cd CreatePDFFromDynamicHtml/4// dotnet run CreatePDFFromDynamicHtml.csproj56 namespace CreatePDFFromDynamicHtml7 {8 class Program9 {10 private static readonly ILog log = LogManager.GetLogger(typeof(Program));11 static void Main()12 {13 //Configure the logging14 ConfigureLogging();15 try16 {17 // Initial setup, create credentials instance.18 Credentials credentials = Credentials.ServicePrincipalCredentialsBuilder()19 .WithClientId("PDF_SERVICES_CLIENT_ID")20 .WithClientSecret("PDF_SERVICES_CLIENT_SECRET")21 .Build();2223 //Create an ExecutionContext using credentials and create a new operation instance.24 ExecutionContext executionContext = ExecutionContext.Create(credentials);25 CreatePDFOperation htmlToPDFOperation = CreatePDFOperation.CreateNew();2627 // Set operation input from a source file.28 FileRef source = FileRef.CreateFromLocalFile(@"createPDFFromDynamicHtmlInput.zip");29 htmlToPDFOperation.SetInput(source);3031 // Provide any custom configuration options for the operation.32 SetCustomOptions(htmlToPDFOperation);3334 // Execute the operation.35 FileRef result = htmlToPDFOperation.Execute(executionContext);3637 // Save the result to the specified location.38 result.SaveAs(Directory.GetCurrentDirectory() + "/output/createPdfFromDynamicHtmlOutput.pdf");39 }40 catch (ServiceUsageException ex)41 {42 log.Error("Exception encountered while executing operation", ex);43 }44 // errors continued. . .45 }4647 private static void SetCustomOptions(CreatePDFOperation htmlToPDFOperation)48 {49 // Define the page layout, in this case an 8 x 11.5 inch page (effectively portrait orientation).50 PageLayout pageLayout = new PageLayout();51 pageLayout.SetPageSize(8, 11.5);5253 //Set the dataToMerge field that needs to be populated in the HTML before its conversion54 JObject dataToMerge = new JObject55 {56 { "title", "Create, Convert PDFs and More!" },57 { "sub_title", "Easily integrate PDF actions within your document workflows." }58 };5960 // Set the desired HTML-to-PDF conversion options.61 CreatePDFOptions htmlToPdfOptions = CreatePDFOptions.HtmlOptionsBuilder()62 .IncludeHeaderFooter(true)63 .WithPageLayout(pageLayout)64 .WithDataToMerge(dataToMerge)65 .Build();66 htmlToPDFOperation.SetOptions(htmlToPdfOptions);67 }6869 static void ConfigureLogging()70 {71 ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());72 XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));73 }74 }75 }
Copied to your clipboard1// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample2// Run the sample:3// node src/htmltopdf/dynamic-html-to-pdf.js45const {6 ServicePrincipalCredentials,7 PDFServices,8 MimeType,9 PageLayout,10 HTMLToPDFParams,11 HTMLToPDFResult,12 HTMLToPDFJob,13 SDKError,14 ServiceUsageError,15 ServiceApiError16} = require("@adobe/pdfservices-node-sdk");17const fs = require("fs");1819(async () => {20 let readStream;21 try {22 // Initial setup, create credentials instance23 const credentials = new ServicePrincipalCredentials({24 clientId: process.env.PDF_SERVICES_CLIENT_ID,25 clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET26 });2728 // Creates a PDF Services instance29 const pdfServices = new PDFServices({credentials});3031 // Creates an asset(s) from source file(s) and upload32 readStream = fs.createReadStream("./createPDFFromDynamicHtmlInput.zip");33 const inputAsset = await pdfServices.upload({34 readStream,35 mimeType: MimeType.ZIP36 });3738 // Create parameters for the job39 const params = getHTMLToPDFParams();4041 // Creates a new job instance42 const job = new HTMLToPDFJob({inputAsset, params});4344 // Submit the job and get the job result45 const pollingURL = await pdfServices.submit({job});46 const pdfServicesResponse = await pdfServices.getJobResult({47 pollingURL,48 resultType: HTMLToPDFResult49 });5051 // Get content from the resulting asset(s)52 const resultAsset = pdfServicesResponse.result.asset;53 const streamAsset = await pdfServices.getContent({asset: resultAsset});5455 // Creates an output stream and copy result asset's content to it56 const outputFilePath = "./createPDFFromDynamicHtmlOutput.pdf";57 console.log(`Saving asset at ${outputFilePath}`);5859 const outputStream = fs.createWriteStream(outputFilePath);60 streamAsset.readStream.pipe(outputStream);61 } catch (err) {62 if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {63 console.log("Exception encountered while executing operation", err);64 } else {65 console.log("Exception encountered while executing operation", err);66 }67 } finally {68 readStream?.destroy();69 }70})();7172function getHTMLToPDFParams() {73 // Define the page layout, in this case an 8 x 11.5 inch page (effectively portrait orientation)74 const pageLayout = new PageLayout({75 pageHeight: 11.5,76 pageWidth: 877 });7879 // Set the dataToMerge field that needs to be populated in the HTML before its conversion80 const dataToMerge = {81 "title": "Create, Convert PDFs and More!",82 "sub_title": "Easily integrate PDF actions within your document workflows."83 };8485 return new HTMLToPDFParams({86 pageLayout,87 dataToMerge,88 includeHeaderFooter: true,89 });90}
Copied to your clipboard1// Please refer our REST API docs for more information2// https://developer.adobe.com/document-services/docs/apis/#tag/Html-To-PDF34curl --location --request POST 'https://pdf-services.adobe.io/operation/htmltopdf' \5--header 'x-api-key: {{Placeholder for client_id}}' \6--header 'Content-Type: application/json' \7--header 'Authorization: Bearer {{Placeholder for token}}' \8--data-raw '{9 "assetID": "urn:aaid:AS:UE1:23c30ee0-2e4d-46d6-87f2-087832fca718",10 "json": "{}",11 "includeHeaderFooter": true,12 "pageLayout": {13 "pageWidth": 11,14 "pageHeight": 8.515 }16}'