From 513f27ee007fba3c487a49ee2a35e74aaa3f217e Mon Sep 17 00:00:00 2001 From: Vignesh Date: Thu, 21 Mar 2024 11:27:59 +0530 Subject: [PATCH 1/5] --Updated node samples --- .../accessibility-auto-tag-api.md | 127 ++++++--- src/pages/apis/pdf-services/combine-pdf.md | 115 +++++--- src/pages/apis/pdf-services/compress-pdf.md | 110 +++++--- src/pages/apis/pdf-services/convert-pdf.md | 119 +++++--- src/pages/apis/pdf-services/create-pdf.md | 108 ++++++-- .../apis/pdf-services/delete-pdf-pages.md | 130 ++++++--- .../apis/pdf-services/document-generation.md | 133 ++++++--- src/pages/apis/pdf-services/e-seal.md | 258 ++++++++++++------ .../apis/pdf-services/extract-pdf-content.md | 128 ++++++--- .../apis/pdf-services/get-pdf-properties.md | 106 ++++--- src/pages/apis/pdf-services/html-to-pdf.md | 132 ++++++--- .../apis/pdf-services/insert-pdf-pages.md | 174 ++++++++---- src/pages/apis/pdf-services/linearize-pdf.md | 110 +++++--- src/pages/apis/pdf-services/ocr-pdf.md | 112 +++++--- .../apis/pdf-services/remove-pdf-password.md | 124 ++++++--- .../apis/pdf-services/reorder-pdf-pages.md | 134 ++++++--- .../apis/pdf-services/replace-pdf-pages.md | 171 ++++++++---- .../apis/pdf-services/rotate-pdf-pages.md | 153 +++++++---- src/pages/apis/pdf-services/secure-pdf.md | 119 +++++--- src/pages/apis/pdf-services/split-pdf.md | 130 ++++++--- src/pages/home/accessbility-auto-tag.md | 105 ++++--- src/pages/home/create-pdf-from-url.md | 139 ++++++++-- .../home/dynamic-pdf-document-generation.md | 153 ++++++++--- src/pages/home/e-seal.md | 241 ++++++++++------ src/pages/home/pdf-content-structure.md | 126 ++++++--- 25 files changed, 2403 insertions(+), 1054 deletions(-) diff --git a/src/pages/apis/pdf-services/accessibility-auto-tag-api.md b/src/pages/apis/pdf-services/accessibility-auto-tag-api.md index d6ba828f9..05b1db768 100644 --- a/src/pages/apis/pdf-services/accessibility-auto-tag-api.md +++ b/src/pages/apis/pdf-services/accessibility-auto-tag-api.md @@ -36,41 +36,102 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/autotag' // Run the sample: // node src/autotagpdf/autotag-pdf.js -const PDFServicesSdk = require('@adobe/pdfservices-node-sdk'); - -try { - // Initial setup, create credentials instance. - const credentials = PDFServicesSdk.Credentials - .servicePrincipalCredentialsBuilder() - .withClientId("PDF_SERVICES_CLIENT_ID") - .withClientSecret("PDF_SERVICES_CLIENT_SECRET") - .build(); - - // Create an ExecutionContext using credentials and create a new operation instance. - const executionContext = PDFServicesSdk.ExecutionContext.create(credentials), - autotagPDF = PDFServicesSdk.AutotagPDF, - autotagPDFOperation = autotagPDF.Operation.createNew(); - - // Set operation input from a source file. - const input = PDFServicesSdk.FileRef.createFromLocalFile('autotagPDFInput.pdf'); - autotagPDFOperation.setInput(input); - - // Execute the operation and Save the result to the specified location. - autotagPDFOperation.execute(executionContext) - .then(result => { - result.taggedPDF.saveAsFile('autotagPDFOutput.pdf'); - }) - .catch(err => { - if(err instanceof PDFServicesSdk.Error.ServiceApiError - || err instanceof PDFServicesSdk.Error.ServiceUsageError) { - console.log('Exception encountered while executing operation', err); - } else { - console.log('Exception encountered while executing operation', err); - } +const { + ServicePrincipalCredentials, + PDFServices, + MimeType, + AutotagPDFParams, + AutotagPDFJob, + AutotagPDFResult, + SDKError, + ServiceUsageError, + ServiceApiError +} = require("@dcloud/pdfservices-node-sdk"); +const fs = require("fs"); + +(async () => { + let readStream; + try { + // Initial setup, create credentials instance + const credentials = new ServicePrincipalCredentials({ + clientId: process.env.PDF_SERVICES_CLIENT_ID, + clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET + }); + + // Creates a PDF Services instance + const pdfServices = new PDFServices({ + credentials + }); + + // Creates an asset(s) from source file(s) and upload + readStream = fs.createReadStream("resources/autotagPDFInput.pdf"); + const inputAsset = await pdfServices.upload({ + readStream, + mimeType: MimeType.PDF + }); + + // Create parameters for the job + const params = new AutotagPDFParams({ + generateReport: true, + shiftHeadings: true + }); + + // Creates a new job instance + const job = new AutotagPDFJob({ + inputAsset, + params }); -} catch (err) { - console.log('Exception encountered while executing operation', err); + // Submit the job and get the job result + const pollingURL = await pdfServices.submit({ + job + }); + const pdfServicesResponse = await pdfServices.getJobResult({ + pollingURL, + resultType: AutotagPDFResult + }); + + // Get content from the resulting asset(s) + const resultAsset = pdfServicesResponse.result.taggedPDF; + const resultAssetReport = pdfServicesResponse.result.report; + const streamAsset = await pdfServices.getContent({ + asset: resultAsset + }); + const streamAssetReport = await pdfServices.getContent({ + asset: resultAssetReport + }); + + // Creates an output stream and copy stream asset's content to it + const outputFilePath = createOutputFilePath(".pdf"); + const outputFilePathReport = createOutputFilePath(".xlsx"); + console.log(`Saving asset at ${outputFilePath}`); + console.log(`Saving asset at ${outputFilePathReport}`); + + let writeStream = fs.createWriteStream(outputFilePath); + streamAsset.readStream.pipe(writeStream); + writeStream = fs.createWriteStream(outputFilePathReport); + streamAssetReport.readStream.pipe(writeStream); + } catch (err) { + if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { + console.log("Exception encountered while executing operation", err); + } else { + console.log("Exception encountered while executing operation", err); + } + } finally { + readStream?.destroy(); + } +})(); +// Generates a string containing a directory structure and file name for the output file +function createOutputFilePath(extension) { + const filePath = "output/AutotagPDFWithOptions/"; + const date = new Date(); + const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + + ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); + fs.mkdirSync(filePath, { + recursive: true + }); + return (`${filePath}autotag${dateString}${extension}`); } ``` diff --git a/src/pages/apis/pdf-services/combine-pdf.md b/src/pages/apis/pdf-services/combine-pdf.md index 4adc02fc5..306973c55 100644 --- a/src/pages/apis/pdf-services/combine-pdf.md +++ b/src/pages/apis/pdf-services/combine-pdf.md @@ -46,39 +46,90 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/combinep // Run the sample: // node src/combinepdf/combine-pdf.js -const PDFServicesSdk = require('@adobe/pdfservices-node-sdk'); - -try { - // Initial setup, create credentials instance. - const credentials = PDFServicesSdk.Credentials - .servicePrincipalCredentialsBuilder() - .withClientId("PDF_SERVICES_CLIENT_ID") - .withClientSecret("PDF_SERVICES_CLIENT_SECRET") - .build(); - - // Create an ExecutionContext using credentials and create a new operation instance. - const executionContext = PDFServicesSdk.ExecutionContext.create(credentials), - combineFilesOperation = PDFServicesSdk.CombineFiles.Operation.createNew(); - - // Set operation input from a source file. - const combineSource1 = PDFServicesSdk.FileRef.createFromLocalFile('resources/combineFilesInput1.pdf'), - combineSource2 = PDFServicesSdk.FileRef.createFromLocalFile('resources/combineFilesInput2.pdf'); - combineFilesOperation.addInput(combineSource1); - combineFilesOperation.addInput(combineSource2); - - // Execute the operation and Save the result to the specified location. - combineFilesOperation.execute(executionContext) - .then(result => result.saveAsFile('output/combineFilesOutput.pdf')) - .catch(err => { - if (err instanceof PDFServicesSdk.Error.ServiceApiError - || err instanceof PDFServicesSdk.Error.ServiceUsageError) { - console.log('Exception encountered while executing operation', err); - } else { - console.log('Exception encountered while executing operation', err); - } +const { + ServicePrincipalCredentials, + PDFServices, + MimeType, + CombinePDFJob, + CombinePDFParams, + CombinePDFResult, + SDKError, + ServiceUsageError, + ServiceApiError +} = require("@dcloud/pdfservices-node-sdk"); +const fs = require("fs"); + +(async () => { + let readStream1; + let readStream2; + try { + // Initial setup, create credentials instance + const credentials = new ServicePrincipalCredentials({ + clientId: process.env.PDF_SERVICES_CLIENT_ID, + clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET + }); + + // Creates an asset(s) from source file(s) and upload + readStream1 = fs.createReadStream("resources/combineFilesInput1.pdf"); + readStream2 = fs.createReadStream("resources/combineFilesInput2.pdf"); + const [inputAsset1, inputAsset2] = await pdfServices.uploadAssets({ + streamAssets: [{ + readStream: readStream1, + mimeType: MimeType.PDF + }, { + readStream: readStream2, + mimeType: MimeType.PDF + }] + }); + + // Create parameters for the job + const params = new CombinePDFParams() + .addAsset(inputAsset1) + .addAsset(inputAsset2); + // Submit the job and get the job result + const pollingURL = await pdfServices.submit({ + job }); -} catch (err) { - console.log('Exception encountered while executing operation', err); + const pdfServicesResponse = await pdfServices.getJobResult({ + pollingURL, + resultType: CombinePDFResult + }); + + // Get content from the resulting asset(s) + const resultAsset = pdfServicesResponse.result.asset; + const streamAsset = await pdfServices.getContent({ + asset: resultAsset + }); + + // Creates an output stream and copy result asset's content to it + const outputFilePath = createOutputFilePath(); + console.log(`Saving asset at ${outputFilePath}`); + + const outputStream = fs.createWriteStream(outputFilePath); + streamAsset.readStream.pipe(outputStream); + } catch (err) { + if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { + console.log("Exception encountered while executing operation", err); + } else { + console.log("Exception encountered while executing operation", err); + } + } finally { + readStream1?.destroy(); + readStream2?.destroy(); + } +})(); + +// Generates a string containing a directory structure and file name for the output file +function createOutputFilePath() { + const filePath = "output/CombinePDF/"; + const date = new Date(); + const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + + ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); + fs.mkdirSync(filePath, { + recursive: true + }); + return (`${filePath}combine${dateString}.pdf`); } ``` diff --git a/src/pages/apis/pdf-services/compress-pdf.md b/src/pages/apis/pdf-services/compress-pdf.md index badb191df..c9053cc4c 100644 --- a/src/pages/apis/pdf-services/compress-pdf.md +++ b/src/pages/apis/pdf-services/compress-pdf.md @@ -41,38 +41,86 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/compress // Run the sample: // node src/compresspdf/compress-pdf.js -const PDFServicesSdk = require('@adobe/pdfservices-node-sdk'); - -try { - // Initial setup, create credentials instance. - const credentials = PDFServicesSdk.Credentials - .servicePrincipalCredentialsBuilder() - .withClientId("PDF_SERVICES_CLIENT_ID") - .withClientSecret("PDF_SERVICES_CLIENT_SECRET") - .build(); - - // Create an ExecutionContext using credentials and create a new operation instance. - const executionContext = PDFServicesSdk.ExecutionContext.create(credentials), - compressPDF = PDFServicesSdk.CompressPDF, - compressPDFOperation = compressPDF.Operation.createNew(); - - // Set operation input from a source file. - const input = PDFServicesSdk.FileRef.createFromLocalFile('resources/compressPDFInput.pdf'); - compressPDFOperation.setInput(input); - - // Execute the operation and Save the result to the specified location. - compressPDFOperation.execute(executionContext) - .then(result => result.saveAsFile('output/compressPDFOutput.pdf')) - .catch(err => { - if(err instanceof PDFServicesSdk.Error.ServiceApiError - || err instanceof PDFServicesSdk.Error.ServiceUsageError) { - console.log('Exception encountered while executing operation', err); - } else { - console.log('Exception encountered while executing operation', err); - } +const { + ServicePrincipalCredentials, + PDFServices, + MimeType, + CompressPDFJob, + CompressPDFResult, + SDKError, + ServiceUsageError, + ServiceApiError +} = require("@dcloud/pdfservices-node-sdk"); +const fs = require("fs"); + +(async () => { + let readStream; + try { + // Initial setup, create credentials instance + const credentials = new ServicePrincipalCredentials({ + clientId: process.env.PDF_SERVICES_CLIENT_ID, + clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET + }); + // Creates a PDF Services instance + const pdfServices = new PDFServices({ + credentials + }); + + // Creates an asset(s) from source file(s) and upload + readStream = fs.createReadStream("resources/compressPDFInput.pdf"); + const inputAsset = await pdfServices.upload({ + readStream, + mimeType: MimeType.PDF + }); + + // Creates a new job instance + const job = new CompressPDFJob({ + inputAsset + }); + + // Submit the job and get the job result + const pollingURL = await pdfServices.submit({ + job + }); + const pdfServicesResponse = await pdfServices.getJobResult({ + pollingURL, + resultType: CompressPDFResult + }); + + // Get content from the resulting asset(s) + const resultAsset = pdfServicesResponse.result.asset; + const streamAsset = await pdfServices.getContent({ + asset: resultAsset }); -} catch (err) { - console.log('Exception encountered while executing operation', err); + + // Creates an output stream and copy stream asset's content to it + const outputFilePath = createOutputFilePath(); + console.log(`Saving asset at ${outputFilePath}`); + + const outputStream = fs.createWriteStream(outputFilePath); + streamAsset.readStream.pipe(outputStream); + } catch (err) { + if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { + console.log("Exception encountered while executing operation", err); + } else { + console.log("Exception encountered while executing operation", err); + } + } finally { + readStream?.destroy(); + } +})(); + +// Generates a string containing a directory structure and file name for the output file +function createOutputFilePath() { + const filePath = "output/CompressPDF/"; + const date = new Date(); + const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + + ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); + fs.mkdirSync(filePath, { + recursive: true + }); + return (`${filePath}compress${dateString}.pdf`); } ``` diff --git a/src/pages/apis/pdf-services/convert-pdf.md b/src/pages/apis/pdf-services/convert-pdf.md index 4b7a5becc..6899531c0 100644 --- a/src/pages/apis/pdf-services/convert-pdf.md +++ b/src/pages/apis/pdf-services/convert-pdf.md @@ -42,38 +42,95 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/exportpd // Run the sample: // node src/exportpdf/export-pdf-to-docx.js -const PDFServicesSdk = require('@adobe/pdfservices-node-sdk'); - -try { - // Initial setup, create credentials instance. - const credentials = PDFServicesSdk.Credentials - .servicePrincipalCredentialsBuilder() - .withClientId("PDF_SERVICES_CLIENT_ID") - .withClientSecret("PDF_SERVICES_CLIENT_SECRET") - .build(); - - //Create an ExecutionContext using credentials and create a new operation instance. - const executionContext = PDFServicesSdk.ExecutionContext.create(credentials), - exportPDF = PDFServicesSdk.ExportPDF, - exportPdfOperation = exportPDF.Operation.createNew(exportPDF.SupportedTargetFormats.DOCX); - - // Set operation input from a source file - const input = PDFServicesSdk.FileRef.createFromLocalFile('resources/exportPDFInput.pdf'); - exportPdfOperation.setInput(input); - - // Execute the operation and Save the result to the specified location. - exportPdfOperation.execute(executionContext) - .then(result => result.saveAsFile('output/exportPdfOutput.docx')) - .catch(err => { - if(err instanceof PDFServicesSdk.Error.ServiceApiError - || err instanceof PDFServicesSdk.Error.ServiceUsageError) { - console.log('Exception encountered while executing operation', err); - } else { - console.log('Exception encountered while executing operation', err); - } +const { + ServicePrincipalCredentials, + PDFServices, + MimeType, + ExportPDFJob, + ExportPDFParams, + ExportPDFTargetFormat, + ExportPDFResult, + SDKError, + ServiceUsageError, + ServiceApiError +} = require("@dcloud/pdfservices-node-sdk"); +const fs = require("fs"); + +(async () => { + let readStream; + try { + // Initial setup, create credentials instance + const credentials = new ServicePrincipalCredentials({ + clientId: process.env.PDF_SERVICES_CLIENT_ID, + clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET + }); + + // Creates a PDF Services instance + const pdfServices = new PDFServices({ + credentials + }); + + // Creates an asset(s) from source file(s) and upload + readStream = fs.createReadStream("resources/exportPDFInput.pdf"); + const inputAsset = await pdfServices.upload({ + readStream, + mimeType: MimeType.PDF + }) + + // Create parameters for the job + const params = new ExportPDFParams({ + targetFormat: ExportPDFTargetFormat.DOCX + }); + + // Creates a new job instance + const job = new ExportPDFJob({ + inputAsset, + params }); -} catch (err) { - console.log('Exception encountered while executing operation', err); + + // Submit the job and get the job result + const pollingURL = await pdfServices.submit({ + job + }); + const pdfServicesResponse = await pdfServices.getJobResult({ + pollingURL, + resultType: ExportPDFResult + }); + + // Get content from the resulting asset(s) + const resultAsset = pdfServicesResponse.result.asset; + const streamAsset = await pdfServices.getContent({ + asset: resultAsset + }); + + // Creates an output stream and copy stream asset's content to it + const outputFilePath = createOutputFilePath(); + console.log(`Saving asset at ${outputFilePath}`); + + const outputStream = fs.createWriteStream(outputFilePath); + streamAsset.readStream.pipe(outputStream); + } catch (err) { + if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { + console.log("Exception encountered while executing operation", err); + } else { + console.log("Exception encountered while executing operation", err); + } + } finally { + readStream?.destroy(); + } +})(); + +// Generates a string containing a directory structure and file name for the output file +function createOutputFilePath() { + const filePath = "output/ExportPDFToDOCX/"; + const date = new Date(); + const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + + ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); + fs.mkdirSync(filePath, { + recursive: true + }); + return (`${filePath}export${dateString}.docx`); } ``` diff --git a/src/pages/apis/pdf-services/create-pdf.md b/src/pages/apis/pdf-services/create-pdf.md index 7ed3503a0..305f5bcce 100644 --- a/src/pages/apis/pdf-services/create-pdf.md +++ b/src/pages/apis/pdf-services/create-pdf.md @@ -40,37 +40,85 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/createpd // Run the sample: // node src/createpdf/create-pdf-from-docx.js -const PDFservicesSdk = require('@adobe/pdfservices-node-sdk'); - -try { - // Initial setup, create credentials instance. - const credentials = PDFServicesSdk.Credentials - .servicePrincipalCredentialsBuilder() - .withClientId("PDF_SERVICES_CLIENT_ID") - .withClientSecret("PDF_SERVICES_CLIENT_SECRET") - .build(); - - // Create an ExecutionContext using credentials and create a new operation instance. - const executionContext = PDFServicesSdk.ExecutionContext.create(credentials), - createPdfOperation = PDFServicesSdk.CreatePDF.Operation.createNew(); - - // Set operation input from a source file. - const input = PDFServicesSdk.FileRef.createFromLocalFile('resources/createPDFInput.docx'); - createPdfOperation.setInput(input); - - // Execute the operation and Save the result to the specified location. - createPdfOperation.execute(executionContext) - .then(result => result.saveAsFile('output/createPDFFromDOCX.pdf')) - .catch(err => { - if(err instanceof PDFServicesSdk.Error.ServiceApiError - || err instanceof PDFServicesSdk.Error.ServiceUsageError) { - console.log('Exception encountered while executing operation', err); - } else { - console.log('Exception encountered while executing operation', err); - } +const { + ServicePrincipalCredentials, + PDFServices, + MimeType, + CreatePDFJob, + CreatePDFResult, + SDKError, + ServiceUsageError, + ServiceApiError +} = require("@dcloud/pdfservices-node-sdk"); +const fs = require("fs"); + +(async () => { + let readStream; + try { + // Initial setup, create credentials instance + const credentials = new ServicePrincipalCredentials({ + clientId: process.env.PDF_SERVICES_CLIENT_ID, + clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET + }); + // Creates a PDF Services instance + const pdfServices = new PDFServices({ + credentials + }); + + // Creates an asset(s) from source file(s) and upload + readStream = fs.createReadStream("resources/createPDFInput.docx"); + const inputAsset = await pdfServices.upload({ + readStream, + mimeType: MimeType.DOCX + }); + + // Creates a new job instance + const job = new CreatePDFJob({ + inputAsset + }); + + // Submit the job and get the job result + const pollingURL = await pdfServices.submit({ + job + }); + const pdfServicesResponse = await pdfServices.getJobResult({ + pollingURL, + resultType: CreatePDFResult + }); + + // Get content from the resulting asset(s) + const resultAsset = pdfServicesResponse.result.asset; + const streamAsset = await pdfServices.getContent({ + asset: resultAsset + }); + + // Creates an output stream and copy result asset's content to it + const outputFilePath = createOutputFilePath(); + console.log(`Saving asset at ${outputFilePath}`); + + const outputStream = fs.createWriteStream(outputFilePath); + streamAsset.readStream.pipe(outputStream); + } catch (err) { + if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { + console.log("Exception encountered while executing operation", err); + } else { + console.log("Exception encountered while executing operation", err); + } + } finally { + readStream?.destroy(); + } +})(); +// Generates a string containing a directory structure and file name for the output file +function createOutputFilePath() { + const filePath = "output/CreatePDFFromDOCX/"; + const date = new Date(); + const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + + ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); + fs.mkdirSync(filePath, { + recursive: true }); -} catch (err) { - console.log('Exception encountered while executing operation', err); + return (`${filePath}create${dateString}.pdf`); } ``` diff --git a/src/pages/apis/pdf-services/delete-pdf-pages.md b/src/pages/apis/pdf-services/delete-pdf-pages.md index ef9cad11b..392ad6c97 100644 --- a/src/pages/apis/pdf-services/delete-pdf-pages.md +++ b/src/pages/apis/pdf-services/delete-pdf-pages.md @@ -51,52 +51,108 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/pagemani // Run the sample: // node src/replacepages/replace-pdf-pages.js -const PDFServicesSdk = require('@adobe/pdfservices-node-sdk'); +const { + ServicePrincipalCredentials, + PDFServices, + MimeType, + DeletePagesParams, + PageRanges, + DeletePagesJob, + DeletePagesResult, + SDKError, + ServiceUsageError, + ServiceApiError +} = require("@dcloud/pdfservices-node-sdk"); +const fs = require("fs"); + +(async () => { + let readStream; + try { + // Initial setup, create credentials instance + const credentials = new ServicePrincipalCredentials({ + clientId: process.env.PDF_SERVICES_CLIENT_ID, + clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET + }); + + // Creates a PDF Services instance + const pdfServices = new PDFServices({ + credentials + }); + + // Creates an asset(s) from source file(s) and upload + readStream = fs.createReadStream("resources/deletePagesInput.pdf"); + const inputAsset = await pdfServices.upload({ + readStream, + mimeType: MimeType.PDF + }); + + // Delete pages of the document (as specified by PageRanges). + const pageRangeForDeletion = getPageRangesForDeletion(); + + // Create parameters for the job + const params = new DeletePagesParams({ + pageRanges: pageRangeForDeletion + }); + + // Creates a new job instance + const job = new DeletePagesJob({ + inputAsset, + params + }); + + // Submit the job and get the job result + const pollingURL = await pdfServices.submit({ + job + }); + const pdfServicesResponse = await pdfServices.getJobResult({ + pollingURL, + resultType: DeletePagesResult + }); + + // Get content from the resulting asset(s) + const resultAsset = pdfServicesResponse.result.asset; + const streamAsset = await pdfServices.getContent({ + asset: resultAsset + }); + + // Creates a write stream and copy stream asset's content to it + const outputFilePath = createOutputFilePath(); + console.log(`Saving asset at ${outputFilePath}`); + + const writeStream = fs.createWriteStream(outputFilePath); + streamAsset.readStream.pipe(writeStream); + } catch (err) { + if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { + console.log("Exception encountered while executing operation", err); + } else { + console.log("Exception encountered while executing operation", err); + } + } finally { + readStream?.destroy(); + } +})(); const getPageRangesForDeletion = () => { // Specify pages for deletion. - const pageRangesForDeletion = new PDFServicesSdk.PageRanges(); + const pageRangesForDeletion = new PageRanges(); // Add page 1. pageRangesForDeletion.addSinglePage(1); - // Add pages 3 to 4. - pageRangesForDeletion.addPageRange(3, 4); + pageRangesForDeletion.addRange(3, 4); return pageRangesForDeletion; }; -try { - // Initial setup, create credentials instance. - const credentials = PDFServicesSdk.Credentials - .servicePrincipalCredentialsBuilder() - .withClientId("PDF_SERVICES_CLIENT_ID") - .withClientSecret("PDF_SERVICES_CLIENT_SECRET") - .build(); - - // Create an ExecutionContext using credentials and create a new operation instance. - const executionContext = PDFServicesSdk.ExecutionContext.create(credentials), - deletePagesOperation = PDFServicesSdk.DeletePages.Operation.createNew(); - - // Set operation input from a source file. - const input = PDFServicesSdk.FileRef.createFromLocalFile('resources/deletePagesInput.pdf'); - deletePagesOperation.setInput(input); - - // Delete pages of the document (as specified by PageRanges). - const pageRangesForDeletion = getPageRangesForDeletion(); - deletePagesOperation.setPageRanges(pageRangesForDeletion); - - // Execute the operation and Save the result to the specified location. - deletePagesOperation.execute(executionContext) - .then(result => result.saveAsFile('output/deletePagesOutput.pdf')) - .catch(err => { - if (err instanceof PDFServicesSdk.Error.ServiceApiError - || err instanceof PDFServicesSdk.Error.ServiceUsageError) { - console.log('Exception encountered while executing operation', err); - } else { - console.log('Exception encountered while executing operation', err); - } - }); -} catch (err) { - console.log('Exception encountered while executing operation', err); +// Generates a string containing a directory structure and file name for the output file +function createOutputFilePath() { + const filePath = "output/DeletePDFPages/"; + const date = new Date(); + const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + + ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); + fs.mkdirSync(filePath, { + recursive: true + }); + return (`${filePath}delete${dateString}.pdf`); } ``` diff --git a/src/pages/apis/pdf-services/document-generation.md b/src/pages/apis/pdf-services/document-generation.md index 1eb4f2e7d..b45bb0f26 100644 --- a/src/pages/apis/pdf-services/document-generation.md +++ b/src/pages/apis/pdf-services/document-generation.md @@ -69,49 +69,98 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/document // Run the sample: // node src/documentmerge/merge-document-to-pdf.js - const PDFServicesSdk = require('@adobe/pdfservices-node-sdk'); - -try { - // Initial setup, create credentials instance. - const credentials = PDFServicesSdk.Credentials - .servicePrincipalCredentialsBuilder() - .withClientId("PDF_SERVICES_CLIENT_ID") - .withClientSecret("PDF_SERVICES_CLIENT_SECRET") - .build(); - - // Setup input data for the document merge process. - const jsonString = "{\"customerName\": \"Kane Miller\", \"customerVisits\": 100}", - jsonDataForMerge = JSON.parse(jsonString); - - // Create an ExecutionContext using credentials. - const executionContext = PDFServicesSdk.ExecutionContext.create(credentials); - - // Create a new DocumentMerge options instance. - const documentMerge = PDFServicesSdk.DocumentMerge, - documentMergeOptions = documentMerge.options, - options = new documentMergeOptions.DocumentMergeOptions(jsonDataForMerge, documentMergeOptions.OutputFormat.PDF); - - // Create a new operation instance using the options instance. - const documentMergeOperation = documentMerge.Operation.createNew(options); - - // Set operation input document template from a source file. - const input = PDFServicesSdk.FileRef.createFromLocalFile('resources/documentMergeTemplate.docx'); - documentMergeOperation.setInput(input); - - // Execute the operation and Save the result to the specified location. - documentMergeOperation.execute(executionContext) - .then(result => result.saveAsFile('output/documentMergeOutput.pdf')) - .catch(err => { - if(err instanceof PDFServicesSdk.Error.ServiceApiError - || err instanceof PDFServicesSdk.Error.ServiceUsageError) { - console.log('Exception encountered while executing operation', err); - } else { - console.log('Exception encountered while executing operation', err); - } +const { + ServicePrincipalCredentials, + PDFServices, + MimeType, + DocumentMergeParams, + OutputFormat, + DocumentMergeJob, + DocumentMergeResult, + SDKError, + ServiceUsageError, + ServiceApiError +} = require("@dcloud/pdfservices-node-sdk"); +const fs = require("fs"); + +(async () => { + let readStream; + try { + // Initial setup, create credentials instance + const credentials = new ServicePrincipalCredentials({ + clientId: process.env.PDF_SERVICES_CLIENT_ID, + clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET }); -} -catch (err) { - console.log('Exception encountered while executing operation', err); + + // Creates a PDF Services instance + const pdfServices = new PDFServices({ + credentials + }); + + // Creates an asset(s) from source file(s) and upload + readStream = fs.createReadStream("resources/salesOrderTemplate.docx"); + const inputAsset = await pdfServices.upload({ + readStream, + mimeType: MimeType.DOCX + }); + + // Setup input data for the document merge process + const jsonString = fs.readFileSync('resources/salesOrder.json', 'utf-8'); + + // Create parameters for the job + const params = new DocumentMergeParams({ + jsonDataForMerge: JSON.parse(jsonString), + outputFormat: OutputFormat.PDF + }); + + // Creates a new job instance + const job = new DocumentMergeJob({ + inputAsset, + params + }); + + // Submit the job and get the job result + const pollingURL = await pdfServices.submit({ + job + }); + const pdfServicesResponse = await pdfServices.getJobResult({ + pollingURL, + resultType: DocumentMergeResult + }); + // Get content from the resulting asset(s) + const resultAsset = pdfServicesResponse.result.asset; + const streamAsset = await pdfServices.getContent({ + asset: resultAsset + }); + + // Creates a write stream and copy stream asset's content to it + const outputFilePath = createOutputFilePath(); + console.log(`Saving asset at ${outputFilePath}`); + + const writeStream = fs.createWriteStream(outputFilePath); + streamAsset.readStream.pipe(writeStream); + } catch (err) { + if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { + console.log("Exception encountered while executing operation", err); + } else { + console.log("Exception encountered while executing operation", err); + } + } finally { + readStream?.destroy(); + } +})(); + +// Generates a string containing a directory structure and file name for the output file +function createOutputFilePath() { + const filePath = "output/MergeDocumentToPDF/"; + const date = new Date(); + const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + + ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); + fs.mkdirSync(filePath, { + recursive: true + }); + return (`${filePath}merge${dateString}.pdf`); } ``` diff --git a/src/pages/apis/pdf-services/e-seal.md b/src/pages/apis/pdf-services/e-seal.md index 84b69d982..5f7650df1 100644 --- a/src/pages/apis/pdf-services/e-seal.md +++ b/src/pages/apis/pdf-services/e-seal.md @@ -70,93 +70,179 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/electron // Run the sample: // node src/electronicseal/electronic-seal.js -const PDFServicesSdk = require('@adobe/pdfservices-node-sdk'); -try { - // Initial setup, create credentials instance. - const credentials = PDFServicesSdk.Credentials - .servicePrincipalCredentialsBuilder() - .withClientId("PDF_SERVICES_CLIENT_ID") - .withClientSecret("PDF_SERVICES_CLIENT_SECRET") - .build(); - - // Create an ExecutionContext using credentials - const executionContext = PDFServicesSdk.ExecutionContext.create(credentials); - - const pdfElectronicSeal = PDFServicesSdk.PDFElectronicSeal, - options = pdfElectronicSeal.options; - - //Get the input document to perform the sealing operation - const sourceFile = PDFServicesSdk.FileRef.createFromLocalFile('resources/sampleInvoice.pdf'), - - //Get the background seal image for signature , if required. - sealImageFile = PDFServicesSdk.FileRef.createFromLocalFile('resources/sampleSealImage.png'); - - // Set the Seal Field Name to be created in input PDF document. - sealFieldName = "Signature1"; - - // Set the page number in input document for applying seal. - sealPageNumber = 1; - - // Set if seal should be visible or invisible. - sealVisible = true; - - //Create FieldLocation instance and set the coordinates for applying signature - fieldLocation = new options.FieldLocation(150,250,350,200); - - //Create FieldOptions instance with required details. - fieldOptions = new options.FieldOptions.Builder(sealFieldName) - .setFieldLocation(fieldLocation) - .setPageNumber(sealPageNumber) - .setVisible(sealVisible) - .build(); - - //Set the name of TSP Provider being used. - providerName = ""; - - //Set the access token to be used to access TSP provider hosted APIs. - accessToken = ""; - - //Set the credential ID. - credentialID = ""; - - //Set the PIN generated while creating credentials. - pin = ""; - - //Create CSCAuthContext instance using access token and token type. - cscAuthContext = new options.CSCAuthContext(accessToken, "Bearer"); - - //Create CertificateCredentials instance with required certificate details. - certificateCredentials = options.CertificateCredentials.cscCredentialBuilder() - .withProviderName(providerName) - .withCredentialID(credentialID) - .withPin(pin) - .withCSCAuthContext(cscAuthContext) - .build(); - - //Create SealOptions instance with sealing parameters. - sealOptions = new options.SealOptions.Builder(certificateCredentials, fieldOptions) - .build() - - //Create the PDFElectronicSealOperation instance using the SealOptions instance - const pdfElectronicSealOperation = pdfElectronicSeal.Operation.createNew(sealOptions); - - //Set the input source file for PDFElectronicSealOperation instance - pdfElectronicSealOperation.setInput(sourceFile); - - //Set the optional input seal image for PDFElectronicSealOperation instance - pdfElectronicSealOperation.setSealImage(sealImageFile); - - // Execute the operation and Save the result to the specified location. - pdfElectronicSealOperation.execute(executionContext) - .then(result => result.saveAsFile("output/ElectronicSeal/sealedOutput.pdf")) - .catch(err => { - if(err instanceof PDFServicesSdk.Error.ServiceApiError - || err instanceof PDFServicesSdk.Error.ServiceUsageError) { - console.log('Exception encountered while executing operation', err); - } else { - console.log('Exception encountered while executing operation', err); - } +const { + ServicePrincipalCredentials, + PDFServices, + MimeType, + FieldLocation, + FieldOptions, + CSCAuthContext, + CSCCredential, + PDFElectronicSealParams, + PDFElectronicSealJob, + PDFElectronicSealResult, + AppearanceOptions, + AppearanceItem, + SDKError, + ServiceUsageError, + ServiceApiError, + DocumentLevelPermission +} = require("@dcloud/pdfservices-node-sdk"); +const fs = require("fs"); + +(async () => { + + let sourceFileReadStream; + let sealImageReadStream; + try { + // Initial setup, create credentials instance + const credentials = new ServicePrincipalCredentials({ + clientId: process.env.PDF_SERVICES_CLIENT_ID, + clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET + }); + + // Creates a PDF Services instance + const pdfServices = new PDFServices({ + credentials + }); + + // Creates an asset(s) from source file(s) and upload + sourceFileReadStream = fs.createReadStream("resources/sampleInvoice.pdf") + sealImageReadStream = fs.createReadStream("resources/sampleSealImage.png"); + const [sourceFileAsset, sealImageAsset] = await pdfServices.uploadAssets({ + streamAssets: [{ + readStream: sourceFileReadStream, + mimeType: MimeType.PDF + }, { + readStream: sealImageReadStream, + mimeType: MimeType.PNG + }] + }); + + // Set the document level permission to be applied for output document + const documentLevelPermission = DocumentLevelPermission.FORM_FILLING; + + // Create AppearanceOptions and add the required signature appearance items + const sealAppearanceOptions = new AppearanceOptions({ + items: [ + AppearanceItem.DATE, + AppearanceItem.SEAL_IMAGE, + AppearanceItem.NAME, + AppearanceItem.LABELS, + AppearanceItem.DISTINGUISHED_NAME + ] + }); + + // Set the Seal Field Name to be created in input PDF document + const sealFieldName = "Signature1"; + + // Set the page number in input document for applying seal + const sealPageNumber = 1; + + // Set if seal should be visible or invisible + const sealVisible = true; + + // Create FieldLocation instance and set the coordinates for applying signature + const fieldLocation = new FieldLocation({ + left: 150, + top: 250, + right: 350, + bottom: 200 + }); + + // Create FieldOptions instance with required details + const sealFieldOptions = new FieldOptions({ + visible: sealVisible, + location: fieldLocation, + fieldName: sealFieldName, + pageNumber: sealPageNumber, + }); + + // Set the name of TSP Provider being used + const providerName = ""; + + // Set the access token to be used to access TSP provider hosted APIs + const accessToken = ""; + // Set the credential ID + const credentialId = ""; + + // Set the PIN generated while creating credentials + const pin = ""; + + // Create CSCAuthContext instance using access token and token type + const authorizationContext = new CSCAuthContext({ + accessToken, + tokenType: "Bearer" + }); + + // Create CertificateCredentials instance with required certificate details + const certificateCredentials = new CSCCredential({ + providerName, + credentialId, + pin, + authorizationContext, + }); + + // Create parameters for the job + const params = new PDFElectronicSealParams({ + documentLevelPermission, + certificateCredentials, + sealFieldOptions, + sealAppearanceOptions + }); + + // Creates a new job instance + const job = new PDFElectronicSealJob({ + inputAsset: sourceFileAsset, + sealImageAsset, + params, + }); + + // Submit the job and get the job result + const pollingURL = await pdfServices.submit({ + job + }); + const pdfServicesResponse = await pdfServices.getJobResult({ + pollingURL, + resultType: PDFElectronicSealResult + }); + + // Get content from the resulting asset(s) + const resultAsset = pdfServicesResponse.result.asset; + const streamAsset = await pdfServices.getContent({ + asset: resultAsset + }); + + // Creates a write stream and copy stream asset's content to it + const outputFilePath = createOutputFilePath(); + console.log(`Saving asset at ${outputFilePath}`); + + const writeStream = fs.createWriteStream(outputFilePath); + streamAsset.readStream.pipe(writeStream); + } catch (err) { + if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { + console.log("Exception encountered while executing operation", err); + } else { + console.log("Exception encountered while executing operation", err); + } + } finally { + sourceFileReadStream?.destroy(); + sealImageReadStream?.destroy(); + } +})(); + +// Generates a string containing a directory structure and file name for the output file +function createOutputFilePath() { + const filePath = "output/ElectronicSealWithAppearanceOptions/"; + const date = new Date(); + const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + + ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); + fs.mkdirSync(filePath, { + recursive: true }); + return (`${filePath}seal${dateString}.pdf`); +} ``` #### .Net diff --git a/src/pages/apis/pdf-services/extract-pdf-content.md b/src/pages/apis/pdf-services/extract-pdf-content.md index 4fe6c4eb3..4b34cc92b 100644 --- a/src/pages/apis/pdf-services/extract-pdf-content.md +++ b/src/pages/apis/pdf-services/extract-pdf-content.md @@ -42,47 +42,95 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/extractp // Run the sample: // node src/extractpdf/extract-text-info-from-pdf.js -const PDFServicesSdk = require('@adobe/pdfservices-node-sdk'); -try { - // Initial setup, create credentials instance. - const credentials = PDFServicesSdk.Credentials - .servicePrincipalCredentialsBuilder() - .withClientId("PDF_SERVICES_CLIENT_ID") - .withClientSecret("PDF_SERVICES_CLIENT_SECRET") - .build(); - - // Create an ExecutionContext using credentials - const executionContext = PDFServicesSdk.ExecutionContext.create(credentials); - - // Build extractPDF options - const options = new PDFServicesSdk.ExtractPDF.options.ExtractPdfOptions.Builder() - .addElementsToExtract(PDFServicesSdk.ExtractPDF.options.ExtractElementType.TEXT).build(); - - // Create a new operation instance. - const extractPDFOperation = PDFServicesSdk.ExtractPDF.Operation.createNew(), - input = PDFServicesSdk.FileRef.createFromLocalFile( - 'resources/extractPDFInput.pdf', - PDFServicesSdk.ExtractPDF.SupportedSourceFormat.pdf - ); - - // Set operation input from a source file. - extractPDFOperation.setInput(input); - - // Set options - extractPDFOperation.setOptions(options); - - extractPDFOperation.execute(executionContext) - .then(result => result.saveAsFile('output/ExtractTextInfoFromPDF.zip')) - .catch(err => { - if(err instanceof PDFServicesSdk.Error.ServiceApiError - || err instanceof PDFServicesSdk.Error.ServiceUsageError) { - console.log('Exception encountered while executing operation', err); - } else { - console.log('Exception encountered while executing operation', err); - } +const { + ServicePrincipalCredentials, + PDFServices, + MimeType, + ExtractPDFParams, + ExtractElementType, + ExtractPDFJob, + ExtractPDFResult, + SDKError, + ServiceUsageError, + ServiceApiError +} = require("@dcloud/pdfservices-node-sdk"); +const fs = require("fs"); + +(async () => { + let readStream; + try { + // Initial setup, create credentials instance + const credentials = new ServicePrincipalCredentials({ + clientId: process.env.PDF_SERVICES_CLIENT_ID, + clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET + }); + + + // Creates a PDF Services instance + const pdfServices = new PDFServices({ + credentials + }); + + // Creates an asset(s) from source file(s) and upload + readStream = fs.createReadStream("resources/extractPDFInput.pdf"); + const inputAsset = await pdfServices.upload({ + readStream, + mimeType: MimeType.PDF + }); + + // Create parameters for the job + const params = new ExtractPDFParams({ + elementsToExtract: [ExtractElementType.TEXT] + }); + + // Creates a new job instance + const job = new ExtractPDFJob({ + inputAsset, + params + }); + + // Submit the job and get the job result + const pollingURL = await pdfServices.submit({ + job }); -} catch (err) { - console.log('Exception encountered while executing operation', err); + const pdfServicesResponse = await pdfServices.getJobResult({ + pollingURL, + resultType: ExtractPDFResult + }); + + // Get content from the resulting asset(s) + const resultAsset = pdfServicesResponse.result.resource; + const streamAsset = await pdfServices.getContent({ + asset: resultAsset + }); + + // Creates a write stream and copy stream asset's content to it + const outputFilePath = createOutputFilePath(); + console.log(`Saving asset at ${outputFilePath}`); + const writeStream = fs.createWriteStream(outputFilePath); + streamAsset.readStream.pipe(writeStream); + } catch (err) { + if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { + console.log("Exception encountered while executing operation", err); + } else { + console.log("Exception encountered while executing operation", err); + } + } finally { + readStream?.destroy(); + } +})(); + +// Generates a string containing a directory structure and file name for the output file +function createOutputFilePath() { + const filePath = "output/ExtractTextInfoFromPDF/"; + const date = new Date(); + const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + + ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); + fs.mkdirSync(filePath, { + recursive: true + }); + return (`${filePath}extract${dateString}.zip`); } ``` diff --git a/src/pages/apis/pdf-services/get-pdf-properties.md b/src/pages/apis/pdf-services/get-pdf-properties.md index f479a8330..6af04cfec 100644 --- a/src/pages/apis/pdf-services/get-pdf-properties.md +++ b/src/pages/apis/pdf-services/get-pdf-properties.md @@ -42,44 +42,76 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/pdfprope // Run the sample: // node src/exportpdf/get-pdf-properties.js -const PDFServicesSdk = require('@adobe/pdfservices-node-sdk'); - -try { - // Initial setup, create credentials instance. - const credentials = PDFServicesSdk.Credentials - .servicePrincipalCredentialsBuilder() - .withClientId("PDF_SERVICES_CLIENT_ID") - .withClientSecret("PDF_SERVICES_CLIENT_SECRET") - .build(); - - //Create an ExecutionContext using credentials and create a new operation instance. - const executionContext = PDFServicesSdk.ExecutionContext.create(credentials), - pdfPropertiesOperation = PDFServicesSdk.PDFProperties.Operation.createNew(); - - // Set operation input from a source file. - const input = PDFServicesSdk.FileRef.createFromLocalFile('resources/pdfPropertiesInput.pdf'); - pdfPropertiesOperation.setInput(input); - - // Provide any custom configuration options for the operation. - const options = new PDFServicesSdk.PDFProperties.options.PDFPropertiesOptions.Builder() - .includePageLevelProperties(true) - .build(); - pdfPropertiesOperation.setOptions(options); - - // Execute the operation ang get properties of the PDF in PDFProperties object. - pdfPropertiesOperation.execute(executionContext) - .then(result => console.log("The resultant json object is : " + JSON.stringify(result, null, 4))) - .catch(err => { - if(err instanceof PDFServicesSdk.Error.ServiceApiError - || err instanceof PDFServicesSdk.Error.ServiceUsageError) { - console.log('Exception encountered while executing operation', err); - } else { - console.log('Exception encountered while executing operation', err); - } +const { + ServicePrincipalCredentials, + PDFServices, + MimeType, + PDFPropertiesParams, + PDFPropertiesJob, + PDFPropertiesResult, + SDKError, + ServiceUsageError, + ServiceApiError +} = require("@dcloud/pdfservices-node-sdk"); +const fs = require("fs"); + +(async () => { + let readStream; + try { + // Initial setup, create credentials instance + const credentials = new ServicePrincipalCredentials({ + clientId: process.env.PDF_SERVICES_CLIENT_ID, + clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET }); -} catch (err) { - console.log('Exception encountered while executing operation', err); -} + + // Creates a PDF Services instance + const pdfServices = new PDFServices({ + credentials + }); + + // Creates an asset(s) from source file(s) and upload + readStream = fs.createReadStream("resources/pdfPropertiesInput.pdf"); + const inputAsset = await pdfServices.upload({ + readStream, + mimeType: MimeType.PDF + }); + + // Create parameters for the job + const params = new PDFPropertiesParams({ + includePageLevelProperties: true + }); + + // Creates a new job instance + const job = new PDFPropertiesJob({ + inputAsset, + params + }); + + // Submit the job and get the job result + const pollingURL = await pdfServices.submit({ + job + }); + const pdfServicesResponse = await pdfServices.getJobResult({ + pollingURL, + resultType: PDFPropertiesResult + }); + + const pdfProperties = pdfServicesResponse.result.pdfProperties; + + // Fetch the requisite properties of the specified PDF. + console.log(`Size of the specified PDF file: ${pdfProperties.document.fileSize}`); + console.log(`Version of the specified PDF file: ${pdfProperties.document.pdfVersion}`); + console.log(`Page count of the specified PDF file: ${pdfProperties.document.pageCount}`); + } catch (err) { + if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { + console.log("Exception encountered while executing operation", err); + } else { + console.log("Exception encountered while executing operation", err); + } + } finally { + readStream?.destroy(); + } +})(); ``` #### .Net diff --git a/src/pages/apis/pdf-services/html-to-pdf.md b/src/pages/apis/pdf-services/html-to-pdf.md index 67d3c0300..2d08b9e35 100644 --- a/src/pages/apis/pdf-services/html-to-pdf.md +++ b/src/pages/apis/pdf-services/html-to-pdf.md @@ -45,53 +45,97 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/htmltopd // Run the sample: // node src/createpdf/create-pdf-from-static-html.js -const PDFServicesSdk = require('@adobe/pdfservices-node-sdk'); - -const setCustomOptions = (htmlToPDFOperation) => { - // Define the page layout, in this case an 8 x 11.5 inch page (effectively portrait orientation). - const pageLayout = new PDFServicesSdk.CreatePDF.options.html.PageLayout(); - pageLayout.setPageSize(8, 11.5); - - // Set the desired HTML-to-PDF conversion options. - const htmlToPdfOptions = new PDFServicesSdk.CreatePDF.options.html.CreatePDFFromHtmlOptions.Builder() - .includesHeaderFooter(true) - .withPageLayout(pageLayout) - .build(); - htmlToPDFOperation.setOptions(htmlToPdfOptions); -}; - - -try { - // Initial setup, create credentials instance. - const credentials = PDFServicesSdk.Credentials - .servicePrincipalCredentialsBuilder() - .withClientId("PDF_SERVICES_CLIENT_ID") - .withClientSecret("PDF_SERVICES_CLIENT_SECRET") - .build(); - - // Create an ExecutionContext using credentials and create a new operation instance. - const executionContext = PDFServicesSdk.ExecutionContext.create(credentials), htmlToPDFOperation = PDFServicesSdk.CreatePDF.Operation.createNew(); - - // Set operation input from a source file. - const input = PDFServicesSdk.FileRef.createFromLocalFile('resources/createPDFFromStaticHtmlInput.zip'); - htmlToPDFOperation.setInput(input); - - // Provide any custom configuration options for the operation. - setCustomOptions(htmlToPDFOperation); - - // Execute the operation and Save the result to the specified location. - htmlToPDFOperation.execute(executionContext) - .then(result => result.saveAsFile('output/createPdfFromStaticHtmlOutput.pdf')) - .catch(err => { - if(err instanceof PDFServicesSdk.Error.ServiceApiError - || err instanceof PDFServicesSdk.Error.ServiceUsageError) { - console.log('Exception encountered while executing operation', err); +const { + ServicePrincipalCredentials, + PDFServices, + PageLayout, + HTMLToPDFParams, + HTMLToPDFResult, + HTMLToPDFJob, + SDKError, + ServiceUsageError, + ServiceApiError +} = require("@dcloud/pdfservices-node-sdk"); +const fs = require("fs"); + +(async () => { + try { + // Initial setup, create credentials instance + const credentials = new ServicePrincipalCredentials({ + clientId: process.env.PDF_SERVICES_CLIENT_ID, + clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET + }); + + // Creates a PDF Services instance + const pdfServices = new PDFServices({ + credentials + }); + + const inputURL = ""; + + // Create parameters for the job + const params = getHTMLToPDFParams(); + + // Creates a new job instance + const job = new HTMLToPDFJob({ + inputURL, + params + }); + + // Submit the job and get the job result + const pollingURL = await pdfServices.submit({ + job + }); + const pdfServicesResponse = await pdfServices.getJobResult({ + pollingURL, + resultType: HTMLToPDFResult + }); + + // Get content from the resulting asset(s) + const resultAsset = pdfServicesResponse.result.asset; + const streamAsset = await pdfServices.getContent({ + asset: resultAsset + }); + + // Creates an output stream and copy result asset's content to it + const outputFilePath = createOutputFilePath(); + console.log(`Saving asset at ${outputFilePath}`); + + const outputStream = fs.createWriteStream(outputFilePath); + streamAsset.readStream.pipe(outputStream); + } catch (err) { + if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { + console.log("Exception encountered while executing operation", err); } else { - console.log('Exception encountered while executing operation', err); + console.log("Exception encountered while executing operation", err); } + } +})(); + +function getHTMLToPDFParams() { + // Define the page layout, in this case an 8 x 11.5 inch page (effectively portrait orientation) + const pageLayout = new PageLayout({ + pageHeight: 11.5, + pageWidth: 8 + }); + + return new HTMLToPDFParams({ + includeHeaderFooter: true, + pageLayout + }); +} + +// Generates a string containing a directory structure and file name for the output file +function createOutputFilePath() { + const filePath = "output/HTMLToPDFFromURL/"; + const date = new Date(); + const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + + ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); + fs.mkdirSync(filePath, { + recursive: true }); -} catch (err) { - console.log('Exception encountered while executing operation', err); + return (`${filePath}create${dateString}.pdf`); } ``` diff --git a/src/pages/apis/pdf-services/insert-pdf-pages.md b/src/pages/apis/pdf-services/insert-pdf-pages.md index b19159d37..4dff33839 100644 --- a/src/pages/apis/pdf-services/insert-pdf-pages.md +++ b/src/pages/apis/pdf-services/insert-pdf-pages.md @@ -73,62 +73,126 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/combinep // Run the sample: // node src/insertpages/insert-pdf-pages.js -const PDFServicesSdk = require('@adobe/pdfservices-node-sdk'); - -const getPageRangesForFirstFile = () => { - // Specify which pages of the first file are to be inserted in the base file. - const pageRangesForFirstFile = new PDFServicesSdk.PageRanges(); - // Add pages 1 to 3. - pageRangesForFirstFile.addPageRange(1, 3); - - // Add page 4. - pageRangesForFirstFile.addSinglePage(4); - - return pageRangesForFirstFile; -}; - -try { - // Initial setup, create credentials instance. - const credentials = PDFServicesSdk.Credentials - .servicePrincipalCredentialsBuilder() - .withClientId("PDF_SERVICES_CLIENT_ID") - .withClientSecret("PDF_SERVICES_CLIENT_SECRET") - .build(); - - // Create an ExecutionContext using credentials and create a new operation instance. - const executionContext = PDFServicesSdk.ExecutionContext.create(credentials), - insertPagesOperation = PDFServicesSdk.InsertPages.Operation.createNew(); - - // Set operation base input from a source file. - const baseInputFile = PDFServicesSdk.FileRef.createFromLocalFile('resources/baseInput.pdf'); - insertPagesOperation.setBaseInput(baseInputFile); - - // Create a FileRef instance using a local file. - const firstFileToInsert = PDFServicesSdk.FileRef.createFromLocalFile('resources/firstFileToInsertInput.pdf'), - pageRanges = getPageRangesForFirstFile(); - - // Adds the pages (specified by the page ranges) of the input PDF file to be inserted at the specified page of the base PDF file. - insertPagesOperation.addPagesToInsertAt(2, firstFileToInsert, pageRanges); - - // Create a FileRef instance using a local file. - const secondFileToInsert = PDFServicesSdk.FileRef.createFromLocalFile('resources/secondFileToInsertInput.pdf'); - - // Adds all the pages of the input PDF file to be inserted at the specified page of the base PDF file. - insertPagesOperation.addPagesToInsertAt(3, secondFileToInsert); - - // Execute the operation and Save the result to the specified location. - insertPagesOperation.execute(executionContext) - .then(result => result.saveAsFile('output/insertPagesOutput.pdf')) - .catch(err => { - if (err instanceof PDFServicesSdk.Error.ServiceApiError - || err instanceof PDFServicesSdk.Error.ServiceUsageError) { - console.log('Exception encountered while executing operation', err); - } else { - console.log('Exception encountered while executing operation', err); - } +const { + ServicePrincipalCredentials, + PDFServices, + MimeType, + PageRanges, + InsertPagesParams, + InsertPagesJob, + InsertPagesResult, + SDKError, + ServiceUsageError, + ServiceApiError +} = require("@dcloud/pdfservices-node-sdk"); +const fs = require("fs"); + +(async () => { + let baseReadStream; + let firstReadStreamToInsert; + let secondReadStreamToInsert; + try { + // Initial setup, create credentials instance + const credentials = new ServicePrincipalCredentials({ + clientId: process.env.PDF_SERVICES_CLIENT_ID, + clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET + }); + + // Creates a PDF Services instance + const pdfServices = new PDFServices({ + credentials + }); + + // Creates an asset(s) from source file(s) and upload + baseReadStream = fs.createReadStream("resources/baseInput.pdf"); + firstReadStreamToInsert = fs.createReadStream("resources/firstFileToInsertInput.pdf"); + secondReadStreamToInsert = fs.createReadStream("resources/secondFileToInsertInput.pdf"); + const [baseAsset, firstAssetToInsert, secondAssetToInsert] = await pdfServices.uploadAssets({ + streamAssets: [{ + readStream: baseReadStream, + mimeType: MimeType.PDF + }, { + readStream: firstReadStreamToInsert, + mimeType: MimeType.PDF + }, { + readStream: secondReadStreamToInsert, + mimeType: MimeType.PDF + }] + }); + + // Create parameters for the job + const params = new InsertPagesParams(baseAsset) + // Add the first asset as input to the params, along with its page ranges and base page + .addPagesToInsertAt({ + inputAsset: firstAssetToInsert, + pageRanges: getPageRangesForFirstFile(), + basePage: 2 + }) + // Add the second asset as input to the params, along with base page + .addPagesToInsertAt({ + inputAsset: secondAssetToInsert, + basePage: 3 + }); + + // Create a new job instance + const job = new InsertPagesJob({ + params }); -} catch (err) { - console.log('Exception encountered while executing operation', err); + + // Submit the job and get the job result + const pollingURL = await pdfServices.submit({ + job + }); + const pdfServicesResponse = await pdfServices.getJobResult({ + pollingURL, + resultType: InsertPagesResult + }); + // Get content from the resulting asset(s) + const resultAsset = pdfServicesResponse.result.asset; + const streamAsset = await pdfServices.getContent({ + asset: resultAsset + }); + + // Creates an output stream and copy result asset's content to it + const outputFilePath = createOutputFilePath(); + console.log(`Saving asset at ${outputFilePath}`); + + const outputStream = fs.createWriteStream(outputFilePath); + streamAsset.readStream.pipe(outputStream); + } catch (err) { + if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { + console.log("Exception encountered while executing operation", err); + } else { + console.log("Exception encountered while executing operation", err); + } + } finally { + baseReadStream?.destroy(); + firstReadStreamToInsert?.destroy(); + secondReadStreamToInsert?.destroy(); + } +})(); + +function getPageRangesForFirstFile() { + // Specify which pages of the first file are to be inserted in the base file + const pageRanges = new PageRanges(); + // Add pages 1 to 3 + pageRanges.addRange(1, 3); + // Add page 4 + pageRanges.addSinglePage(4); + return pageRanges; +} + +// Generates a string containing a directory structure and file name for the output file +function createOutputFilePath() { + const filePath = "output/InsertPages/"; + const date = new Date(); + const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + + ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); + fs.mkdirSync(filePath, { + recursive: true + }); + return (`${filePath}insert${dateString}.pdf`); } ``` diff --git a/src/pages/apis/pdf-services/linearize-pdf.md b/src/pages/apis/pdf-services/linearize-pdf.md index 437358847..4da2b924a 100644 --- a/src/pages/apis/pdf-services/linearize-pdf.md +++ b/src/pages/apis/pdf-services/linearize-pdf.md @@ -39,38 +39,86 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/lineariz // Run the sample: // node src/linearizepdf/linearize-pdf.js -const PDFServicesSdk = require('@adobe/pdfservices-node-sdk'); - -try { - // Initial setup, create credentials instance. - const credentials = PDFServicesSdk.Credentials - .servicePrincipalCredentialsBuilder() - .withClientId("PDF_SERVICES_CLIENT_ID") - .withClientSecret("PDF_SERVICES_CLIENT_SECRET") - .build(); - - // Create an ExecutionContext using credentials and create a new operation instance. - const executionContext = PDFServicesSdk.ExecutionContext.create(credentials), - linearizePDF = PDFServicesSdk.LinearizePDF, - linearizePDFOperation = linearizePDF.Operation.createNew(); - - // Set operation input from a source file. - const input = PDFServicesSdk.FileRef.createFromLocalFile('resources/linearizePDFInput.pdf'); - linearizePDFOperation.setInput(input); - - // Execute the operation and Save the result to the specified location. - linearizePDFOperation.execute(executionContext) - .then(result => result.saveAsFile('output/linearizePDFOutput.pdf')) - .catch(err => { - if(err instanceof PDFServicesSdk.Error.ServiceApiError - || err instanceof PDFServicesSdk.Error.ServiceUsageError) { - console.log('Exception encountered while executing operation', err); - } else { - console.log('Exception encountered while executing operation', err); - } +const { + ServicePrincipalCredentials, + PDFServices, + MimeType, + LinearizePDFJob, + LinearizePDFResult, + SDKError, + ServiceUsageError, + ServiceApiError +} = require("@dcloud/pdfservices-node-sdk"); +const fs = require("fs"); + +(async () => { + let readStream; + try { + // Initial setup, create credentials instance + const credentials = new ServicePrincipalCredentials({ + clientId: process.env.PDF_SERVICES_CLIENT_ID, + clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET + }); + // Creates a PDF Services instance + const pdfServices = new PDFServices({ + credentials + }); + + // Creates an asset(s) from source file(s) and upload + readStream = fs.createReadStream("resources/linearizePDFInput.pdf"); + const inputAsset = await pdfServices.upload({ + readStream, + mimeType: MimeType.PDF + }); + + // Creates a new job instance + const job = new LinearizePDFJob({ + inputAsset + }); + + // Submit the job and get the job result + const pollingURL = await pdfServices.submit({ + job + }); + const pdfServicesResponse = await pdfServices.getJobResult({ + pollingURL, + resultType: LinearizePDFResult + }); + + // Get content from the resulting asset(s) + const resultAsset = pdfServicesResponse.result.asset; + const streamAsset = await pdfServices.getContent({ + asset: resultAsset }); -} catch (err) { - console.log('Exception encountered while executing operation', err); + + // Creates an output stream and copy stream asset's content to it + const outputFilePath = createOutputFilePath(); + console.log(`Saving asset at ${outputFilePath}`); + + const outputStream = fs.createWriteStream(outputFilePath); + streamAsset.readStream.pipe(outputStream); + } catch (err) { + if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { + console.log("Exception encountered while executing operation", err); + } else { + console.log("Exception encountered while executing operation", err); + } + } finally { + readStream?.destroy(); + } +})(); + +// Generates a string containing a directory structure and file name for the output file +function createOutputFilePath() { + const filePath = "output/LinearizePDF/"; + const date = new Date(); + const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + + ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); + fs.mkdirSync(filePath, { + recursive: true + }); + return (`${filePath}linearize${dateString}.pdf`); } ``` diff --git a/src/pages/apis/pdf-services/ocr-pdf.md b/src/pages/apis/pdf-services/ocr-pdf.md index e2a2196cc..74822935a 100644 --- a/src/pages/apis/pdf-services/ocr-pdf.md +++ b/src/pages/apis/pdf-services/ocr-pdf.md @@ -39,37 +39,87 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/ocr' \ // Run the sample: // node src/ocr/ocr-pdf.js -const PDFServicesSdk = require('@adobe/pdfservices-node-sdk'); - -try { - // Initial setup, create credentials instance. - const credentials = PDFServicesSdk.Credentials - .servicePrincipalCredentialsBuilder() - .withClientId("PDF_SERVICES_CLIENT_ID") - .withClientSecret("PDF_SERVICES_CLIENT_SECRET") - .build(); - - // Create an ExecutionContext using credentials and create a new operation instance. - const executionContext = PDFServicesSdk.ExecutionContext.create(credentials), - ocrOperation = PDFServicesSdk.OCR.Operation.createNew(); - - // Set operation input from a source file. - const input = PDFServicesSdk.FileRef.createFromLocalFile('resources/ocrInput.pdf'); - ocrOperation.setInput(input); - - // Execute the operation and Save the result to the specified location. - ocrOperation.execute(executionContext) - .then(result => result.saveAsFile('output/ocrOutput.pdf')) - .catch(err => { - if(err instanceof PDFServicesSdk.Error.ServiceApiError - || err instanceof PDFServicesSdk.Error.ServiceUsageError) { - console.log('Exception encountered while executing operation', err); - } else { - console.log('Exception encountered while executing operation', err); - } - }); -} catch (err) { - console.log('Exception encountered while executing operation', err); +const { + ServicePrincipalCredentials, + PDFServices, + MimeType, + OCRJob, + OCRResult, + SDKError, + ServiceUsageError, + ServiceApiError +} = require("@dcloud/pdfservices-node-sdk"); +const fs = require("fs"); + +(async () => { + let readStream; + try { + // Initial setup, create credentials instance + const credentials = new ServicePrincipalCredentials({ + clientId: process.env.PDF_SERVICES_CLIENT_ID, + clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET + }); + + // Creates a PDF Services instance + const pdfServices = new PDFServices({ + credentials + }); + + // Creates an asset(s) from source file(s) and upload + readStream = fs.createReadStream("resources/ocrInput.pdf"); + const inputAsset = await pdfServices.upload({ + readStream, + mimeType: MimeType.PDF + }); + + // Creates a new job instance + const job = new OCRJob({ + inputAsset + }); + + // Submit the job and get the job result + const pollingURL = await pdfServices.submit({ + job + }); + const pdfServicesResponse = await pdfServices.getJobResult({ + pollingURL, + resultType: OCRResult + }); + + // Get content from the resulting asset(s) + const resultAsset = pdfServicesResponse.result.asset; + const streamAsset = await pdfServices.getContent({ + asset: resultAsset + }); + + // Creates a write stream and copy stream asset's content to it + const outputFilePath = createOutputFilePath(); + console.log(`Saving asset at ${outputFilePath}`); + + const writeStream = fs.createWriteStream(outputFilePath); + streamAsset.readStream.pipe(writeStream); + } catch (err) { + if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { + console.log("Exception encountered while executing operation", err); + } else { + console.log("Exception encountered while executing operation", err); + } + } finally { + readStream?.destroy(); + } +})(); + +// Generates a string containing a directory structure and file name for the output file +function createOutputFilePath() { + const filePath = "output/OCRPDF/"; + const date = new Date(); + const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + + ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); + fs.mkdirSync(filePath, { + recursive: true + }); + return (`${filePath}ocr${dateString}.pdf`); } ``` diff --git a/src/pages/apis/pdf-services/remove-pdf-password.md b/src/pages/apis/pdf-services/remove-pdf-password.md index bdf9e90b2..677dcab14 100644 --- a/src/pages/apis/pdf-services/remove-pdf-password.md +++ b/src/pages/apis/pdf-services/remove-pdf-password.md @@ -40,44 +40,94 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/removepr // Run the sample: // node src/removeprotection/remove-protection.js -const PDFServicesSdk = require('@adobe/pdfservices-node-sdk'); - -try { - // Initial setup, create credentials instance. - const credentials = PDFServicesSdk.Credentials - .servicePrincipalCredentialsBuilder() - .withClientId("PDF_SERVICES_CLIENT_ID") - .withClientSecret("PDF_SERVICES_CLIENT_SECRET") - .build(); - - // Create an ExecutionContext using credentials - const executionContext = PDFServicesSdk.ExecutionContext.create(credentials); - - // Create a new operation instance. - const removeProtectionOperation = PDFServicesSdk.RemoveProtection.Operation.createNew(), - input = PDFServicesSdk.FileRef.createFromLocalFile( - 'resources/removeProtectionInput.pdf', - PDFServicesSdk.RemoveProtection.SupportedSourceFormat.pdf - ); - // Set operation input from a source file. - removeProtectionOperation.setInput(input); - - // Set the password for removing security from a PDF document. - removeProtectionOperation.setPassword("password"); - - // Execute the operation and Save the result to the specified location. - removeProtectionOperation.execute(executionContext) - .then(result => result.saveAsFile('output/removeProtectionOutput.pdf')) - .catch(err => { - if(err instanceof PDFServicesSdk.Error.ServiceApiError - || err instanceof PDFServicesSdk.Error.ServiceUsageError) { - console.log('Exception encountered while executing operation', err); - } else { - console.log('Exception encountered while executing operation', err); - } +const { + ServicePrincipalCredentials, + PDFServices, + MimeType, + RemoveProtectionParams, + RemoveProtectionJob, + RemoveProtectionResult, + SDKError, + ServiceUsageError, + ServiceApiError +} = require("@dcloud/pdfservices-node-sdk"); +const fs = require("fs"); + +(async () => { + let readStream; + try { + // Initial setup, create credentials instance. + const credentials = new ServicePrincipalCredentials({ + clientId: process.env.PDF_SERVICES_CLIENT_ID, + clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET + }); + + // Creates a PDF Services instance + const pdfServices = new PDFServices({ + credentials + }); + + // Creates an asset(s) from source file(s) and upload + readStream = fs.createReadStream("resources/removeProtectionInput.pdf") + const inputAsset = await pdfServices.upload({ + readStream, + mimeType: MimeType.PDF }); -} catch (err) { - console.log('Exception encountered while executing operation', err); + + // Create parameters for the job + const params = new RemoveProtectionParams({ + password: "password" + }); + + // Creates a new job instance + const job = new RemoveProtectionJob({ + inputAsset, + params + }); + + // Submit the job and get the job result + const pollingURL = await pdfServices.submit({ + job + }); + const pdfServicesResponse = await pdfServices.getJobResult({ + pollingURL, + resultType: RemoveProtectionResult + }); + + // Get content from the resulting asset(s) + const resultAsset = pdfServicesResponse.result.asset; + const streamAsset = await pdfServices.getContent({ + asset: resultAsset + }); + + // Creates an output stream and copy stream asset's content to it + const outputFilePath = createOutputFilePath(); + console.log(`Saving asset at ${outputFilePath}`); + + + const outputStream = fs.createWriteStream(outputFilePath); + streamAsset.readStream.pipe(outputStream); + } catch (err) { + if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { + console.log("Exception encountered while executing operation", err); + } else { + console.log("Exception encountered while executing operation", err); + } + } finally { + readStream?.destroy(); + } +})(); +// Generates a string containing a directory structure and file name for the output file +function createOutputFilePath() { + const filePath = "output/RemoveProtection/"; + const date = new Date(); + const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + + ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); + fs.mkdirSync(filePath, { + recursive: true + }); + return (`${filePath}removeProtection${dateString}.pdf`); } ``` diff --git a/src/pages/apis/pdf-services/reorder-pdf-pages.md b/src/pages/apis/pdf-services/reorder-pdf-pages.md index b87b2b90b..7c2b5e64b 100644 --- a/src/pages/apis/pdf-services/reorder-pdf-pages.md +++ b/src/pages/apis/pdf-services/reorder-pdf-pages.md @@ -57,51 +57,105 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/combinep // Run the sample: // node src/reorderpages/reorder-pdf-pages.js -const PDFServicesSdk = require('@adobe/pdfservices-node-sdk'); +const { + ServicePrincipalCredentials, + PDFServices, + MimeType, + PageRanges, + ReorderPagesParams, + ReorderPagesJob, + ReorderPagesResult, + SDKError, + ServiceUsageError, + ServiceApiError +} = require("@dcloud/pdfservices-node-sdk"); +const fs = require("fs"); + +(async () => { + let readStream; + try { + // Initial setup, create credentials instance + const credentials = new ServicePrincipalCredentials({ + clientId: process.env.PDF_SERVICES_CLIENT_ID, + clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET + }); -const getPageRangeForReorder = () => { - // Specify order of the pages for an output document. - const pageRanges = new PDFServicesSdk.PageRanges(); + // Creates a PDF Services instance + const pdfServices = new PDFServices({ + credentials + }); - // Add pages 3 to 4. - pageRanges.addPageRange(3, 4); + // Creates an asset(s) from source file(s) and upload + readStream = fs.createReadStream("resources/reorderPagesInput.pdf"); + const inputAsset = await pdfServices.upload({ + readStream, + mimeType: MimeType.PDF + }); - // Add page 1. - pageRanges.addSinglePage(1); + // Create parameters for the job + // Add the asset as input to the params, along with its page order + const params = new ReorderPagesParams({ + asset: inputAsset, + pageRanges: getPageRangeForReorder() + }); - return pageRanges; -}; -try { - // Initial setup, create credentials instance. - const credentials = PDFServicesSdk.Credentials - .servicePrincipalCredentialsBuilder() - .withClientId("PDF_SERVICES_CLIENT_ID") - .withClientSecret("PDF_SERVICES_CLIENT_SECRET") - .build(); - - // Create an ExecutionContext using credentials and create a new operation instance. - const executionContext = PDFServicesSdk.ExecutionContext.create(credentials), - reorderPagesOperation = PDFServicesSdk.ReorderPages.Operation.createNew(); - - // Set operation input from a source file, along with specifying the order of the pages for rearranging the pages in a PDF file. - const input = PDFServicesSdk.FileRef.createFromLocalFile('resources/reorderPagesInput.pdf'); - const pageRanges = getPageRangeForReorder(); - reorderPagesOperation.setInput(input); - reorderPagesOperation.setPagesOrder(pageRanges); - - // Execute the operation and Save the result to the specified location. - reorderPagesOperation.execute(executionContext) - .then(result => result.saveAsFile('output/reorderPagesOutput.pdf')) - .catch(err => { - if(err instanceof PDFServicesSdk.Error.ServiceApiError - || err instanceof PDFServicesSdk.Error.ServiceUsageError) { - console.log('Exception encountered while executing operation', err); - } else { - console.log('Exception encountered while executing operation', err); - } + // Creates a new job instance + const job = new ReorderPagesJob({ + params + }); + + // Submit the job and get the job result + const pollingURL = await pdfServices.submit({ + job + }); + const pdfServicesResponse = await pdfServices.getJobResult({ + pollingURL, + resultType: ReorderPagesResult }); -} catch (err) { - console.log('Exception encountered while executing operation', err); + + // Get content from the resulting asset(s) + const resultAsset = pdfServicesResponse.result.asset; + const streamAsset = await pdfServices.getContent({ + asset: resultAsset + }); + + // Creates an output stream and copy result asset's content to it + const outputFilePath = createOutputFilePath(); + console.log(`Saving asset at ${outputFilePath}`); + const outputStream = fs.createWriteStream(outputFilePath); + streamAsset.readStream.pipe(outputStream); + } catch (err) { + if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { + console.log("Exception encountered while executing operation", err); + } else { + console.log("Exception encountered while executing operation", err); + } + } finally { + readStream?.destroy(); + } +})(); + +function getPageRangeForReorder() { + // Specify order of the pages for an output document + const pageRanges = new PageRanges(); + // Add pages 3 to 4 + pageRanges.addRange(3, 4); + // Add page 1 + pageRanges.addSinglePage(1); + return pageRanges; +} + +// Generates a string containing a directory structure and file name for the output file +function createOutputFilePath() { + const filePath = "output/ReorderPages/"; + const date = new Date(); + const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + + ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); + fs.mkdirSync(filePath, { + recursive: true + }); + return (`${filePath}reorder${dateString}.pdf`); } ``` diff --git a/src/pages/apis/pdf-services/replace-pdf-pages.md b/src/pages/apis/pdf-services/replace-pdf-pages.md index 157b65062..d6dd0c109 100644 --- a/src/pages/apis/pdf-services/replace-pdf-pages.md +++ b/src/pages/apis/pdf-services/replace-pdf-pages.md @@ -64,62 +64,127 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/combinep // Run the sample: // node src/replacepages/replace-pdf-pages.js -const PDFServicesSdk = require('@adobe/pdfservices-node-sdk'); - -const getPageRangesForFirstFile = () => { - // Specify pages of the first file for replacing the page of base PDF file. - const pageRangesForFirstFile = new PDFServicesSdk.PageRanges(); - // Add pages 1 to 3. - pageRangesForFirstFile.addPageRange(1, 3); - - // Add page 4. - pageRangesForFirstFile.addSinglePage(4); - - return pageRangesForFirstFile; -}; - -try { - // Initial setup, create credentials instance. - const credentials = PDFServicesSdk.Credentials - .servicePrincipalCredentialsBuilder() - .withClientId("PDF_SERVICES_CLIENT_ID") - .withClientSecret("PDF_SERVICES_CLIENT_SECRET") - .build(); - - // Create an ExecutionContext using credentials and create a new operation instance. - const executionContext = PDFServicesSdk.ExecutionContext.create(credentials), - replacePagesOperation = PDFServicesSdk.ReplacePages.Operation.createNew(); - - // Set operation base input from a source file. - const baseInputFile = PDFServicesSdk.FileRef.createFromLocalFile('resources/baseInput.pdf'); - replacePagesOperation.setBaseInput(baseInputFile); - - // Create a FileRef instance using a local file. - const firstInputFile = PDFServicesSdk.FileRef.createFromLocalFile('resources/replacePagesInput1.pdf'), - pageRanges = getPageRangesForFirstFile(); - - // Adds the pages (specified by the page ranges) of the input PDF file for replacing the page of the base PDF file. - replacePagesOperation.addPagesForReplace(1, firstInputFile, pageRanges); - - // Create a FileRef instance using a local file. - const secondInputFile = PDFServicesSdk.FileRef.createFromLocalFile('resources/replacePagesInput2.pdf'); - - // Adds all the pages of the input PDF file for replacing the page of the base PDF file. - replacePagesOperation.addPagesForReplace(3, secondInputFile); - - // Execute the operation and Save the result to the specified location. - replacePagesOperation.execute(executionContext) - .then(result => result.saveAsFile('output/replacePagesOutput.pdf')) - .catch(err => { - if (err instanceof PDFServicesSdk.Error.ServiceApiError - || err instanceof PDFServicesSdk.Error.ServiceUsageError) { - console.log('Exception encountered while executing operation', err); +const { + ServicePrincipalCredentials, + PDFServices, + MimeType, + PageRanges, + InsertPagesResult, + ReplacePagesJob, + ReplacePagesParams, + SDKError, + ServiceUsageError, + ServiceApiError +} = require("@dcloud/pdfservices-node-sdk"); +const fs = require("fs"); + +(async () => { + let baseReadStream; + let readStream1; + let readStream2; + try { + // Initial setup, create credentials instance + const credentials = new ServicePrincipalCredentials({ + clientId: process.env.PDF_SERVICES_CLIENT_ID, + clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET + }); + + // Creates a PDF Services instance + const pdfServices = new PDFServices({ + credentials + }); + + // Creates an asset(s) from source file(s) and upload + baseReadStream = fs.createReadStream("resources/baseInput.pdf"); + readStream1 = fs.createReadStream("resources/replacePagesInput1.pdf"); + readStream2 = fs.createReadStream("resources/replacePagesInput2.pdf"); + const [baseAsset, asset1, asset2] = await pdfServices.uploadAssets({ + streamAssets: [{ + readStream: baseReadStream, + mimeType: MimeType.PDF + }, { + readStream: readStream1, + mimeType: MimeType.PDF + }, { + readStream: readStream2, + mimeType: MimeType.PDF + }] + }); + + // Create parameters for the job + const params = new ReplacePagesParams(baseAsset) + // Add the first asset as input to the params, along with its page ranges and base page + .addPagesForReplace({ + asset: asset1, + pageRanges: getPageRangesForFirstFile(), + basePage: 1 + }) + // Add the second asset as input to the params, along with base page + .addPagesForReplace({ + asset: asset2, + basePage: 3 + }); + + // Create a new job instance + const job = new ReplacePagesJob({ + params + }); + + // Submit the job and get the job result + const pollingURL = await pdfServices.submit({ + job + }); + const pdfServicesResponse = await pdfServices.getJobResult({ + pollingURL, + resultType: InsertPagesResult + }); + + // Get content from the resulting asset(s) + const resultAsset = pdfServicesResponse.result.asset; + const streamAsset = await pdfServices.getContent({ + asset: resultAsset + }); + + // Creates an output stream and copy result asset's content to it + const outputFilePath = createOutputFilePath(); + console.log(`Saving asset at ${outputFilePath}`); + + const outputStream = fs.createWriteStream(outputFilePath); + streamAsset.readStream.pipe(outputStream); + } catch (err) { + if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { + console.log("Exception encountered while executing operation", err); } else { - console.log('Exception encountered while executing operation', err); + console.log("Exception encountered while executing operation", err); } + } finally { + baseReadStream?.destroy(); + readStream1?.destroy(); + readStream2?.destroy(); + } +})(); + +function getPageRangesForFirstFile() { + // Specify pages of the first file for replacing the page of base PDF file + const pageRanges = new PageRanges(); + // Add pages 1 to 3 + pageRanges.addRange(1, 3); + // Add page 4 + pageRanges.addSinglePage(4); + return pageRanges; +} + +// Generates a string containing a directory structure and file name for the output file +function createOutputFilePath() { + const filePath = "output/ReplacePages/"; + const date = new Date(); + const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + + ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); + fs.mkdirSync(filePath, { + recursive: true }); -} catch (err) { - console.log('Exception encountered while executing operation', err); + return (`${filePath}replace${dateString}.pdf`); } ``` diff --git a/src/pages/apis/pdf-services/rotate-pdf-pages.md b/src/pages/apis/pdf-services/rotate-pdf-pages.md index 4dc9328f6..764c2ab78 100644 --- a/src/pages/apis/pdf-services/rotate-pdf-pages.md +++ b/src/pages/apis/pdf-services/rotate-pdf-pages.md @@ -62,67 +62,114 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/pagemani // Run the sample: // node src/rotatepages/rotate-pdf-pages.js -const PDFServicesSdk = require('@adobe/pdfservices-node-sdk'); +const { + ServicePrincipalCredentials, + PDFServices, + MimeType, + PageRanges, + RotatePagesParams, + Angle, + RotatePagesJob, + RotatePagesResult, + SDKError, + ServiceUsageError, + ServiceApiError +} = require("@dcloud/pdfservices-node-sdk"); +const fs = require("fs"); + +(async () => { + let readStream; + try { + // Initial setup, create credentials instance + const credentials = new ServicePrincipalCredentials({ + clientId: process.env.PDF_SERVICES_CLIENT_ID, + clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET + }); + + // Creates a PDF Services instance + const pdfServices = new PDFServices({ + credentials + }); + + // Creates an asset(s) from source file(s) and upload + readStream = fs.createReadStream("resources/rotatePagesInput.pdf"); + const inputAsset = await pdfServices.upload({ + readStream, + mimeType: MimeType.PDF + }); + + // First set of page ranges for rotating the specified pages of the input PDF file + const firstPageRange = getFirstPageRangeForRotation(); + + // Second set of page ranges for rotating the specified pages of the input PDF file + const secondPageRange = getSecondPageRangeForRotation(); + + // Create parameters for the job + const params = new RotatePagesParams() + .setAngleToRotatePagesBy(Angle._90, firstPageRange) + .setAngleToRotatePagesBy(Angle._180, secondPageRange); + + // Creates a new job instance + const job = new RotatePagesJob({ + inputAsset, + params + }); + + // Submit the job and get the job result + const pollingURL = await pdfServices.submit({ + job + }); + const pdfServicesResponse = await pdfServices.getJobResult({ + pollingURL, + resultType: RotatePagesResult + }); -const getFirstPageRangeForRotation = () => { + // Get content from the resulting asset(s) + const resultAsset = pdfServicesResponse.result.asset; + const streamAsset = await pdfServices.getContent({ + asset: resultAsset + }); + + // Creates a write stream and copy stream asset's content to it + const outputFilePath = createOutputFilePath(); + console.log(`Saving asset at ${outputFilePath}`); + + const writeStream = fs.createWriteStream(outputFilePath); + streamAsset.readStream.pipe(writeStream); + } catch (err) { + if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { + console.log("Exception encountered while executing operation", err); + } else { + console.log("Exception encountered while executing operation", err); + } + } finally { + readStream?.destroy(); + } +})(); + +function getFirstPageRangeForRotation() { // Specify pages for rotation. - const firstPageRange = new PDFServicesSdk.PageRanges(); + const firstPageRange = new PageRanges(); // Add page 1. firstPageRange.addSinglePage(1); - // Add pages 3 to 4. - firstPageRange.addPageRange(3, 4); - + firstPageRange.addRange(3, 4); return firstPageRange; -}; +} -const getSecondPageRangeForRotation = () => { - // Specify pages for rotation. - const secondPageRange = new PDFServicesSdk.PageRanges(); - // Add page 2. - secondPageRange.addSinglePage(2); - - return secondPageRange; -}; - -try { - // Initial setup, create credentials instance. - const credentials = PDFServicesSdk.Credentials - .servicePrincipalCredentialsBuilder() - .withClientId("PDF_SERVICES_CLIENT_ID") - .withClientSecret("PDF_SERVICES_CLIENT_SECRET") - .build(); - - // Create an ExecutionContext using credentials and create a new operation instance. - const executionContext = PDFServicesSdk.ExecutionContext.create(credentials), - rotatePagesOperation = PDFServicesSdk.RotatePages.Operation.createNew(); - - // Set operation input from a source file. - const input = PDFServicesSdk.FileRef.createFromLocalFile('resources/rotatePagesInput.pdf'); - rotatePagesOperation.setInput(input); - - // Sets angle by 90 degrees (in clockwise direction) for rotating the specified pages of the input PDF file. - const firstPageRange = getFirstPageRangeForRotation(); - rotatePagesOperation.setAngleToRotatePagesBy(PDFServicesSdk.RotatePages.Angle._90, firstPageRange); - - // Sets angle by 180 degrees (in clockwise direction) for rotating the specified pages of the input PDF file. - const secondPageRange = getSecondPageRangeForRotation(); - rotatePagesOperation.setAngleToRotatePagesBy(PDFServicesSdk.RotatePages.Angle._180,secondPageRange); - - // Execute the operation and Save the result to the specified location. - rotatePagesOperation.execute(executionContext) - .then(result => result.saveAsFile('output/rotatePagesOutput.pdf')) - .catch(err => { - if (err instanceof PDFServicesSdk.Error.ServiceApiError - || err instanceof PDFServicesSdk.Error.ServiceUsageError) { - console.log('Exception encountered while executing operation', err); - } else { - console.log('Exception encountered while executing operation', err); - } - }); -} catch (err) { - console.log('Exception encountered while executing operation', err); +// Generates a string containing a directory structure and file name for the output file +function createOutputFilePath() { + const filePath = "output/RotatePages/"; + const date = new Date(); + const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + + ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); + fs.mkdirSync(filePath, { + recursive: true + }); + return (`${filePath}rotate${dateString}.pdf`); } + ``` #### .Net diff --git a/src/pages/apis/pdf-services/secure-pdf.md b/src/pages/apis/pdf-services/secure-pdf.md index f5423ee46..3a0aaf87b 100644 --- a/src/pages/apis/pdf-services/secure-pdf.md +++ b/src/pages/apis/pdf-services/secure-pdf.md @@ -41,46 +41,89 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/protectp // Run the sample: // node src/protectpdf/protect-pdf.js - const PDFServicesSdk = require('@adobe/pdfservices-node-sdk'); - +const { + ServicePrincipalCredentials, + PDFServices, + MimeType, + ProtectPDFParams, + EncryptionAlgorithm, + ProtectPDFJob, + ProtectPDFResult, + SDKError, + ServiceUsageError, + ServiceApiError +} = require("@dcloud/pdfservices-node-sdk"); +const fs = require("fs"); + +(async () => { + let readStream; try { - // Initial setup, create credentials instance. - const credentials = PDFServicesSdk.Credentials - .servicePrincipalCredentialsBuilder() - .withClientId("PDF_SERVICES_CLIENT_ID") - .withClientSecret("PDF_SERVICES_CLIENT_SECRET") - .build(); - - // Create an ExecutionContext using credentials - const executionContext = PDFServicesSdk.ExecutionContext.create(credentials); - - // Build ProtectPDF options by setting a User Password and Encryption Algorithm (used for encrypting the PDF file). - const protectPDF = PDFServicesSdk.ProtectPDF, - options = new protectPDF.options.PasswordProtectOptions.Builder() - .setUserPassword("encryptPassword") - .setEncryptionAlgorithm(PDFServicesSdk.ProtectPDF.options.EncryptionAlgorithm.AES_256) - .build(); - - // Create a new operation instance. - const protectPDFOperation = protectPDF.Operation.createNew(options); - - // Set operation input from a source file. - const input = PDFServicesSdk.FileRef.createFromLocalFile('resources/protectPDFInput.pdf'); - protectPDFOperation.setInput(input); - - // Execute the operation and Save the result to the specified location. - protectPDFOperation.execute(executionContext) - .then(result => result.saveAsFile('output/protectPDFOutput.pdf')) - .catch(err => { - if(err instanceof PDFServicesSdk.Error.ServiceApiError - || err instanceof PDFServicesSdk.Error.ServiceUsageError) { - console.log('Exception encountered while executing operation', err); - } else { - console.log('Exception encountered while executing operation', err); - } - }); + // Initial setup, create credentials instance + const credentials = new ServicePrincipalCredentials({ + clientId: process.env.PDF_SERVICES_CLIENT_ID, + clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET + }); + + // Creates a PDF Services instance + const pdfServices = new PDFServices({ + credentials + }); + + // Creates an asset(s) from source file(s) and upload + readStream = fs.createReadStream("resources/protectPDFInput.pdf") + const inputAsset = await pdfServices.upload({ + readStream, + mimeType: MimeType.PDF + }); + + // Create parameters for the job + const params = new ProtectPDFParams({ + userPassword: "password", + encryptionAlgorithm: EncryptionAlgorithm.AES_256 + }); + + // Submit the job and get the job result + const pollingURL = await pdfServices.submit({ + job + }); + const pdfServicesResponse = await pdfServices.getJobResult({ + pollingURL, + resultType: ProtectPDFResult + }); + // Get content from the resulting asset(s) + const resultAsset = pdfServicesResponse.result.asset; + const streamAsset = await pdfServices.getContent({ + asset: resultAsset + }); + + // Creates an output stream and copy stream asset's content to it + const outputFilePath = createOutputFilePath(); + console.log(`Saving asset at ${outputFilePath}`); + + const outputStream = fs.createWriteStream(outputFilePath); + streamAsset.readStream.pipe(outputStream); } catch (err) { - console.log('Exception encountered while executing operation', err); + if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { + console.log("Exception encountered while executing operation", err); + } else { + console.log("Exception encountered while executing operation", err); + } + } finally { + readStream?.destroy(); + } +})(); + +// Generates a string containing a directory structure and file name for the output file +function createOutputFilePath() { + const filePath = "output/ProtectPDF/"; + const date = new Date(); + const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + + ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); + fs.mkdirSync(filePath, { + recursive: true + }); + return (`${filePath}protect${dateString}.pdf`); } ``` diff --git a/src/pages/apis/pdf-services/split-pdf.md b/src/pages/apis/pdf-services/split-pdf.md index 2d2bc06d1..23894a6dc 100644 --- a/src/pages/apis/pdf-services/split-pdf.md +++ b/src/pages/apis/pdf-services/split-pdf.md @@ -42,50 +42,94 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/splitpdf // Run the sample: // node src/splitpdf/split-pdf-by-number-of-pages.js -const PDFServicesSdk = require('@adobe/pdfservices-node-sdk'); - -try { - // Initial setup, create credentials instance. - const credentials = PDFServicesSdk.Credentials - .servicePrincipalCredentialsBuilder() - .withClientId("PDF_SERVICES_CLIENT_ID") - .withClientSecret("PDF_SERVICES_CLIENT_SECRET") - .build(); - - // Create an ExecutionContext using credentials - const executionContext = PDFServicesSdk.ExecutionContext.create(credentials); - - // Create a new operation instance. - const splitPDFOperation = PDFServicesSdk.SplitPDF.Operation.createNew(), - input = PDFServicesSdk.FileRef.createFromLocalFile( - 'resources/splitPDFInput.pdf', - PDFServicesSdk.SplitPDF.SupportedSourceFormat.pdf - ); - // Set operation input from a source file. - splitPDFOperation.setInput(input); - - // Set the maximum number of pages each of the output files can have. - splitPDFOperation.setPageCount(2); - - // Execute the operation and Save the result to the specified location. - splitPDFOperation.execute(executionContext) - .then(result => { - let saveFilesPromises = []; - for(let i = 0; i < result.length; i++){ - saveFilesPromises.push(result[i].saveAsFile(`output/SplitPDFByNumberOfPagesOutput_${i}.pdf`)); - } - return Promise.all(saveFilesPromises); - }) - .catch(err => { - if(err instanceof PDFServicesSdk.Error.ServiceApiError - || err instanceof PDFServicesSdk.Error.ServiceUsageError) { - console.log('Exception encountered while executing operation', err); - } else { - console.log('Exception encountered while executing operation', err); - } +const { + ServicePrincipalCredentials, + PDFServices, + MimeType, + SplitPDFParams, + SplitPDFJob, + SplitPDFResult, + SDKError, + ServiceUsageError, + ServiceApiError +} = require("@dcloud/pdfservices-node-sdk"); +const fs = require("fs"); + +(async () => { + let readStream; + try { + // Initial setup, create credentials instance + const credentials = new ServicePrincipalCredentials({ + clientId: process.env.PDF_SERVICES_CLIENT_ID, + clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET + }); + + // Creates a PDF Services instance + const pdfServices = new PDFServices({ + credentials + }); + + // Creates an asset(s) from source file(s) and upload + readStream = fs.createReadStream("resources/splitPDFInput.pdf") + const inputAsset = await pdfServices.upload({ + readStream, + mimeType: MimeType.PDF + }); + + // Create parameters for the job + const params = new SplitPDFParams({ + fileCount: 2 }); -} catch (err) { - console.log('Exception encountered while executing operation', err); + + // Creates a new job instance + const job = new SplitPDFJob({ + inputAsset, + params + }); + + const pollingURL = await pdfServices.submit({ + job + }); + const pdfServicesResponse = await pdfServices.getJobResult({ + pollingURL, + resultType: SplitPDFResult + }); + // Get content from the resulting asset(s) + const resultAssets = pdfServicesResponse.result.assets; + let getOutputFilePathForIndex = createOutputFilePath(); + for (let i = 0; i < resultAssets.length; i++) { + const streamAsset = await pdfServices.getContent({ + asset: resultAssets[i] + }); + + // Creates an output stream and copy stream asset's content to it + const _outputFilePath = getOutputFilePathForIndex(i); + console.log(`Saving asset at ${_outputFilePath}`); + + const writeStream = fs.createWriteStream(_outputFilePath); + streamAsset.readStream.pipe(writeStream); + } + } catch (err) { + if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { + console.log("Exception encountered while executing operation", err); + } else { + console.log("Exception encountered while executing operation", err); + } + } finally { + readStream?.destroy(); + } +})(); +// Generates a string containing a directory structure and file name for the output file +function createOutputFilePath() { + const filePath = "output/SplitPDFIntoNumberOfFiles/"; + const date = new Date(); + const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + + ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); + fs.mkdirSync(filePath, { + recursive: true + }); + return (index) => `${filePath}split${dateString}_${index}.pdf`; } ``` diff --git a/src/pages/home/accessbility-auto-tag.md b/src/pages/home/accessbility-auto-tag.md index c05fe22f4..7a4421168 100644 --- a/src/pages/home/accessbility-auto-tag.md +++ b/src/pages/home/accessbility-auto-tag.md @@ -30,41 +30,80 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/autotag' // Run the sample: // node src/autotagpdf/autotag-pdf.js -const PDFServicesSdk = require('@adobe/pdfservices-node-sdk'); - -try { - // Initial setup, create credentials instance. - const credentials = PDFServicesSdk.Credentials - .servicePrincipalCredentialsBuilder() - .withClientId("PDF_SERVICES_CLIENT_ID") - .withClientSecret("PDF_SERVICES_CLIENT_SECRET") - .build(); - - // Create an ExecutionContext using credentials and create a new operation instance. - const executionContext = PDFServicesSdk.ExecutionContext.create(credentials), - autotagPDF = PDFServicesSdk.AutotagPDF, - autotagPDFOperation = autotagPDF.Operation.createNew(); - - // Set operation input from a source file. - const input = PDFServicesSdk.FileRef.createFromLocalFile('autotagPDFInput.pdf'); - autotagPDFOperation.setInput(input); - - // Execute the operation and Save the result to the specified location. - autotagPDFOperation.execute(executionContext) - .then(result => { - result.taggedPDF.saveAsFile('autotagPDFOutput.pdf'); - }) - .catch(err => { - if(err instanceof PDFServicesSdk.Error.ServiceApiError - || err instanceof PDFServicesSdk.Error.ServiceUsageError) { - console.log('Exception encountered while executing operation', err); - } else { - console.log('Exception encountered while executing operation', err); - } +const { + ServicePrincipalCredentials, + PDFServices, + MimeType, + AutotagPDFJob, + AutotagPDFResult, + SDKError, + ServiceUsageError, + ServiceApiError +} = require("@dcloud/pdfservices-node-sdk"); +const fs = require("fs"); + +(async () => { + let readStream; + try { + // Initial setup, create credentials instance + const credentials = new ServicePrincipalCredentials({ + clientId: process.env.PDF_SERVICES_CLIENT_ID, + clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET + }); + + // Creates a PDF Services instance + const pdfServices = new PDFServices({ + credentials + });; + + // Creates an asset(s) from source file(s) and upload + readStream = fs.createReadStream("resources/autotagPDFInput.pdf"); + const inputAsset = await pdfServices.upload({ + readStream, + mimeType: MimeType.PDF + }); + + // Submit the job and get the job result + const pollingURL = await pdfServices.submit({ + job + }); + const pdfServicesResponse = await pdfServices.getJobResult({ + pollingURL, + resultType: AutotagPDFResult + }); + // Get content from the resulting asset(s) + const resultAsset = pdfServicesResponse.result.taggedPDF; + const streamAsset = await pdfServices.getContent({ + asset: resultAsset }); -} catch (err) { - console.log('Exception encountered while executing operation', err); + // Creates an output stream and copy stream asset's content to it + const outputFilePath = createOutputFilePath(); + console.log(`Saving asset at ${outputFilePath}`); + + const outputStream = fs.createWriteStream(outputFilePath); + streamAsset.readStream.pipe(outputStream); + } catch (err) { + if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { + console.log("Exception encountered while executing operation", err); + } else { + console.log("Exception encountered while executing operation", err); + } + } finally { + readStream?.destroy(); + } +})(); +// Generates a string containing a directory structure and file name for the output file +function createOutputFilePath() { + const filePath = "output/AutotagPDF/"; + const date = new Date(); + const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + + ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); + fs.mkdirSync(filePath, { + recursive: true + }); + return (`${filePath}autotag${dateString}.pdf`); } ``` diff --git a/src/pages/home/create-pdf-from-url.md b/src/pages/home/create-pdf-from-url.md index 9152fcfae..d7e1c8c18 100644 --- a/src/pages/home/create-pdf-from-url.md +++ b/src/pages/home/create-pdf-from-url.md @@ -33,37 +33,116 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/createpd // Run the sample: // node src/createpdf/create-pdf-from-docx.js -const PDFservicesSdk = require('@adobe/pdfservices-node-sdk'); - -try { - // Initial setup, create credentials instance. - const credentials = PDFServicesSdk.Credentials - .servicePrincipalCredentialsBuilder() - .withClientId("PDF_SERVICES_CLIENT_ID") - .withClientSecret("PDF_SERVICES_CLIENT_SECRET") - .build(); - - // Create an ExecutionContext using credentials and create a new operation instance. - const executionContext = PDFServicesSdk.ExecutionContext.create(credentials), - createPdfOperation = PDFServicesSdk.CreatePDF.Operation.createNew(); - - // Set operation input from a source file. - const input = PDFServicesSdk.FileRef.createFromLocalFile('resources/createPDFInput.docx'); - createPdfOperation.setInput(input); - - // Execute the operation and Save the result to the specified location. - createPdfOperation.execute(executionContext) - .then(result => result.saveAsFile('output/createPDFFromDOCX.pdf')) - .catch(err => { - if(err instanceof PDFServicesSdk.Error.ServiceApiError - || err instanceof PDFServicesSdk.Error.ServiceUsageError) { - console.log('Exception encountered while executing operation', err); - } else { - console.log('Exception encountered while executing operation', err); - } +const { + ServicePrincipalCredentials, + PDFServices, + MimeType, + ClientConfig, + CreatePDFJob, + CreatePDFResult, + ProxyServerConfig, + ProxyScheme, + UsernamePasswordCredentials, + SDKError, + ServiceUsageError, + ServiceApiError +} = require("@dcloud/pdfservices-node-sdk"); +const fs = require("fs"); + +(async () => { + let readStream; + try { + // Initial setup, create credentials instance + const credentials = new ServicePrincipalCredentials({ + clientId: process.env.PDF_SERVICES_CLIENT_ID, + clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET + }); + + /* + Initial setup, creates proxy server config instance for client config. + Replace the values of PROXY_HOSTNAME with the proxy server hostname. + Replace the username and password with Proxy Server Authentication credentials. + If the scheme of proxy server is not HTTP then, replace ProxyScheme parameter with HTTPS. + If the port for proxy server is diff than the default port for HTTP and HTTPS, then please set the + PROXY_PORT, + else, remove its setter statement. + */ + const proxyServerConfig = new ProxyServerConfig({ + host: "PROXY_HOSTNAME", + port: 443, + scheme: ProxyScheme.HTTP, + credentials: new UsernamePasswordCredentials({ + username: "USERNAME", + password: "PASSWORD" + }) + }); + + // Creates client config instance + const clientConfig = new ClientConfig({ + proxyServerConfig + }); + + // Creates a PDF Services instance + const pdfServices = new PDFServices({ + credentials, + clientConfig + }); + + // Creates an asset(s) from source file(s) and upload + readStream = fs.createReadStream("resources/createPDFInput.docx") + const inputAsset = await pdfServices.upload({ + readStream, + mimeType: MimeType.DOCX + }); + + // Creates a new job instance + const job = new CreatePDFJob({ + inputAsset + }); + + // Submit the job and get the job result + const pollingURL = await pdfServices.submit({ + job + }); + const pdfServicesResponse = await pdfServices.getJobResult({ + pollingURL, + resultType: CreatePDFResult + }); + + // Get content from the resulting asset(s) + const resultAsset = pdfServicesResponse.result.asset; + const streamAsset = await pdfServices.getContent({ + asset: resultAsset + }); + + // Creates a write stream and copy stream asset's content to it + const outputFilePath = createOutputFilePath(); + console.log(`Saving asset at ${outputFilePath}`); + + const writeStream = fs.createWriteStream(outputFilePath); + streamAsset.readStream.pipe(writeStream); + } catch (err) { + if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { + console.log("Exception encountered while executing operation", err); + } else { + console.log("Exception encountered while executing operation", err); + } + } finally { + readStream?.destroy(); + } +})(); + +// Generates a string containing a directory structure and file name for the output file +function createOutputFilePath() { + const filePath = "output/CreatePDFWithAuthenticatedProxyServer/"; + const date = new Date(); + const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + + ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); + fs.mkdirSync(filePath, { + recursive: true }); -} catch (err) { - console.log('Exception encountered while executing operation', err); + return (`${filePath}create${dateString}.pdf`); } ``` diff --git a/src/pages/home/dynamic-pdf-document-generation.md b/src/pages/home/dynamic-pdf-document-generation.md index 2af0de101..e3cc07026 100644 --- a/src/pages/home/dynamic-pdf-document-generation.md +++ b/src/pages/home/dynamic-pdf-document-generation.md @@ -58,49 +58,118 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/document // Run the sample: // node src/documentmerge/merge-document-to-pdf.js -const PDFServicesSdk = require('@adobe/pdfservices-node-sdk'); - -try { - // Initial setup, create credentials instance. - const credentials = PDFServicesSdk.Credentials - .servicePrincipalCredentialsBuilder() - .withClientId("PDF_SERVICES_CLIENT_ID") - .withClientSecret("PDF_SERVICES_CLIENT_SECRET") - .build(); - - // Setup input data for the document merge process. - const jsonString = "{\"customerName\": \"Kane Miller\", \"customerVisits\": 100}", - jsonDataForMerge = JSON.parse(jsonString); - - // Create an ExecutionContext using credentials. - const executionContext = PDFServicesSdk.ExecutionContext.create(credentials); - - // Create a new DocumentMerge options instance. - const documentMerge = PDFServicesSdk.DocumentMerge, - documentMergeOptions = documentMerge.options, - options = new documentMergeOptions.DocumentMergeOptions(jsonDataForMerge, documentMergeOptions.OutputFormat.PDF); - - // Create a new operation instance using the options instance. - const documentMergeOperation = documentMerge.Operation.createNew(options); - - // Set operation input document template from a source file. - const input = PDFServicesSdk.FileRef.createFromLocalFile('resources/documentMergeTemplate.docx'); - documentMergeOperation.setInput(input); - - // Execute the operation and Save the result to the specified location. - documentMergeOperation.execute(executionContext) - .then(result => result.saveAsFile('output/documentMergeOutput.pdf')) - .catch(err => { - if(err instanceof PDFServicesSdk.Error.ServiceApiError - || err instanceof PDFServicesSdk.Error.ServiceUsageError) { - console.log('Exception encountered while executing operation', err); - } else { - console.log('Exception encountered while executing operation', err); - } +const { + ServicePrincipalCredentials, + PDFServices, + MimeType, + DocumentMergeParams, + OutputFormat, + DocumentMergeJob, + DocumentMergeResult, + SDKError, + ServiceUsageError, + ServiceApiError +} = require("@dcloud/pdfservices-node-sdk"); +const fs = require("fs"); + +(async () => { + let readStream; + try { + // Initial setup, create credentials instance + const credentials = new ServicePrincipalCredentials({ + clientId: process.env.PDF_SERVICES_CLIENT_ID, + clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET }); -} -catch (err) { - console.log('Exception encountered while executing operation', err); + + // Creates a PDF Services instance + const pdfServices = new PDFServices({ + credentials + }); + + // Creates an asset(s) from source file(s) and upload + readStream = fs.createReadStream("resources/documentMergeTemplate.docx"); + const inputAsset = await pdfServices.upload({ + readStream, + mimeType: MimeType.DOCX + }); + + // Setup input data for the document merge process + const jsonDataForMerge = { + customerName: 'Kane Miller', + customerVisits: 100, + itemsBought: [{ + description: 'Sprays', + quantity: 50, + amount: 100 + }, + { + description: 'Chemicals', + quantity: 100, + amount: 200 + } + ], + totalAmount: 300, + previousBalance: 50, + lastThreeBillings: [ + 100, + 200, + 300 + ], + photograph: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAZuElEQVR4nL1de7gcRZX/neqeme65l7zuzRsijxgwBJJAghBBXQ0PkeCCD15+i+7qqkvg81v8dkX9Y1fYBZUVBVzQRR4rEXCVh8AniisQFJIQlIsIeQAxkoQ8bp7ce+fR3XX2j+ruqZ7q7um5N+z55ruZ6T516lTVr845daq6Q+sO6Z0B8hkABBRJAAKEiNR1otYVnYi178QxJzOn8kecLR7mlmROryTklIkrFPNLg1+ivXbFybJVu8/t5fRSUteEBTPb2c0ZDYWNBwBktDrilIozj1dJyxqk0emm6pJSdlbRoNTOEgCYJSJFVf8LDSl6A3QsEAtEnZWHq0hPzugIHZVBAqEC8fgXwFQCp7KFZR01IeI4E1OhTErvrM6UNeaqmiIDZnLmT9uwFLe6KUurbvFSnBKdpY+SoBZGLLTbi5DHwFpxPbO6SRo8um3qgCYTL6GFAoAgi8fEFIvWFQ2nhZAlC9iOIrgwKV+m5M7WLwtNSQuVz1OUbAlIlkwCSb8W2iklVEOZ8pIEibQR1kkYV1L41TBoJRJeTLOYJmWhKQKMEt/ZQoXSNEyZnlTVYkc6K6U7T6MQZTiYfipCU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XDTDLQuGFGvrmJUxIi5OiBFc4GmornWp732Fmn+S2mr/fXNhmXIzHj9SOoz0nqrNdsR3k10QTo6EtI6IKVzpGGixvRZyu6YMZs0G58hv4gOdqCOUeVmKLJu5aMjyQmkZtwzykYNaM/B61EPwsM0LfkpzU61km3NNbpSmpnV1u5OcsOiW3tRnAINZVlWptt3g+fbnYjHeJNI/qTOUKF1pjTmTeQJjAKmUkXSMLpvip564CgxkYzytEgnRg23ydEpo3b1RGKW9YF+at9cxmmTV2h+vEOcFRiq6LiI1EqnDv8DFMX/p0qKgIStifo5R1xKkEmJjE07Zxj+dR7nIFoiIDwHz2TaDjO/Eyqh25HE/w/Y7omSZoG071FjIqYieEnAItdnhRdSsKOxal2Q3Itsr0WnsZ3PaqEjxRPpJA2LUDxvNUrOwtjRqcMpGmYwWBrQynr5UiKMyEdHRjGKDs20sURrfeTZmkQB9fSyD0CGW7MGSDKsT0vvdi/ZrrTuSTORlZPSb1kSbSlQ3IvlPMAYqpv9liwTOwHZ6IRrRbr10aVJQQCsDAG6tv8HcAoVaSJluIMAAAAASUVORK5CYII=' + }; + + // Create parameters for the job + const params = new DocumentMergeParams({ + jsonDataForMerge, + outputFormat: OutputFormat.DOCX + }); + + // Creates a new job instance + const job = new DocumentMergeJob({ + inputAsset, + params + }); + + // Submit the job and get the job result + const pollingURL = await pdfServices.submit({ + job + }); + const pdfServicesResponse = await pdfServices.getJobResult({ + pollingURL, + resultType: DocumentMergeResult + }); + // Get content from the resulting asset(s) + const resultAsset = pdfServicesResponse.result.asset; + const streamAsset = await pdfServices.getContent({ + asset: resultAsset + }); + + // Creates a write stream and copy stream asset's content to it + const outputFilePath = createOutputFilePath(); + console.log(`Saving asset at ${outputFilePath}`); + const writeStream = fs.createWriteStream(outputFilePath); + streamAsset.readStream.pipe(writeStream); + } catch (err) { + if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { + console.log("Exception encountered while executing operation", err); + } else { + console.log("Exception encountered while executing operation", err); + } + } finally { + readStream?.destroy(); + } +})(); +// Generates a string containing a directory structure and file name for the output file +function createOutputFilePath() { + const filePath = "output/MergeDocumentToDOCX/"; + const date = new Date(); + const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + + ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); + fs.mkdirSync(filePath, { + recursive: true + }); + return (`${filePath}merge${dateString}.docx`); } ``` diff --git a/src/pages/home/e-seal.md b/src/pages/home/e-seal.md index b9f078d41..b00079212 100644 --- a/src/pages/home/e-seal.md +++ b/src/pages/home/e-seal.md @@ -64,92 +64,163 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/electron // Run the sample: // node src/electronicseal/electronic-seal.js -try { - // Initial setup, create credentials instance. - const credentials = PDFServicesSdk.Credentials - .servicePrincipalCredentialsBuilder() - .withClientId("PDF_SERVICES_CLIENT_ID") - .withClientSecret("PDF_SERVICES_CLIENT_SECRET") - .build(); - - // Create an ExecutionContext using credentials - const executionContext = PDFServicesSdk.ExecutionContext.create(credentials); - - const pdfElectronicSeal = PDFServicesSdk.PDFElectronicSeal, - options = pdfElectronicSeal.options; - - //Get the input document to perform the sealing operation - const sourceFile = PDFServicesSdk.FileRef.createFromLocalFile('resources/sampleInvoice.pdf'), - - //Get the background seal image for signature , if required. - sealImageFile = PDFServicesSdk.FileRef.createFromLocalFile('resources/sampleSealImage.png'); - - // Set the Seal Field Name to be created in input PDF document. - sealFieldName = "Signature1"; - - // Set the page number in input document for applying seal. - sealPageNumber = 1; - - // Set if seal should be visible or invisible. - sealVisible = true; - - //Create FieldLocation instance and set the coordinates for applying signature - fieldLocation = new options.FieldLocation(150,250,350,200); - - //Create FieldOptions instance with required details. - fieldOptions = new options.FieldOptions.Builder(sealFieldName) - .setFieldLocation(fieldLocation) - .setPageNumber(sealPageNumber) - .setVisible(sealVisible) - .build(); - - //Set the name of TSP Provider being used. - providerName = ""; - - //Set the access token to be used to access TSP provider hosted APIs. - accessToken = ""; - - //Set the credential ID. - credentialID = ""; - - //Set the PIN generated while creating credentials. - pin = ""; - - //Create CSCAuthContext instance using access token and token type. - cscAuthContext = new options.CSCAuthContext(accessToken, "Bearer"); - - //Create CertificateCredentials instance with required certificate details. - certificateCredentials = options.CertificateCredentials.cscCredentialBuilder() - .withProviderName(providerName) - .withCredentialID(credentialID) - .withPin(pin) - .withCSCAuthContext(cscAuthContext) - .build(); - - //Create SealOptions instance with sealing parameters. - sealOptions = new options.SealOptions.Builder(certificateCredentials, fieldOptions) - .build() - - //Create the PDFElectronicSealOperation instance using the SealOptions instance - const pdfElectronicSealOperation = pdfElectronicSeal.Operation.createNew(sealOptions); - - //Set the input source file for PDFElectronicSealOperation instance - pdfElectronicSealOperation.setInput(sourceFile); - - //Set the optional input seal image for PDFElectronicSealOperation instance - pdfElectronicSealOperation.setSealImage(sealImageFile); - - // Execute the operation and Save the result to the specified location. - pdfElectronicSealOperation.execute(executionContext) - .then(result => result.saveAsFile("output/ElectronicSeal/sealedOutput.pdf")) - .catch(err => { - if(err instanceof PDFServicesSdk.Error.ServiceApiError - || err instanceof PDFServicesSdk.Error.ServiceUsageError) { - console.log('Exception encountered while executing operation', err); - } else { - console.log('Exception encountered while executing operation', err); - } +const { + ServicePrincipalCredentials, + PDFServices, + MimeType, + DocumentLevelPermission, + FieldLocation, + FieldOptions, + CSCAuthContext, + CSCCredential, + PDFElectronicSealParams, + PDFElectronicSealJob, + PDFElectronicSealResult, + SDKError, + ServiceUsageError, + ServiceApiError +} = require("@dcloud/pdfservices-node-sdk"); +const fs = require("fs"); + +(async () => { + let sourceFileReadStream; + let sealImageReadStream; + try { + // Initial setup, create credentials instance + const credentials = new ServicePrincipalCredentials({ + clientId: process.env.PDF_SERVICES_CLIENT_ID, + clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET + }); + // Creates a PDF Services instance + const pdfServices = new PDFServices({ + credentials + }); + + // Creates an asset(s) from source file(s) and upload + sourceFileReadStream = fs.createReadStream("resources/sampleInvoice.pdf") + sealImageReadStream = fs.createReadStream("resources/sampleSealImage.png"); + const [sourceFileAsset, sealImageAsset] = await pdfServices.uploadAssets({ + streamAssets: [{ + readStream: sourceFileReadStream, + mimeType: MimeType.PDF + }, { + readStream: sealImageReadStream, + mimeType: MimeType.PNG + }] + }); + + // Set the document level permission to be applied for output document + const documentLevelPermission = DocumentLevelPermission.FORM_FILLING; + + // Set the Seal Field Name to be created in input PDF document + const sealFieldName = "Signature1"; + + // Set the page number in input document for applying seal + const sealPageNumber = 1; + + // Set if seal should be visible or invisible + const sealVisible = true; + + // Create FieldLocation instance and set the coordinates for applying signature + const fieldLocation = new FieldLocation({ + left: 150, + top: 250, + right: 350, + bottom: 200 + }); + + // Create FieldOptions instance with required details + const sealFieldOptions = new FieldOptions({ + visible: sealVisible, + location: fieldLocation, + fieldName: sealFieldName, + pageNumber: sealPageNumber, + }); + + // Set the name of TSP Provider being used + const providerName = ""; + + // Set the access token to be used to access TSP provider hosted APIs + const accessToken = ""; + // Set the credential ID + const credentialId = ""; + + // Set the PIN generated while creating credentials + const pin = ""; + + // Create CSCAuthContext instance using access token and token type + const authorizationContext = new CSCAuthContext({ + accessToken, + tokenType: "Bearer" + }); + + // Create CertificateCredentials instance with required certificate details + const certificateCredentials = new CSCCredential({ + providerName, + credentialId, + pin, + authorizationContext, + }); + + // Create parameters for the job + const params = new PDFElectronicSealParams({ + certificateCredentials, + sealFieldOptions, + documentLevelPermission, + }); + + // Creates a new job instance + const job = new PDFElectronicSealJob({ + inputAsset: sourceFileAsset, + sealImageAsset, + params, + }); + + // Submit the job and get the job result + const pollingURL = await pdfServices.submit({ + job + }); + const pdfServicesResponse = await pdfServices.getJobResult({ + pollingURL, + resultType: PDFElectronicSealResult + }); + + // Get content from the resulting asset(s) + const resultAsset = pdfServicesResponse.result.asset; + const streamAsset = await pdfServices.getContent({ + asset: resultAsset }); + + // Creates a write stream and copy stream asset's content to it + const outputFilePath = createOutputFilePath(); + console.log(`Saving asset at ${outputFilePath}`); + + const writeStream = fs.createWriteStream(outputFilePath); + streamAsset.readStream.pipe(writeStream); + } catch (err) { + if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { + console.log("Exception encountered while executing operation", err); + } else { + console.log("Exception encountered while executing operation", err); + } + } finally { + sourceFileReadStream?.destroy(); + sealImageReadStream?.destroy(); + } +})(); + +// Generates a string containing a directory structure and file name for the output file +function createOutputFilePath() { + const filePath = "output/ElectronicSeal/"; + const date = new Date(); + const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + + ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); + fs.mkdirSync(filePath, { + recursive: true + }); + return (`${filePath}seal${dateString}.pdf`); +} ``` #### .Net diff --git a/src/pages/home/pdf-content-structure.md b/src/pages/home/pdf-content-structure.md index f3b5f49a7..b521679bc 100644 --- a/src/pages/home/pdf-content-structure.md +++ b/src/pages/home/pdf-content-structure.md @@ -36,47 +36,93 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/extractp // Run the sample: // node src/extractpdf/extract-text-info-from-pdf.js -const PDFServicesSdk = require('@adobe/pdfservices-node-sdk'); -try { - // Initial setup, create credentials instance. - const credentials = PDFServicesSdk.Credentials - .servicePrincipalCredentialsBuilder() - .withClientId("PDF_SERVICES_CLIENT_ID") - .withClientSecret("PDF_SERVICES_CLIENT_SECRET") - .build(); - - // Create an ExecutionContext using credentials - const executionContext = PDFServicesSdk.ExecutionContext.create(credentials); - - // Build extractPDF options - const options = new PDFServicesSdk.ExtractPDF.options.ExtractPdfOptions.Builder() - .addElementsToExtract(PDFServicesSdk.ExtractPDF.options.ExtractElementType.TEXT).build(); - - // Create a new operation instance. - const extractPDFOperation = PDFServicesSdk.ExtractPDF.Operation.createNew(), - input = PDFServicesSdk.FileRef.createFromLocalFile( - 'resources/extractPDFInput.pdf', - PDFServicesSdk.ExtractPDF.SupportedSourceFormat.pdf - ); - - // Set operation input from a source file. - extractPDFOperation.setInput(input); - - // Set options - extractPDFOperation.setOptions(options); - - extractPDFOperation.execute(executionContext) - .then(result => result.saveAsFile('output/ExtractTextInfoFromPDF.zip')) - .catch(err => { - if(err instanceof PDFServicesSdk.Error.ServiceApiError - || err instanceof PDFServicesSdk.Error.ServiceUsageError) { - console.log('Exception encountered while executing operation', err); - } else { - console.log('Exception encountered while executing operation', err); - } +const { + ServicePrincipalCredentials, + PDFServices, + MimeType, + ExtractPDFParams, + ExtractElementType, + ExtractPDFJob, + ExtractPDFResult, + SDKError, + ServiceUsageError, + ServiceApiError +} = require("@dcloud/pdfservices-node-sdk"); +const fs = require("fs"); + +(async () => { + let readStream; + try { + // Initial setup, create credentials instance + const credentials = new ServicePrincipalCredentials({ + clientId: process.env.PDF_SERVICES_CLIENT_ID, + clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET + }); + + // Creates a PDF Services instance + const pdfServices = new PDFServices({ + credentials + }); + + // Creates an asset(s) from source file(s) and upload + readStream = fs.createReadStream("resources/extractPDFInput.pdf"); + const inputAsset = await pdfServices.upload({ + readStream, + mimeType: MimeType.PDF + }); + + // Create parameters for the job + const params = new ExtractPDFParams({ + elementsToExtract: [ExtractElementType.TEXT] + }); + + // Creates a new job instance + const job = new ExtractPDFJob({ + inputAsset, + params }); -} catch (err) { - console.log('Exception encountered while executing operation', err); + + // Submit the job and get the job result + const pollingURL = await pdfServices.submit({ + job + }); + const pdfServicesResponse = await pdfServices.getJobResult({ + pollingURL, + resultType: ExtractPDFResult + }); + + // Get content from the resulting asset(s) + const resultAsset = pdfServicesResponse.result.resource; + const streamAsset = await pdfServices.getContent({ + asset: resultAsset + }); + + // Creates a write stream and copy stream asset's content to it + const outputFilePath = createOutputFilePath(); + console.log(`Saving asset at ${outputFilePath}`); + const writeStream = fs.createWriteStream(outputFilePath); + streamAsset.readStream.pipe(writeStream); + } catch (err) { + if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { + console.log("Exception encountered while executing operation", err); + } else { + console.log("Exception encountered while executing operation", err); + } + } finally { + readStream?.destroy(); + } +})(); +// Generates a string containing a directory structure and file name for the output file +function createOutputFilePath() { + const filePath = "output/ExtractTextInfoFromPDF/"; + const date = new Date(); + const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + + ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); + fs.mkdirSync(filePath, { + recursive: true + }); + return (`${filePath}extract${dateString}.zip`); } ``` From 9398ae7197cc677672f0a2c61e1f6458bd9bba6f Mon Sep 17 00:00:00 2001 From: Vignesh Date: Thu, 21 Mar 2024 15:33:32 +0530 Subject: [PATCH 2/5] --Updated and formatted node samples --- .../accessibility-auto-tag-api.md | 36 ++++++--------- src/pages/apis/pdf-services/combine-pdf.md | 18 ++++++++ src/pages/apis/pdf-services/compress-pdf.md | 6 +++ src/pages/apis/pdf-services/convert-pdf.md | 7 ++- src/pages/apis/pdf-services/create-pdf.md | 7 +++ .../apis/pdf-services/delete-pdf-pages.md | 7 ++- .../apis/pdf-services/document-generation.md | 9 ++++ src/pages/apis/pdf-services/e-seal.md | 32 ++++++------- .../apis/pdf-services/extract-pdf-content.md | 7 ++- .../apis/pdf-services/get-pdf-properties.md | 7 ++- src/pages/apis/pdf-services/html-to-pdf.md | 25 ++++++++-- .../apis/pdf-services/insert-pdf-pages.md | 6 +++ src/pages/apis/pdf-services/linearize-pdf.md | 7 +++ src/pages/apis/pdf-services/ocr-pdf.md | 5 ++ .../apis/pdf-services/remove-pdf-password.md | 7 ++- .../apis/pdf-services/reorder-pdf-pages.md | 6 +++ .../apis/pdf-services/replace-pdf-pages.md | 6 +++ .../apis/pdf-services/rotate-pdf-pages.md | 14 +++++- src/pages/apis/pdf-services/secure-pdf.md | 13 ++++++ src/pages/apis/pdf-services/split-pdf.md | 13 +++++- src/pages/home/accessbility-auto-tag.md | 14 +++++- src/pages/home/create-pdf-from-url.md | 46 +++++-------------- .../home/dynamic-pdf-document-generation.md | 45 +++++++----------- src/pages/home/e-seal.md | 10 ++++ src/pages/home/pdf-content-structure.md | 7 +++ 25 files changed, 241 insertions(+), 119 deletions(-) diff --git a/src/pages/apis/pdf-services/accessibility-auto-tag-api.md b/src/pages/apis/pdf-services/accessibility-auto-tag-api.md index 05b1db768..1fa40b1ad 100644 --- a/src/pages/apis/pdf-services/accessibility-auto-tag-api.md +++ b/src/pages/apis/pdf-services/accessibility-auto-tag-api.md @@ -40,7 +40,6 @@ const { ServicePrincipalCredentials, PDFServices, MimeType, - AutotagPDFParams, AutotagPDFJob, AutotagPDFResult, SDKError, @@ -49,6 +48,11 @@ const { } = require("@dcloud/pdfservices-node-sdk"); const fs = require("fs"); +/** + * This sample illustrates how to generate a tagged PDF. + *

+ * Refer to README.md for instructions on how to run the samples. + */ (async () => { let readStream; try { @@ -70,16 +74,9 @@ const fs = require("fs"); mimeType: MimeType.PDF }); - // Create parameters for the job - const params = new AutotagPDFParams({ - generateReport: true, - shiftHeadings: true - }); - // Creates a new job instance const job = new AutotagPDFJob({ - inputAsset, - params + inputAsset }); // Submit the job and get the job result @@ -93,24 +90,16 @@ const fs = require("fs"); // Get content from the resulting asset(s) const resultAsset = pdfServicesResponse.result.taggedPDF; - const resultAssetReport = pdfServicesResponse.result.report; const streamAsset = await pdfServices.getContent({ asset: resultAsset }); - const streamAssetReport = await pdfServices.getContent({ - asset: resultAssetReport - }); // Creates an output stream and copy stream asset's content to it - const outputFilePath = createOutputFilePath(".pdf"); - const outputFilePathReport = createOutputFilePath(".xlsx"); + const outputFilePath = createOutputFilePath(); console.log(`Saving asset at ${outputFilePath}`); - console.log(`Saving asset at ${outputFilePathReport}`); - let writeStream = fs.createWriteStream(outputFilePath); - streamAsset.readStream.pipe(writeStream); - writeStream = fs.createWriteStream(outputFilePathReport); - streamAssetReport.readStream.pipe(writeStream); + const outputStream = fs.createWriteStream(outputFilePath); + streamAsset.readStream.pipe(outputStream); } catch (err) { if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { console.log("Exception encountered while executing operation", err); @@ -121,9 +110,10 @@ const fs = require("fs"); readStream?.destroy(); } })(); + // Generates a string containing a directory structure and file name for the output file -function createOutputFilePath(extension) { - const filePath = "output/AutotagPDFWithOptions/"; +function createOutputFilePath() { + const filePath = "output/AutotagPDF/"; const date = new Date(); const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + @@ -131,7 +121,7 @@ function createOutputFilePath(extension) { fs.mkdirSync(filePath, { recursive: true }); - return (`${filePath}autotag${dateString}${extension}`); + return (`${filePath}autotag${dateString}.pdf`); } ``` diff --git a/src/pages/apis/pdf-services/combine-pdf.md b/src/pages/apis/pdf-services/combine-pdf.md index 306973c55..f0d9ba27f 100644 --- a/src/pages/apis/pdf-services/combine-pdf.md +++ b/src/pages/apis/pdf-services/combine-pdf.md @@ -59,6 +59,13 @@ const { } = require("@dcloud/pdfservices-node-sdk"); const fs = require("fs"); +/** + * This sample illustrates how to combine multiple PDF files into a single PDF file. + *

+ * Note that the SDK supports combining upto 20 files in one operation. + *

+ * Refer to README.md for instructions on how to run the samples. + */ (async () => { let readStream1; let readStream2; @@ -69,6 +76,11 @@ const fs = require("fs"); clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET }); + // Creates a PDF Services instance + const pdfServices = new PDFServices({ + credentials + }); + // Creates an asset(s) from source file(s) and upload readStream1 = fs.createReadStream("resources/combineFilesInput1.pdf"); readStream2 = fs.createReadStream("resources/combineFilesInput2.pdf"); @@ -86,6 +98,12 @@ const fs = require("fs"); const params = new CombinePDFParams() .addAsset(inputAsset1) .addAsset(inputAsset2); + + // Create a new job instance + const job = new CombinePDFJob({ + params + }); + // Submit the job and get the job result const pollingURL = await pdfServices.submit({ job diff --git a/src/pages/apis/pdf-services/compress-pdf.md b/src/pages/apis/pdf-services/compress-pdf.md index c9053cc4c..1e0ab4f39 100644 --- a/src/pages/apis/pdf-services/compress-pdf.md +++ b/src/pages/apis/pdf-services/compress-pdf.md @@ -53,6 +53,11 @@ const { } = require("@dcloud/pdfservices-node-sdk"); const fs = require("fs"); +/** + * This sample illustrates how to compress PDF by reducing the size of the PDF file. + *

+ * Refer to README.md for instructions on how to run the samples. + */ (async () => { let readStream; try { @@ -61,6 +66,7 @@ const fs = require("fs"); clientId: process.env.PDF_SERVICES_CLIENT_ID, clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET }); + // Creates a PDF Services instance const pdfServices = new PDFServices({ credentials diff --git a/src/pages/apis/pdf-services/convert-pdf.md b/src/pages/apis/pdf-services/convert-pdf.md index 6899531c0..79061480f 100644 --- a/src/pages/apis/pdf-services/convert-pdf.md +++ b/src/pages/apis/pdf-services/convert-pdf.md @@ -56,6 +56,11 @@ const { } = require("@dcloud/pdfservices-node-sdk"); const fs = require("fs"); +/** + * This sample illustrates how to export a PDF file to a Word (DOCX) file + *

+ * Refer to README.md for instructions on how to run the samples. + */ (async () => { let readStream; try { @@ -75,7 +80,7 @@ const fs = require("fs"); const inputAsset = await pdfServices.upload({ readStream, mimeType: MimeType.PDF - }) + }); // Create parameters for the job const params = new ExportPDFParams({ diff --git a/src/pages/apis/pdf-services/create-pdf.md b/src/pages/apis/pdf-services/create-pdf.md index 305f5bcce..7b461e497 100644 --- a/src/pages/apis/pdf-services/create-pdf.md +++ b/src/pages/apis/pdf-services/create-pdf.md @@ -52,6 +52,11 @@ const { } = require("@dcloud/pdfservices-node-sdk"); const fs = require("fs"); +/** + * This sample illustrates how to create a PDF file from a DOCX file. + *

+ * Refer to README.md for instructions on how to run the samples. + */ (async () => { let readStream; try { @@ -60,6 +65,7 @@ const fs = require("fs"); clientId: process.env.PDF_SERVICES_CLIENT_ID, clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET }); + // Creates a PDF Services instance const pdfServices = new PDFServices({ credentials @@ -108,6 +114,7 @@ const fs = require("fs"); readStream?.destroy(); } })(); + // Generates a string containing a directory structure and file name for the output file function createOutputFilePath() { const filePath = "output/CreatePDFFromDOCX/"; diff --git a/src/pages/apis/pdf-services/delete-pdf-pages.md b/src/pages/apis/pdf-services/delete-pdf-pages.md index 392ad6c97..eb1d94e2e 100644 --- a/src/pages/apis/pdf-services/delete-pdf-pages.md +++ b/src/pages/apis/pdf-services/delete-pdf-pages.md @@ -49,7 +49,7 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/pagemani ```js // Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample // Run the sample: -// node src/replacepages/replace-pdf-pages.js +// node src/deletepages/delete-pdf-pages.js const { ServicePrincipalCredentials, @@ -65,6 +65,11 @@ const { } = require("@dcloud/pdfservices-node-sdk"); const fs = require("fs"); +/** + * This sample illustrates how to delete pages in a PDF file + *

+ * Refer to README.md for instructions on how to run the samples. + */ (async () => { let readStream; try { diff --git a/src/pages/apis/pdf-services/document-generation.md b/src/pages/apis/pdf-services/document-generation.md index b45bb0f26..38bc1fda1 100644 --- a/src/pages/apis/pdf-services/document-generation.md +++ b/src/pages/apis/pdf-services/document-generation.md @@ -83,6 +83,14 @@ const { } = require("@dcloud/pdfservices-node-sdk"); const fs = require("fs"); +/** + * This sample illustrates how to merge the Word based document template with the input JSON data to generate + * the output document in the PDF format. + *

+ * To know more about document generation and document templates, please see the documentation + *

+ * Refer to README.md for instructions on how to run the samples. + */ (async () => { let readStream; try { @@ -127,6 +135,7 @@ const fs = require("fs"); pollingURL, resultType: DocumentMergeResult }); + // Get content from the resulting asset(s) const resultAsset = pdfServicesResponse.result.asset; const streamAsset = await pdfServices.getContent({ diff --git a/src/pages/apis/pdf-services/e-seal.md b/src/pages/apis/pdf-services/e-seal.md index 5f7650df1..85c6d5175 100644 --- a/src/pages/apis/pdf-services/e-seal.md +++ b/src/pages/apis/pdf-services/e-seal.md @@ -74,6 +74,7 @@ const { ServicePrincipalCredentials, PDFServices, MimeType, + DocumentLevelPermission, FieldLocation, FieldOptions, CSCAuthContext, @@ -81,17 +82,21 @@ const { PDFElectronicSealParams, PDFElectronicSealJob, PDFElectronicSealResult, - AppearanceOptions, - AppearanceItem, SDKError, ServiceUsageError, - ServiceApiError, - DocumentLevelPermission + ServiceApiError } = require("@dcloud/pdfservices-node-sdk"); const fs = require("fs"); +/** + * This sample illustrates how to apply electronic seal over the PDF document using default appearance options. + * + *

+ * To know more about PDF Electronic Seal, please see the <documentation. + *

+ * Refer to README.md for instructions on how to run the samples. + */ (async () => { - let sourceFileReadStream; let sealImageReadStream; try { @@ -122,17 +127,6 @@ const fs = require("fs"); // Set the document level permission to be applied for output document const documentLevelPermission = DocumentLevelPermission.FORM_FILLING; - // Create AppearanceOptions and add the required signature appearance items - const sealAppearanceOptions = new AppearanceOptions({ - items: [ - AppearanceItem.DATE, - AppearanceItem.SEAL_IMAGE, - AppearanceItem.NAME, - AppearanceItem.LABELS, - AppearanceItem.DISTINGUISHED_NAME - ] - }); - // Set the Seal Field Name to be created in input PDF document const sealFieldName = "Signature1"; @@ -163,6 +157,7 @@ const fs = require("fs"); // Set the access token to be used to access TSP provider hosted APIs const accessToken = ""; + // Set the credential ID const credentialId = ""; @@ -185,10 +180,9 @@ const fs = require("fs"); // Create parameters for the job const params = new PDFElectronicSealParams({ - documentLevelPermission, certificateCredentials, sealFieldOptions, - sealAppearanceOptions + documentLevelPermission, }); // Creates a new job instance @@ -233,7 +227,7 @@ const fs = require("fs"); // Generates a string containing a directory structure and file name for the output file function createOutputFilePath() { - const filePath = "output/ElectronicSealWithAppearanceOptions/"; + const filePath = "output/ElectronicSeal/"; const date = new Date(); const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + diff --git a/src/pages/apis/pdf-services/extract-pdf-content.md b/src/pages/apis/pdf-services/extract-pdf-content.md index 4b34cc92b..69c6d4e29 100644 --- a/src/pages/apis/pdf-services/extract-pdf-content.md +++ b/src/pages/apis/pdf-services/extract-pdf-content.md @@ -56,6 +56,11 @@ const { } = require("@dcloud/pdfservices-node-sdk"); const fs = require("fs"); +/** + * This sample illustrates how to extract Text Information from PDF. + *

+ * Refer to README.md for instructions on how to run the samples & understand output zip file + */ (async () => { let readStream; try { @@ -65,7 +70,6 @@ const fs = require("fs"); clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET }); - // Creates a PDF Services instance const pdfServices = new PDFServices({ credentials @@ -107,6 +111,7 @@ const fs = require("fs"); // Creates a write stream and copy stream asset's content to it const outputFilePath = createOutputFilePath(); console.log(`Saving asset at ${outputFilePath}`); + const writeStream = fs.createWriteStream(outputFilePath); streamAsset.readStream.pipe(writeStream); } catch (err) { diff --git a/src/pages/apis/pdf-services/get-pdf-properties.md b/src/pages/apis/pdf-services/get-pdf-properties.md index 6af04cfec..a463e39f0 100644 --- a/src/pages/apis/pdf-services/get-pdf-properties.md +++ b/src/pages/apis/pdf-services/get-pdf-properties.md @@ -40,7 +40,7 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/pdfprope ```js // Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample // Run the sample: -// node src/exportpdf/get-pdf-properties.js +// node src/pdfproperties/get-pdf-properties.js const { ServicePrincipalCredentials, @@ -55,6 +55,11 @@ const { } = require("@dcloud/pdfservices-node-sdk"); const fs = require("fs"); +/** + * This sample illustrates how to retrieve properties of an input PDF file + * + * Refer to README.md for instructions on how to run the samples. + */ (async () => { let readStream; try { diff --git a/src/pages/apis/pdf-services/html-to-pdf.md b/src/pages/apis/pdf-services/html-to-pdf.md index 2d08b9e35..3992b5e85 100644 --- a/src/pages/apis/pdf-services/html-to-pdf.md +++ b/src/pages/apis/pdf-services/html-to-pdf.md @@ -43,11 +43,12 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/htmltopd ```js // Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample // Run the sample: -// node src/createpdf/create-pdf-from-static-html.js +// node src/htmltopdf/static-html-to-pdf.js const { ServicePrincipalCredentials, PDFServices, + MimeType, PageLayout, HTMLToPDFParams, HTMLToPDFResult, @@ -58,7 +59,14 @@ const { } = require("@dcloud/pdfservices-node-sdk"); const fs = require("fs"); +/** + * This sample illustrates how to convert an HTML file to PDF. The HTML file and its associated dependencies must be + * in a single ZIP file + *

+ * Refer to README.md for instructions on how to run the samples. + */ (async () => { + let readStream; try { // Initial setup, create credentials instance const credentials = new ServicePrincipalCredentials({ @@ -71,14 +79,19 @@ const fs = require("fs"); credentials }); - const inputURL = ""; + // Creates an asset(s) from source file(s) and upload + readStream = fs.createReadStream("resources/createPDFFromStaticHtmlInput.zip"); + const inputAsset = await pdfServices.upload({ + readStream, + mimeType: MimeType.ZIP + }); // Create parameters for the job const params = getHTMLToPDFParams(); // Creates a new job instance const job = new HTMLToPDFJob({ - inputURL, + inputAsset, params }); @@ -109,6 +122,8 @@ const fs = require("fs"); } else { console.log("Exception encountered while executing operation", err); } + } finally { + readStream?.destroy(); } })(); @@ -120,14 +135,14 @@ function getHTMLToPDFParams() { }); return new HTMLToPDFParams({ + pageLayout, includeHeaderFooter: true, - pageLayout }); } // Generates a string containing a directory structure and file name for the output file function createOutputFilePath() { - const filePath = "output/HTMLToPDFFromURL/"; + const filePath = "output/StaticHTMLToPDF/"; const date = new Date(); const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + diff --git a/src/pages/apis/pdf-services/insert-pdf-pages.md b/src/pages/apis/pdf-services/insert-pdf-pages.md index 4dff33839..73332b5ff 100644 --- a/src/pages/apis/pdf-services/insert-pdf-pages.md +++ b/src/pages/apis/pdf-services/insert-pdf-pages.md @@ -87,6 +87,11 @@ const { } = require("@dcloud/pdfservices-node-sdk"); const fs = require("fs"); +/** + * This sample illustrates how to insert specific pages of multiple PDF files into a single PDF file + *

+ * Refer to README.md for instructions on how to run the samples. + */ (async () => { let baseReadStream; let firstReadStreamToInsert; @@ -147,6 +152,7 @@ const fs = require("fs"); pollingURL, resultType: InsertPagesResult }); + // Get content from the resulting asset(s) const resultAsset = pdfServicesResponse.result.asset; const streamAsset = await pdfServices.getContent({ diff --git a/src/pages/apis/pdf-services/linearize-pdf.md b/src/pages/apis/pdf-services/linearize-pdf.md index 4da2b924a..6f7f8e69d 100644 --- a/src/pages/apis/pdf-services/linearize-pdf.md +++ b/src/pages/apis/pdf-services/linearize-pdf.md @@ -51,6 +51,12 @@ const { } = require("@dcloud/pdfservices-node-sdk"); const fs = require("fs"); +/** + * This 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. + *

+ * Refer to README.md for instructions on how to run the samples. + */ (async () => { let readStream; try { @@ -59,6 +65,7 @@ const fs = require("fs"); clientId: process.env.PDF_SERVICES_CLIENT_ID, clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET }); + // Creates a PDF Services instance const pdfServices = new PDFServices({ credentials diff --git a/src/pages/apis/pdf-services/ocr-pdf.md b/src/pages/apis/pdf-services/ocr-pdf.md index 74822935a..bd9da781f 100644 --- a/src/pages/apis/pdf-services/ocr-pdf.md +++ b/src/pages/apis/pdf-services/ocr-pdf.md @@ -51,6 +51,11 @@ const { } = require("@dcloud/pdfservices-node-sdk"); const fs = require("fs"); +/** + * This sample illustrates how to perform OCR operation on a PDF file and convert it into a searchable PDF file + *

+ * Refer to README.md for instructions on how to run the samples. + */ (async () => { let readStream; try { diff --git a/src/pages/apis/pdf-services/remove-pdf-password.md b/src/pages/apis/pdf-services/remove-pdf-password.md index 677dcab14..9d6824e32 100644 --- a/src/pages/apis/pdf-services/remove-pdf-password.md +++ b/src/pages/apis/pdf-services/remove-pdf-password.md @@ -53,6 +53,11 @@ const { } = require("@dcloud/pdfservices-node-sdk"); const fs = require("fs"); +/** + * This sample illustrates how to remove password security from a PDF document. + *

+ * Refer to README.md for instructions on how to run the samples. + */ (async () => { let readStream; try { @@ -104,7 +109,6 @@ const fs = require("fs"); const outputFilePath = createOutputFilePath(); console.log(`Saving asset at ${outputFilePath}`); - const outputStream = fs.createWriteStream(outputFilePath); streamAsset.readStream.pipe(outputStream); } catch (err) { @@ -117,6 +121,7 @@ const fs = require("fs"); readStream?.destroy(); } })(); + // Generates a string containing a directory structure and file name for the output file function createOutputFilePath() { const filePath = "output/RemoveProtection/"; diff --git a/src/pages/apis/pdf-services/reorder-pdf-pages.md b/src/pages/apis/pdf-services/reorder-pdf-pages.md index 7c2b5e64b..3831e3d16 100644 --- a/src/pages/apis/pdf-services/reorder-pdf-pages.md +++ b/src/pages/apis/pdf-services/reorder-pdf-pages.md @@ -71,6 +71,11 @@ const { } = require("@dcloud/pdfservices-node-sdk"); const fs = require("fs"); +/** + * This sample illustrates how to reorder the pages in a PDF file + *

+ * Refer to README.md for instructions on how to run the samples. + */ (async () => { let readStream; try { @@ -122,6 +127,7 @@ const fs = require("fs"); // Creates an output stream and copy result asset's content to it const outputFilePath = createOutputFilePath(); console.log(`Saving asset at ${outputFilePath}`); + const outputStream = fs.createWriteStream(outputFilePath); streamAsset.readStream.pipe(outputStream); } catch (err) { diff --git a/src/pages/apis/pdf-services/replace-pdf-pages.md b/src/pages/apis/pdf-services/replace-pdf-pages.md index d6dd0c109..7fbfe4b15 100644 --- a/src/pages/apis/pdf-services/replace-pdf-pages.md +++ b/src/pages/apis/pdf-services/replace-pdf-pages.md @@ -78,6 +78,12 @@ const { } = require("@dcloud/pdfservices-node-sdk"); const fs = require("fs"); +/** + * This sample illustrates how to replace specific pages in a PDF file + *

+ * Refer to README.md for instructions on how to run the samples. + */ + (async () => { let baseReadStream; let readStream1; diff --git a/src/pages/apis/pdf-services/rotate-pdf-pages.md b/src/pages/apis/pdf-services/rotate-pdf-pages.md index 764c2ab78..274180bdd 100644 --- a/src/pages/apis/pdf-services/rotate-pdf-pages.md +++ b/src/pages/apis/pdf-services/rotate-pdf-pages.md @@ -77,6 +77,11 @@ const { } = require("@dcloud/pdfservices-node-sdk"); const fs = require("fs"); +/** + * This sample illustrates how to rotate pages in a PDF file + *

+ * Refer to README.md for instructions on how to run the samples. + */ (async () => { let readStream; try { @@ -157,6 +162,14 @@ function getFirstPageRangeForRotation() { return firstPageRange; } +function getSecondPageRangeForRotation() { + // Specify pages for rotation. + const secondPageRange = new PageRanges(); + // Add page 2. + secondPageRange.addSinglePage(2); + return secondPageRange; +} + // Generates a string containing a directory structure and file name for the output file function createOutputFilePath() { const filePath = "output/RotatePages/"; @@ -169,7 +182,6 @@ function createOutputFilePath() { }); return (`${filePath}rotate${dateString}.pdf`); } - ``` #### .Net diff --git a/src/pages/apis/pdf-services/secure-pdf.md b/src/pages/apis/pdf-services/secure-pdf.md index 3a0aaf87b..562387f4d 100644 --- a/src/pages/apis/pdf-services/secure-pdf.md +++ b/src/pages/apis/pdf-services/secure-pdf.md @@ -55,6 +55,12 @@ const { } = require("@dcloud/pdfservices-node-sdk"); const fs = require("fs"); +/** + * This sample illustrates how to convert a PDF file into a password protected PDF file + * The password is used for encrypting PDF contents and will be required for viewing the PDF file + *

+ * Refer to README.md for instructions on how to run the samples. + */ (async () => { let readStream; try { @@ -82,6 +88,12 @@ const fs = require("fs"); encryptionAlgorithm: EncryptionAlgorithm.AES_256 }); + // Create a new job instance + const job = new ProtectPDFJob({ + inputAsset, + params + }); + // Submit the job and get the job result const pollingURL = await pdfServices.submit({ job @@ -90,6 +102,7 @@ const fs = require("fs"); pollingURL, resultType: ProtectPDFResult }); + // Get content from the resulting asset(s) const resultAsset = pdfServicesResponse.result.asset; const streamAsset = await pdfServices.getContent({ diff --git a/src/pages/apis/pdf-services/split-pdf.md b/src/pages/apis/pdf-services/split-pdf.md index 23894a6dc..ab860847e 100644 --- a/src/pages/apis/pdf-services/split-pdf.md +++ b/src/pages/apis/pdf-services/split-pdf.md @@ -55,6 +55,12 @@ const { } = require("@dcloud/pdfservices-node-sdk"); const fs = require("fs"); +/** + * This sample illustrates how to split input PDF into multiple PDF files on the basis of the maximum number + * of pages each of the output files can have. + *

+ * Refer to README.md for instructions on how to run the samples. + */ (async () => { let readStream; try { @@ -78,7 +84,7 @@ const fs = require("fs"); // Create parameters for the job const params = new SplitPDFParams({ - fileCount: 2 + pageCount: 2 }); // Creates a new job instance @@ -87,6 +93,7 @@ const fs = require("fs"); params }); + // Submit the job and get the job result const pollingURL = await pdfServices.submit({ job }); @@ -94,6 +101,7 @@ const fs = require("fs"); pollingURL, resultType: SplitPDFResult }); + // Get content from the resulting asset(s) const resultAssets = pdfServicesResponse.result.assets; let getOutputFilePathForIndex = createOutputFilePath(); @@ -119,9 +127,10 @@ const fs = require("fs"); readStream?.destroy(); } })(); + // Generates a string containing a directory structure and file name for the output file function createOutputFilePath() { - const filePath = "output/SplitPDFIntoNumberOfFiles/"; + const filePath = "output/SplitPDFByNumberOfPages/"; const date = new Date(); const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + diff --git a/src/pages/home/accessbility-auto-tag.md b/src/pages/home/accessbility-auto-tag.md index 7a4421168..6371d0609 100644 --- a/src/pages/home/accessbility-auto-tag.md +++ b/src/pages/home/accessbility-auto-tag.md @@ -42,6 +42,11 @@ const { } = require("@dcloud/pdfservices-node-sdk"); const fs = require("fs"); +/** + * This sample illustrates how to generate a tagged PDF. + *

+ * Refer to README.md for instructions on how to run the samples. + */ (async () => { let readStream; try { @@ -54,7 +59,7 @@ const fs = require("fs"); // Creates a PDF Services instance const pdfServices = new PDFServices({ credentials - });; + }); // Creates an asset(s) from source file(s) and upload readStream = fs.createReadStream("resources/autotagPDFInput.pdf"); @@ -63,6 +68,11 @@ const fs = require("fs"); mimeType: MimeType.PDF }); + // Creates a new job instance + const job = new AutotagPDFJob({ + inputAsset + }); + // Submit the job and get the job result const pollingURL = await pdfServices.submit({ job @@ -71,6 +81,7 @@ const fs = require("fs"); pollingURL, resultType: AutotagPDFResult }); + // Get content from the resulting asset(s) const resultAsset = pdfServicesResponse.result.taggedPDF; const streamAsset = await pdfServices.getContent({ @@ -93,6 +104,7 @@ const fs = require("fs"); readStream?.destroy(); } })(); + // Generates a string containing a directory structure and file name for the output file function createOutputFilePath() { const filePath = "output/AutotagPDF/"; diff --git a/src/pages/home/create-pdf-from-url.md b/src/pages/home/create-pdf-from-url.md index d7e1c8c18..149ae9fc6 100644 --- a/src/pages/home/create-pdf-from-url.md +++ b/src/pages/home/create-pdf-from-url.md @@ -37,18 +37,19 @@ const { ServicePrincipalCredentials, PDFServices, MimeType, - ClientConfig, CreatePDFJob, CreatePDFResult, - ProxyServerConfig, - ProxyScheme, - UsernamePasswordCredentials, SDKError, ServiceUsageError, ServiceApiError } = require("@dcloud/pdfservices-node-sdk"); const fs = require("fs"); +/** + * This sample illustrates how to create a PDF file from a DOCX file. + *

+ * Refer to README.md for instructions on how to run the samples. + */ (async () => { let readStream; try { @@ -58,38 +59,13 @@ const fs = require("fs"); clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET }); - /* - Initial setup, creates proxy server config instance for client config. - Replace the values of PROXY_HOSTNAME with the proxy server hostname. - Replace the username and password with Proxy Server Authentication credentials. - If the scheme of proxy server is not HTTP then, replace ProxyScheme parameter with HTTPS. - If the port for proxy server is diff than the default port for HTTP and HTTPS, then please set the - PROXY_PORT, - else, remove its setter statement. - */ - const proxyServerConfig = new ProxyServerConfig({ - host: "PROXY_HOSTNAME", - port: 443, - scheme: ProxyScheme.HTTP, - credentials: new UsernamePasswordCredentials({ - username: "USERNAME", - password: "PASSWORD" - }) - }); - - // Creates client config instance - const clientConfig = new ClientConfig({ - proxyServerConfig - }); - // Creates a PDF Services instance const pdfServices = new PDFServices({ - credentials, - clientConfig + credentials }); // Creates an asset(s) from source file(s) and upload - readStream = fs.createReadStream("resources/createPDFInput.docx") + readStream = fs.createReadStream("resources/createPDFInput.docx"); const inputAsset = await pdfServices.upload({ readStream, mimeType: MimeType.DOCX @@ -115,12 +91,12 @@ const fs = require("fs"); asset: resultAsset }); - // Creates a write stream and copy stream asset's content to it + // Creates an output stream and copy result asset's content to it const outputFilePath = createOutputFilePath(); console.log(`Saving asset at ${outputFilePath}`); - const writeStream = fs.createWriteStream(outputFilePath); - streamAsset.readStream.pipe(writeStream); + const outputStream = fs.createWriteStream(outputFilePath); + streamAsset.readStream.pipe(outputStream); } catch (err) { if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { console.log("Exception encountered while executing operation", err); @@ -134,7 +110,7 @@ const fs = require("fs"); // Generates a string containing a directory structure and file name for the output file function createOutputFilePath() { - const filePath = "output/CreatePDFWithAuthenticatedProxyServer/"; + const filePath = "output/CreatePDFFromDOCX/"; const date = new Date(); const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + diff --git a/src/pages/home/dynamic-pdf-document-generation.md b/src/pages/home/dynamic-pdf-document-generation.md index e3cc07026..8ec2c60e7 100644 --- a/src/pages/home/dynamic-pdf-document-generation.md +++ b/src/pages/home/dynamic-pdf-document-generation.md @@ -72,6 +72,14 @@ const { } = require("@dcloud/pdfservices-node-sdk"); const fs = require("fs"); +/** + * This sample illustrates how to merge the Word based document template with the input JSON data to generate + * the output document in the PDF format. + *

+ * To know more about document generation and document templates, please see the documentation + *

+ * Refer to README.md for instructions on how to run the samples. + */ (async () => { let readStream; try { @@ -87,41 +95,19 @@ const fs = require("fs"); }); // Creates an asset(s) from source file(s) and upload - readStream = fs.createReadStream("resources/documentMergeTemplate.docx"); + readStream = fs.createReadStream("resources/salesOrderTemplate.docx"); const inputAsset = await pdfServices.upload({ readStream, mimeType: MimeType.DOCX }); // Setup input data for the document merge process - const jsonDataForMerge = { - customerName: 'Kane Miller', - customerVisits: 100, - itemsBought: [{ - description: 'Sprays', - quantity: 50, - amount: 100 - }, - { - description: 'Chemicals', - quantity: 100, - amount: 200 - } - ], - totalAmount: 300, - previousBalance: 50, - lastThreeBillings: [ - 100, - 200, - 300 - ], - photograph: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAZuElEQVR4nL1de7gcRZX/neqeme65l7zuzRsijxgwBJJAghBBXQ0PkeCCD15+i+7qqkvg81v8dkX9Y1fYBZUVBVzQRR4rEXCVh8AniisQFJIQlIsIeQAxkoQ8bp7ce+fR3XX2j+ruqZ7q7um5N+z55ruZ6T516lTVr845daq6Q+sO6Z0B8hkABBRJAAKEiNR1otYVnYi178QxJzOn8kecLR7mlmROryTklIkrFPNLg1+ivXbFybJVu8/t5fRSUteEBTPb2c0ZDYWNBwBktDrilIozj1dJyxqk0emm6pJSdlbRoNTOEgCYJSJFVf8LDSl6A3QsEAtEnZWHq0hPzugIHZVBAqEC8fgXwFQCp7KFZR01IeI4E1OhTErvrM6UNeaqmiIDZnLmT9uwFLe6KUurbvFSnBKdpY+SoBZGLLTbi5DHwFpxPbO6SRo8um3qgCYTL6GFAoAgi8fEFIvWFQ2nhZAlC9iOIrgwKV+m5M7WLwtNSQuVz1OUbAlIlkwCSb8W2iklVEOZ8pIEibQR1kkYV1L41TBoJRJeTLOYJmWhKQKMEt/ZQoXSNEyZnlTVYkc6K6U7T6MQZTiYfipCUFGLk4+mIq3oVrLS0A7vMRD1qB5hpdipcNhaWAMCAMQW2rykroReMQKAAUu7RqEK1AlHITvQ5um4ZTFVWCA1G6exZFsohURtcun8SqsUm9V9dNNqttRNvi5TZ6f2CSoJlA2pfB+noym0TflyRlWLIlsyJEj1IoW9C0ThYujjDFuWQmObkRxHZ6ZNMa2S+m7G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+fbnYjHeJNI/qTOUKF1pjTmTeQJjAKmUkXSMLpvip564CgxkYzytEgnRg23ydEpo3b1RGKW9YF+at9cxmmTV2h+vEOcFRiq6LiI1EqnDv8DFMX/p0qKgIStifo5R1xKkEmJjE07Zxj+dR7nIFoiIDwHz2TaDjO/Eyqh25HE/w/Y7omSZoG071FjIqYieEnAItdnhRdSsKOxal2Q3Itsr0WnsZ3PaqEjxRPpJA2LUDxvNUrOwtjRqcMpGmYwWBrQynr5UiKMyEdHRjGKDs20sURrfeTZmkQB9fSyD0CGW7MGSDKsT0vvdi/ZrrTuSTORlZPSb1kSbSlQ3IvlPMAYqpv9liwTOwHZ6IRrRbr10aVJQQCsDAG6tv8HcAoVaSJluIMAAAAASUVORK5CYII=' - }; + const jsonString = fs.readFileSync('resources/salesOrder.json', 'utf-8'); // Create parameters for the job const params = new DocumentMergeParams({ - jsonDataForMerge, - outputFormat: OutputFormat.DOCX + jsonDataForMerge: JSON.parse(jsonString), + outputFormat: OutputFormat.PDF }); // Creates a new job instance @@ -138,6 +124,7 @@ const fs = require("fs"); pollingURL, resultType: DocumentMergeResult }); + // Get content from the resulting asset(s) const resultAsset = pdfServicesResponse.result.asset; const streamAsset = await pdfServices.getContent({ @@ -147,6 +134,7 @@ const fs = require("fs"); // Creates a write stream and copy stream asset's content to it const outputFilePath = createOutputFilePath(); console.log(`Saving asset at ${outputFilePath}`); + const writeStream = fs.createWriteStream(outputFilePath); streamAsset.readStream.pipe(writeStream); } catch (err) { @@ -159,9 +147,10 @@ const fs = require("fs"); readStream?.destroy(); } })(); + // Generates a string containing a directory structure and file name for the output file function createOutputFilePath() { - const filePath = "output/MergeDocumentToDOCX/"; + const filePath = "output/MergeDocumentToPDF/"; const date = new Date(); const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + @@ -169,7 +158,7 @@ function createOutputFilePath() { fs.mkdirSync(filePath, { recursive: true }); - return (`${filePath}merge${dateString}.docx`); + return (`${filePath}merge${dateString}.pdf`); } ``` diff --git a/src/pages/home/e-seal.md b/src/pages/home/e-seal.md index b00079212..2ec10c025 100644 --- a/src/pages/home/e-seal.md +++ b/src/pages/home/e-seal.md @@ -82,6 +82,14 @@ const { } = require("@dcloud/pdfservices-node-sdk"); const fs = require("fs"); +/** + * This sample illustrates how to apply electronic seal over the PDF document using default appearance options. + * + *

+ * To know more about PDF Electronic Seal, please see the <documentation. + *

+ * Refer to README.md for instructions on how to run the samples. + */ (async () => { let sourceFileReadStream; let sealImageReadStream; @@ -91,6 +99,7 @@ const fs = require("fs"); clientId: process.env.PDF_SERVICES_CLIENT_ID, clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET }); + // Creates a PDF Services instance const pdfServices = new PDFServices({ credentials @@ -142,6 +151,7 @@ const fs = require("fs"); // Set the access token to be used to access TSP provider hosted APIs const accessToken = ""; + // Set the credential ID const credentialId = ""; diff --git a/src/pages/home/pdf-content-structure.md b/src/pages/home/pdf-content-structure.md index b521679bc..f68bef85e 100644 --- a/src/pages/home/pdf-content-structure.md +++ b/src/pages/home/pdf-content-structure.md @@ -50,6 +50,11 @@ const { } = require("@dcloud/pdfservices-node-sdk"); const fs = require("fs"); +/** + * This sample illustrates how to extract Text Information from PDF. + *

+ * Refer to README.md for instructions on how to run the samples & understand output zip file + */ (async () => { let readStream; try { @@ -100,6 +105,7 @@ const fs = require("fs"); // Creates a write stream and copy stream asset's content to it const outputFilePath = createOutputFilePath(); console.log(`Saving asset at ${outputFilePath}`); + const writeStream = fs.createWriteStream(outputFilePath); streamAsset.readStream.pipe(writeStream); } catch (err) { @@ -112,6 +118,7 @@ const fs = require("fs"); readStream?.destroy(); } })(); + // Generates a string containing a directory structure and file name for the output file function createOutputFilePath() { const filePath = "output/ExtractTextInfoFromPDF/"; From a023a3618fb2354a76502709fc0c74508467e3b0 Mon Sep 17 00:00:00 2001 From: Vignesh Date: Thu, 21 Mar 2024 20:42:12 +0530 Subject: [PATCH 3/5] --Formatted node samples --- .../accessibility-auto-tag-api.md | 31 ++------- src/pages/apis/pdf-services/combine-pdf.md | 28 ++------- src/pages/apis/pdf-services/compress-pdf.md | 24 +------ src/pages/apis/pdf-services/convert-pdf.md | 63 ++++++++----------- src/pages/apis/pdf-services/create-pdf.md | 26 ++------ .../apis/pdf-services/delete-pdf-pages.md | 41 +++--------- .../apis/pdf-services/document-generation.md | 38 +++-------- src/pages/apis/pdf-services/e-seal.md | 29 ++------- .../apis/pdf-services/extract-pdf-content.md | 24 +------ .../apis/pdf-services/get-pdf-properties.md | 9 +-- src/pages/apis/pdf-services/html-to-pdf.md | 25 +------- .../apis/pdf-services/insert-pdf-pages.md | 38 ++--------- src/pages/apis/pdf-services/linearize-pdf.md | 23 +------ src/pages/apis/pdf-services/ocr-pdf.md | 40 +++--------- .../apis/pdf-services/remove-pdf-password.md | 24 +------ .../apis/pdf-services/reorder-pdf-pages.md | 24 +------ .../apis/pdf-services/replace-pdf-pages.md | 29 ++------- .../apis/pdf-services/rotate-pdf-pages.md | 41 +++--------- src/pages/apis/pdf-services/secure-pdf.md | 25 +------- src/pages/apis/pdf-services/split-pdf.md | 27 ++------ src/pages/home/accessbility-auto-tag.md | 31 ++------- src/pages/home/create-pdf-from-url.md | 26 ++------ .../home/dynamic-pdf-document-generation.md | 38 +++-------- src/pages/home/e-seal.md | 29 ++------- src/pages/home/pdf-content-structure.md | 24 +------ 25 files changed, 135 insertions(+), 622 deletions(-) diff --git a/src/pages/apis/pdf-services/accessibility-auto-tag-api.md b/src/pages/apis/pdf-services/accessibility-auto-tag-api.md index 1fa40b1ad..a0a5e3c2b 100644 --- a/src/pages/apis/pdf-services/accessibility-auto-tag-api.md +++ b/src/pages/apis/pdf-services/accessibility-auto-tag-api.md @@ -42,17 +42,9 @@ const { MimeType, AutotagPDFJob, AutotagPDFResult, - SDKError, - ServiceUsageError, - ServiceApiError -} = require("@dcloud/pdfservices-node-sdk"); +} = require("@adobe/pdfservices-node-sdk"); const fs = require("fs"); -/** - * This sample illustrates how to generate a tagged PDF. - *

- * Refer to README.md for instructions on how to run the samples. - */ (async () => { let readStream; try { @@ -68,7 +60,7 @@ const fs = require("fs"); }); // Creates an asset(s) from source file(s) and upload - readStream = fs.createReadStream("resources/autotagPDFInput.pdf"); + readStream = fs.createReadStream("./autotagPDFInput.pdf"); const inputAsset = await pdfServices.upload({ readStream, mimeType: MimeType.PDF @@ -95,11 +87,11 @@ const fs = require("fs"); }); // Creates an output stream and copy stream asset's content to it - const outputFilePath = createOutputFilePath(); + const outputFilePath = "./autotag-tagged.pdf"; console.log(`Saving asset at ${outputFilePath}`); - const outputStream = fs.createWriteStream(outputFilePath); - streamAsset.readStream.pipe(outputStream); + let writeStream = fs.createWriteStream(outputFilePath); + streamAsset.readStream.pipe(writeStream); } catch (err) { if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { console.log("Exception encountered while executing operation", err); @@ -110,19 +102,6 @@ const fs = require("fs"); readStream?.destroy(); } })(); - -// Generates a string containing a directory structure and file name for the output file -function createOutputFilePath() { - const filePath = "output/AutotagPDF/"; - const date = new Date(); - const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + - ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + - ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); - fs.mkdirSync(filePath, { - recursive: true - }); - return (`${filePath}autotag${dateString}.pdf`); -} ``` #### .Net diff --git a/src/pages/apis/pdf-services/combine-pdf.md b/src/pages/apis/pdf-services/combine-pdf.md index f0d9ba27f..e5489cf1f 100644 --- a/src/pages/apis/pdf-services/combine-pdf.md +++ b/src/pages/apis/pdf-services/combine-pdf.md @@ -56,16 +56,9 @@ const { SDKError, ServiceUsageError, ServiceApiError -} = require("@dcloud/pdfservices-node-sdk"); +} = require("@adobe/pdfservices-node-sdk"); const fs = require("fs"); -/** - * This sample illustrates how to combine multiple PDF files into a single PDF file. - *

- * Note that the SDK supports combining upto 20 files in one operation. - *

- * Refer to README.md for instructions on how to run the samples. - */ (async () => { let readStream1; let readStream2; @@ -82,8 +75,8 @@ const fs = require("fs"); }); // Creates an asset(s) from source file(s) and upload - readStream1 = fs.createReadStream("resources/combineFilesInput1.pdf"); - readStream2 = fs.createReadStream("resources/combineFilesInput2.pdf"); + readStream1 = fs.createReadStream("./combineFilesInput1.pdf"); + readStream2 = fs.createReadStream("./combineFilesInput2.pdf"); const [inputAsset1, inputAsset2] = await pdfServices.uploadAssets({ streamAssets: [{ readStream: readStream1, @@ -120,7 +113,7 @@ const fs = require("fs"); }); // Creates an output stream and copy result asset's content to it - const outputFilePath = createOutputFilePath(); + const outputFilePath = "./combineFilesOutput.pdf"; console.log(`Saving asset at ${outputFilePath}`); const outputStream = fs.createWriteStream(outputFilePath); @@ -136,19 +129,6 @@ const fs = require("fs"); readStream2?.destroy(); } })(); - -// Generates a string containing a directory structure and file name for the output file -function createOutputFilePath() { - const filePath = "output/CombinePDF/"; - const date = new Date(); - const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + - ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + - ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); - fs.mkdirSync(filePath, { - recursive: true - }); - return (`${filePath}combine${dateString}.pdf`); -} ``` #### .Net diff --git a/src/pages/apis/pdf-services/compress-pdf.md b/src/pages/apis/pdf-services/compress-pdf.md index 1e0ab4f39..3eb873dbc 100644 --- a/src/pages/apis/pdf-services/compress-pdf.md +++ b/src/pages/apis/pdf-services/compress-pdf.md @@ -50,14 +50,9 @@ const { SDKError, ServiceUsageError, ServiceApiError -} = require("@dcloud/pdfservices-node-sdk"); +} = require("@adobe/pdfservices-node-sdk"); const fs = require("fs"); -/** - * This sample illustrates how to compress PDF by reducing the size of the PDF file. - *

- * Refer to README.md for instructions on how to run the samples. - */ (async () => { let readStream; try { @@ -73,7 +68,7 @@ const fs = require("fs"); }); // Creates an asset(s) from source file(s) and upload - readStream = fs.createReadStream("resources/compressPDFInput.pdf"); + readStream = fs.createReadStream("./compressPDFInput.pdf"); const inputAsset = await pdfServices.upload({ readStream, mimeType: MimeType.PDF @@ -100,7 +95,7 @@ const fs = require("fs"); }); // Creates an output stream and copy stream asset's content to it - const outputFilePath = createOutputFilePath(); + const outputFilePath = "./compressPDFOutput.pdf"; console.log(`Saving asset at ${outputFilePath}`); const outputStream = fs.createWriteStream(outputFilePath); @@ -115,19 +110,6 @@ const fs = require("fs"); readStream?.destroy(); } })(); - -// Generates a string containing a directory structure and file name for the output file -function createOutputFilePath() { - const filePath = "output/CompressPDF/"; - const date = new Date(); - const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + - ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + - ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); - fs.mkdirSync(filePath, { - recursive: true - }); - return (`${filePath}compress${dateString}.pdf`); -} ``` #### .Net diff --git a/src/pages/apis/pdf-services/convert-pdf.md b/src/pages/apis/pdf-services/convert-pdf.md index 79061480f..5ee954f80 100644 --- a/src/pages/apis/pdf-services/convert-pdf.md +++ b/src/pages/apis/pdf-services/convert-pdf.md @@ -40,27 +40,23 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/exportpd ```js // Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample // Run the sample: -// node src/exportpdf/export-pdf-to-docx.js +// node src/exportpdftoimages/export-pdf-to-jpeg.js const { ServicePrincipalCredentials, PDFServices, MimeType, - ExportPDFJob, - ExportPDFParams, - ExportPDFTargetFormat, - ExportPDFResult, + ExportPDFToImagesJob, + ExportPDFToImagesTargetFormat, + ExportPDFToImagesOutputType, + ExportPDFToImagesParams, + ExportPDFToImagesResult, SDKError, ServiceUsageError, ServiceApiError -} = require("@dcloud/pdfservices-node-sdk"); +} = require("@adobe/pdfservices-node-sdk"); const fs = require("fs"); -/** - * This sample illustrates how to export a PDF file to a Word (DOCX) file - *

- * Refer to README.md for instructions on how to run the samples. - */ (async () => { let readStream; try { @@ -76,19 +72,20 @@ const fs = require("fs"); }); // Creates an asset(s) from source file(s) and upload - readStream = fs.createReadStream("resources/exportPDFInput.pdf"); + readStream = fs.createReadStream("./exportPDFToImageInput.pdf"); const inputAsset = await pdfServices.upload({ readStream, mimeType: MimeType.PDF }); // Create parameters for the job - const params = new ExportPDFParams({ - targetFormat: ExportPDFTargetFormat.DOCX + const params = new ExportPDFToImagesParams({ + targetFormat: ExportPDFToImagesTargetFormat.JPEG, + outputType: ExportPDFToImagesOutputType.LIST_OF_PAGE_IMAGES }); // Creates a new job instance - const job = new ExportPDFJob({ + const job = new ExportPDFToImagesJob({ inputAsset, params }); @@ -99,21 +96,24 @@ const fs = require("fs"); }); const pdfServicesResponse = await pdfServices.getJobResult({ pollingURL, - resultType: ExportPDFResult + resultType: ExportPDFToImagesResult }); // Get content from the resulting asset(s) - const resultAsset = pdfServicesResponse.result.asset; - const streamAsset = await pdfServices.getContent({ - asset: resultAsset - }); + const resultAssets = pdfServicesResponse.result.assets; + + for (let i = 0; i < resultAssets.length; i++) { + const _outputFilePath = "./exportPDFToImageOutput_${i}.jpeg"; + console.log(`Saving asset at ${_outputFilePath}`); - // Creates an output stream and copy stream asset's content to it - const outputFilePath = createOutputFilePath(); - console.log(`Saving asset at ${outputFilePath}`); + const streamAsset = await pdfServices.getContent({ + asset: resultAssets[i] + }); - const outputStream = fs.createWriteStream(outputFilePath); - streamAsset.readStream.pipe(outputStream); + // Creates an output stream and copy stream asset's content to it + const outputStream = fs.createWriteStream(_outputFilePath); + streamAsset.readStream.pipe(outputStream); + } } catch (err) { if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { console.log("Exception encountered while executing operation", err); @@ -124,19 +124,6 @@ const fs = require("fs"); readStream?.destroy(); } })(); - -// Generates a string containing a directory structure and file name for the output file -function createOutputFilePath() { - const filePath = "output/ExportPDFToDOCX/"; - const date = new Date(); - const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + - ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + - ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); - fs.mkdirSync(filePath, { - recursive: true - }); - return (`${filePath}export${dateString}.docx`); -} ``` #### .Net diff --git a/src/pages/apis/pdf-services/create-pdf.md b/src/pages/apis/pdf-services/create-pdf.md index 7b461e497..6c35eacad 100644 --- a/src/pages/apis/pdf-services/create-pdf.md +++ b/src/pages/apis/pdf-services/create-pdf.md @@ -38,7 +38,7 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/createpd ```js // Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample // Run the sample: -// node src/createpdf/create-pdf-from-docx.js +// node src/createpdf/create-pdf-from-docx.js const { ServicePrincipalCredentials, @@ -49,14 +49,9 @@ const { SDKError, ServiceUsageError, ServiceApiError -} = require("@dcloud/pdfservices-node-sdk"); +} = require("@adobe/pdfservices-node-sdk"); const fs = require("fs"); -/** - * This sample illustrates how to create a PDF file from a DOCX file. - *

- * Refer to README.md for instructions on how to run the samples. - */ (async () => { let readStream; try { @@ -72,7 +67,7 @@ const fs = require("fs"); }); // Creates an asset(s) from source file(s) and upload - readStream = fs.createReadStream("resources/createPDFInput.docx"); + readStream = fs.createReadStream("./createPDFInput.docx"); const inputAsset = await pdfServices.upload({ readStream, mimeType: MimeType.DOCX @@ -99,7 +94,7 @@ const fs = require("fs"); }); // Creates an output stream and copy result asset's content to it - const outputFilePath = createOutputFilePath(); + const outputFilePath = "./createPDFFromDOCX.pdf"; console.log(`Saving asset at ${outputFilePath}`); const outputStream = fs.createWriteStream(outputFilePath); @@ -114,19 +109,6 @@ const fs = require("fs"); readStream?.destroy(); } })(); - -// Generates a string containing a directory structure and file name for the output file -function createOutputFilePath() { - const filePath = "output/CreatePDFFromDOCX/"; - const date = new Date(); - const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + - ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + - ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); - fs.mkdirSync(filePath, { - recursive: true - }); - return (`${filePath}create${dateString}.pdf`); -} ``` #### .Net diff --git a/src/pages/apis/pdf-services/delete-pdf-pages.md b/src/pages/apis/pdf-services/delete-pdf-pages.md index eb1d94e2e..429263bb3 100644 --- a/src/pages/apis/pdf-services/delete-pdf-pages.md +++ b/src/pages/apis/pdf-services/delete-pdf-pages.md @@ -62,14 +62,9 @@ const { SDKError, ServiceUsageError, ServiceApiError -} = require("@dcloud/pdfservices-node-sdk"); +} = require("@adobe/pdfservices-node-sdk"); const fs = require("fs"); -/** - * This sample illustrates how to delete pages in a PDF file - *

- * Refer to README.md for instructions on how to run the samples. - */ (async () => { let readStream; try { @@ -80,12 +75,10 @@ const fs = require("fs"); }); // Creates a PDF Services instance - const pdfServices = new PDFServices({ - credentials - }); + const pdfServices = new PDFServices({credentials}); // Creates an asset(s) from source file(s) and upload - readStream = fs.createReadStream("resources/deletePagesInput.pdf"); + readStream = fs.createReadStream("./deletePagesInput.pdf"); const inputAsset = await pdfServices.upload({ readStream, mimeType: MimeType.PDF @@ -100,15 +93,10 @@ const fs = require("fs"); }); // Creates a new job instance - const job = new DeletePagesJob({ - inputAsset, - params - }); + const job = new DeletePagesJob({inputAsset, params}); // Submit the job and get the job result - const pollingURL = await pdfServices.submit({ - job - }); + const pollingURL = await pdfServices.submit({job}); const pdfServicesResponse = await pdfServices.getJobResult({ pollingURL, resultType: DeletePagesResult @@ -116,12 +104,10 @@ const fs = require("fs"); // Get content from the resulting asset(s) const resultAsset = pdfServicesResponse.result.asset; - const streamAsset = await pdfServices.getContent({ - asset: resultAsset - }); + const streamAsset = await pdfServices.getContent({asset: resultAsset}); // Creates a write stream and copy stream asset's content to it - const outputFilePath = createOutputFilePath(); + const outputFilePath = "./deletePagesOutput.pdf"; console.log(`Saving asset at ${outputFilePath}`); const writeStream = fs.createWriteStream(outputFilePath); @@ -146,19 +132,6 @@ const getPageRangesForDeletion = () => { pageRangesForDeletion.addRange(3, 4); return pageRangesForDeletion; }; - -// Generates a string containing a directory structure and file name for the output file -function createOutputFilePath() { - const filePath = "output/DeletePDFPages/"; - const date = new Date(); - const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + - ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + - ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); - fs.mkdirSync(filePath, { - recursive: true - }); - return (`${filePath}delete${dateString}.pdf`); -} ``` #### .Net diff --git a/src/pages/apis/pdf-services/document-generation.md b/src/pages/apis/pdf-services/document-generation.md index 38bc1fda1..cd17654c5 100644 --- a/src/pages/apis/pdf-services/document-generation.md +++ b/src/pages/apis/pdf-services/document-generation.md @@ -80,17 +80,9 @@ const { SDKError, ServiceUsageError, ServiceApiError -} = require("@dcloud/pdfservices-node-sdk"); +} = require("@adobe/pdfservices-node-sdk"); const fs = require("fs"); -/** - * This sample illustrates how to merge the Word based document template with the input JSON data to generate - * the output document in the PDF format. - *

- * To know more about document generation and document templates, please see the documentation - *

- * Refer to README.md for instructions on how to run the samples. - */ (async () => { let readStream; try { @@ -105,19 +97,22 @@ const fs = require("fs"); credentials }); + // Setup input data for the document merge process + const jsonDataForMerge = { + customerName: "Kane Miller", + customerVisits: 100 + } + // Creates an asset(s) from source file(s) and upload - readStream = fs.createReadStream("resources/salesOrderTemplate.docx"); + readStream = fs.createReadStream("./documentMergeTemplate.docx"); const inputAsset = await pdfServices.upload({ readStream, mimeType: MimeType.DOCX }); - // Setup input data for the document merge process - const jsonString = fs.readFileSync('resources/salesOrder.json', 'utf-8'); - // Create parameters for the job const params = new DocumentMergeParams({ - jsonDataForMerge: JSON.parse(jsonString), + jsonDataForMerge, outputFormat: OutputFormat.PDF }); @@ -143,7 +138,7 @@ const fs = require("fs"); }); // Creates a write stream and copy stream asset's content to it - const outputFilePath = createOutputFilePath(); + const outputFilePath = "./documentMergeOutput.pdf"; console.log(`Saving asset at ${outputFilePath}`); const writeStream = fs.createWriteStream(outputFilePath); @@ -158,19 +153,6 @@ const fs = require("fs"); readStream?.destroy(); } })(); - -// Generates a string containing a directory structure and file name for the output file -function createOutputFilePath() { - const filePath = "output/MergeDocumentToPDF/"; - const date = new Date(); - const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + - ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + - ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); - fs.mkdirSync(filePath, { - recursive: true - }); - return (`${filePath}merge${dateString}.pdf`); -} ``` #### .NET diff --git a/src/pages/apis/pdf-services/e-seal.md b/src/pages/apis/pdf-services/e-seal.md index 85c6d5175..e25032ea0 100644 --- a/src/pages/apis/pdf-services/e-seal.md +++ b/src/pages/apis/pdf-services/e-seal.md @@ -85,17 +85,9 @@ const { SDKError, ServiceUsageError, ServiceApiError -} = require("@dcloud/pdfservices-node-sdk"); +} = require("@adobe/pdfservices-node-sdk"); const fs = require("fs"); -/** - * This sample illustrates how to apply electronic seal over the PDF document using default appearance options. - * - *

- * To know more about PDF Electronic Seal, please see the <documentation. - *

- * Refer to README.md for instructions on how to run the samples. - */ (async () => { let sourceFileReadStream; let sealImageReadStream; @@ -112,8 +104,8 @@ const fs = require("fs"); }); // Creates an asset(s) from source file(s) and upload - sourceFileReadStream = fs.createReadStream("resources/sampleInvoice.pdf") - sealImageReadStream = fs.createReadStream("resources/sampleSealImage.png"); + sourceFileReadStream = fs.createReadStream("./sampleInvoice.pdf") + sealImageReadStream = fs.createReadStream("./sampleSealImage.png"); const [sourceFileAsset, sealImageAsset] = await pdfServices.uploadAssets({ streamAssets: [{ readStream: sourceFileReadStream, @@ -208,7 +200,7 @@ const fs = require("fs"); }); // Creates a write stream and copy stream asset's content to it - const outputFilePath = createOutputFilePath(); + const outputFilePath = "./sealedOutput.pdf"; console.log(`Saving asset at ${outputFilePath}`); const writeStream = fs.createWriteStream(outputFilePath); @@ -224,19 +216,6 @@ const fs = require("fs"); sealImageReadStream?.destroy(); } })(); - -// Generates a string containing a directory structure and file name for the output file -function createOutputFilePath() { - const filePath = "output/ElectronicSeal/"; - const date = new Date(); - const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + - ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + - ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); - fs.mkdirSync(filePath, { - recursive: true - }); - return (`${filePath}seal${dateString}.pdf`); -} ``` #### .Net diff --git a/src/pages/apis/pdf-services/extract-pdf-content.md b/src/pages/apis/pdf-services/extract-pdf-content.md index 69c6d4e29..48473c700 100644 --- a/src/pages/apis/pdf-services/extract-pdf-content.md +++ b/src/pages/apis/pdf-services/extract-pdf-content.md @@ -53,14 +53,9 @@ const { SDKError, ServiceUsageError, ServiceApiError -} = require("@dcloud/pdfservices-node-sdk"); +} = require("@adobe/pdfservices-node-sdk"); const fs = require("fs"); -/** - * This sample illustrates how to extract Text Information from PDF. - *

- * Refer to README.md for instructions on how to run the samples & understand output zip file - */ (async () => { let readStream; try { @@ -76,7 +71,7 @@ const fs = require("fs"); }); // Creates an asset(s) from source file(s) and upload - readStream = fs.createReadStream("resources/extractPDFInput.pdf"); + readStream = fs.createReadStream("./extractPDFInput.pdf"); const inputAsset = await pdfServices.upload({ readStream, mimeType: MimeType.PDF @@ -109,7 +104,7 @@ const fs = require("fs"); }); // Creates a write stream and copy stream asset's content to it - const outputFilePath = createOutputFilePath(); + const outputFilePath = "./ExtractTextInfoFromPDF.zip"; console.log(`Saving asset at ${outputFilePath}`); const writeStream = fs.createWriteStream(outputFilePath); @@ -124,19 +119,6 @@ const fs = require("fs"); readStream?.destroy(); } })(); - -// Generates a string containing a directory structure and file name for the output file -function createOutputFilePath() { - const filePath = "output/ExtractTextInfoFromPDF/"; - const date = new Date(); - const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + - ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + - ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); - fs.mkdirSync(filePath, { - recursive: true - }); - return (`${filePath}extract${dateString}.zip`); -} ``` #### .Net diff --git a/src/pages/apis/pdf-services/get-pdf-properties.md b/src/pages/apis/pdf-services/get-pdf-properties.md index a463e39f0..fb264e1b1 100644 --- a/src/pages/apis/pdf-services/get-pdf-properties.md +++ b/src/pages/apis/pdf-services/get-pdf-properties.md @@ -52,14 +52,9 @@ const { SDKError, ServiceUsageError, ServiceApiError -} = require("@dcloud/pdfservices-node-sdk"); +} = require("@adobe/pdfservices-node-sdk"); const fs = require("fs"); -/** - * This sample illustrates how to retrieve properties of an input PDF file - * - * Refer to README.md for instructions on how to run the samples. - */ (async () => { let readStream; try { @@ -75,7 +70,7 @@ const fs = require("fs"); }); // Creates an asset(s) from source file(s) and upload - readStream = fs.createReadStream("resources/pdfPropertiesInput.pdf"); + readStream = fs.createReadStream("./pdfPropertiesInput.pdf"); const inputAsset = await pdfServices.upload({ readStream, mimeType: MimeType.PDF diff --git a/src/pages/apis/pdf-services/html-to-pdf.md b/src/pages/apis/pdf-services/html-to-pdf.md index 3992b5e85..6973c3b06 100644 --- a/src/pages/apis/pdf-services/html-to-pdf.md +++ b/src/pages/apis/pdf-services/html-to-pdf.md @@ -56,15 +56,9 @@ const { SDKError, ServiceUsageError, ServiceApiError -} = require("@dcloud/pdfservices-node-sdk"); +} = require("@adobe/pdfservices-node-sdk"); const fs = require("fs"); -/** - * This sample illustrates how to convert an HTML file to PDF. The HTML file and its associated dependencies must be - * in a single ZIP file - *

- * Refer to README.md for instructions on how to run the samples. - */ (async () => { let readStream; try { @@ -80,7 +74,7 @@ const fs = require("fs"); }); // Creates an asset(s) from source file(s) and upload - readStream = fs.createReadStream("resources/createPDFFromStaticHtmlInput.zip"); + readStream = fs.createReadStream("./createPDFFromStaticHtmlInput.zip"); const inputAsset = await pdfServices.upload({ readStream, mimeType: MimeType.ZIP @@ -111,7 +105,7 @@ const fs = require("fs"); }); // Creates an output stream and copy result asset's content to it - const outputFilePath = createOutputFilePath(); + const outputFilePath = "createPdfFromStaticHtmlOutput.pdf"; console.log(`Saving asset at ${outputFilePath}`); const outputStream = fs.createWriteStream(outputFilePath); @@ -139,19 +133,6 @@ function getHTMLToPDFParams() { includeHeaderFooter: true, }); } - -// Generates a string containing a directory structure and file name for the output file -function createOutputFilePath() { - const filePath = "output/StaticHTMLToPDF/"; - const date = new Date(); - const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + - ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + - ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); - fs.mkdirSync(filePath, { - recursive: true - }); - return (`${filePath}create${dateString}.pdf`); -} ``` #### .Net diff --git a/src/pages/apis/pdf-services/insert-pdf-pages.md b/src/pages/apis/pdf-services/insert-pdf-pages.md index 73332b5ff..d4d913755 100644 --- a/src/pages/apis/pdf-services/insert-pdf-pages.md +++ b/src/pages/apis/pdf-services/insert-pdf-pages.md @@ -84,14 +84,9 @@ const { SDKError, ServiceUsageError, ServiceApiError -} = require("@dcloud/pdfservices-node-sdk"); +} = require("@adobe/pdfservices-node-sdk"); const fs = require("fs"); -/** - * This sample illustrates how to insert specific pages of multiple PDF files into a single PDF file - *

- * Refer to README.md for instructions on how to run the samples. - */ (async () => { let baseReadStream; let firstReadStreamToInsert; @@ -109,9 +104,9 @@ const fs = require("fs"); }); // Creates an asset(s) from source file(s) and upload - baseReadStream = fs.createReadStream("resources/baseInput.pdf"); - firstReadStreamToInsert = fs.createReadStream("resources/firstFileToInsertInput.pdf"); - secondReadStreamToInsert = fs.createReadStream("resources/secondFileToInsertInput.pdf"); + baseReadStream = fs.createReadStream("./baseInput.pdf"); + firstReadStreamToInsert = fs.createReadStream("./firstFileToInsertInput.pdf"); + secondReadStreamToInsert = fs.createReadStream("./secondFileToInsertInput.pdf"); const [baseAsset, firstAssetToInsert, secondAssetToInsert] = await pdfServices.uploadAssets({ streamAssets: [{ readStream: baseReadStream, @@ -160,7 +155,7 @@ const fs = require("fs"); }); // Creates an output stream and copy result asset's content to it - const outputFilePath = createOutputFilePath(); + const outputFilePath = "./insertPagesOutput.pdf"; console.log(`Saving asset at ${outputFilePath}`); const outputStream = fs.createWriteStream(outputFilePath); @@ -177,29 +172,6 @@ const fs = require("fs"); secondReadStreamToInsert?.destroy(); } })(); - -function getPageRangesForFirstFile() { - // Specify which pages of the first file are to be inserted in the base file - const pageRanges = new PageRanges(); - // Add pages 1 to 3 - pageRanges.addRange(1, 3); - // Add page 4 - pageRanges.addSinglePage(4); - return pageRanges; -} - -// Generates a string containing a directory structure and file name for the output file -function createOutputFilePath() { - const filePath = "output/InsertPages/"; - const date = new Date(); - const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + - ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + - ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); - fs.mkdirSync(filePath, { - recursive: true - }); - return (`${filePath}insert${dateString}.pdf`); -} ``` #### .Net diff --git a/src/pages/apis/pdf-services/linearize-pdf.md b/src/pages/apis/pdf-services/linearize-pdf.md index 6f7f8e69d..6f5c91f35 100644 --- a/src/pages/apis/pdf-services/linearize-pdf.md +++ b/src/pages/apis/pdf-services/linearize-pdf.md @@ -51,12 +51,6 @@ const { } = require("@dcloud/pdfservices-node-sdk"); const fs = require("fs"); -/** - * This 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. - *

- * Refer to README.md for instructions on how to run the samples. - */ (async () => { let readStream; try { @@ -72,7 +66,7 @@ const fs = require("fs"); }); // Creates an asset(s) from source file(s) and upload - readStream = fs.createReadStream("resources/linearizePDFInput.pdf"); + readStream = fs.createReadStream("./linearizePDFInput.pdf"); const inputAsset = await pdfServices.upload({ readStream, mimeType: MimeType.PDF @@ -99,7 +93,7 @@ const fs = require("fs"); }); // Creates an output stream and copy stream asset's content to it - const outputFilePath = createOutputFilePath(); + const outputFilePath = "./linearizePDFOutput.pdf"; console.log(`Saving asset at ${outputFilePath}`); const outputStream = fs.createWriteStream(outputFilePath); @@ -114,19 +108,6 @@ const fs = require("fs"); readStream?.destroy(); } })(); - -// Generates a string containing a directory structure and file name for the output file -function createOutputFilePath() { - const filePath = "output/LinearizePDF/"; - const date = new Date(); - const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + - ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + - ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); - fs.mkdirSync(filePath, { - recursive: true - }); - return (`${filePath}linearize${dateString}.pdf`); -} ``` #### .Net diff --git a/src/pages/apis/pdf-services/ocr-pdf.md b/src/pages/apis/pdf-services/ocr-pdf.md index bd9da781f..2d31f45b4 100644 --- a/src/pages/apis/pdf-services/ocr-pdf.md +++ b/src/pages/apis/pdf-services/ocr-pdf.md @@ -48,14 +48,9 @@ const { SDKError, ServiceUsageError, ServiceApiError -} = require("@dcloud/pdfservices-node-sdk"); +} = require("@adobe/pdfservices-node-sdk"); const fs = require("fs"); -/** - * This sample illustrates how to perform OCR operation on a PDF file and convert it into a searchable PDF file - *

- * Refer to README.md for instructions on how to run the samples. - */ (async () => { let readStream; try { @@ -66,26 +61,20 @@ const fs = require("fs"); }); // Creates a PDF Services instance - const pdfServices = new PDFServices({ - credentials - }); + const pdfServices = new PDFServices({credentials}); // Creates an asset(s) from source file(s) and upload - readStream = fs.createReadStream("resources/ocrInput.pdf"); + readStream = fs.createReadStream("./ocrInput.pdf"); const inputAsset = await pdfServices.upload({ readStream, mimeType: MimeType.PDF }); // Creates a new job instance - const job = new OCRJob({ - inputAsset - }); + const job = new OCRJob({inputAsset}); // Submit the job and get the job result - const pollingURL = await pdfServices.submit({ - job - }); + const pollingURL = await pdfServices.submit({job}); const pdfServicesResponse = await pdfServices.getJobResult({ pollingURL, resultType: OCRResult @@ -93,12 +82,10 @@ const fs = require("fs"); // Get content from the resulting asset(s) const resultAsset = pdfServicesResponse.result.asset; - const streamAsset = await pdfServices.getContent({ - asset: resultAsset - }); + const streamAsset = await pdfServices.getContent({asset: resultAsset}); // Creates a write stream and copy stream asset's content to it - const outputFilePath = createOutputFilePath(); + const outputFilePath = "./ocrOutput.pdf"; console.log(`Saving asset at ${outputFilePath}`); const writeStream = fs.createWriteStream(outputFilePath); @@ -113,19 +100,6 @@ const fs = require("fs"); readStream?.destroy(); } })(); - -// Generates a string containing a directory structure and file name for the output file -function createOutputFilePath() { - const filePath = "output/OCRPDF/"; - const date = new Date(); - const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + - ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + - ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); - fs.mkdirSync(filePath, { - recursive: true - }); - return (`${filePath}ocr${dateString}.pdf`); -} ``` #### .Net diff --git a/src/pages/apis/pdf-services/remove-pdf-password.md b/src/pages/apis/pdf-services/remove-pdf-password.md index 9d6824e32..26b05b073 100644 --- a/src/pages/apis/pdf-services/remove-pdf-password.md +++ b/src/pages/apis/pdf-services/remove-pdf-password.md @@ -50,14 +50,9 @@ const { SDKError, ServiceUsageError, ServiceApiError -} = require("@dcloud/pdfservices-node-sdk"); +} = require("@adobe/pdfservices-node-sdk"); const fs = require("fs"); -/** - * This sample illustrates how to remove password security from a PDF document. - *

- * Refer to README.md for instructions on how to run the samples. - */ (async () => { let readStream; try { @@ -73,7 +68,7 @@ const fs = require("fs"); }); // Creates an asset(s) from source file(s) and upload - readStream = fs.createReadStream("resources/removeProtectionInput.pdf") + readStream = fs.createReadStream("./removeProtectionInput.pdf") const inputAsset = await pdfServices.upload({ readStream, mimeType: MimeType.PDF @@ -106,7 +101,7 @@ const fs = require("fs"); }); // Creates an output stream and copy stream asset's content to it - const outputFilePath = createOutputFilePath(); + const outputFilePath = "./removeProtectionOutput.pdf"; console.log(`Saving asset at ${outputFilePath}`); const outputStream = fs.createWriteStream(outputFilePath); @@ -121,19 +116,6 @@ const fs = require("fs"); readStream?.destroy(); } })(); - -// Generates a string containing a directory structure and file name for the output file -function createOutputFilePath() { - const filePath = "output/RemoveProtection/"; - const date = new Date(); - const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + - ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + - ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); - fs.mkdirSync(filePath, { - recursive: true - }); - return (`${filePath}removeProtection${dateString}.pdf`); -} ``` #### .Net diff --git a/src/pages/apis/pdf-services/reorder-pdf-pages.md b/src/pages/apis/pdf-services/reorder-pdf-pages.md index 3831e3d16..fe861e747 100644 --- a/src/pages/apis/pdf-services/reorder-pdf-pages.md +++ b/src/pages/apis/pdf-services/reorder-pdf-pages.md @@ -68,14 +68,9 @@ const { SDKError, ServiceUsageError, ServiceApiError -} = require("@dcloud/pdfservices-node-sdk"); +} = require("@adobe/pdfservices-node-sdk"); const fs = require("fs"); -/** - * This sample illustrates how to reorder the pages in a PDF file - *

- * Refer to README.md for instructions on how to run the samples. - */ (async () => { let readStream; try { @@ -91,7 +86,7 @@ const fs = require("fs"); }); // Creates an asset(s) from source file(s) and upload - readStream = fs.createReadStream("resources/reorderPagesInput.pdf"); + readStream = fs.createReadStream("./reorderPagesInput.pdf"); const inputAsset = await pdfServices.upload({ readStream, mimeType: MimeType.PDF @@ -125,7 +120,7 @@ const fs = require("fs"); }); // Creates an output stream and copy result asset's content to it - const outputFilePath = createOutputFilePath(); + const outputFilePath = "./reorderPagesOutput.pdf"; console.log(`Saving asset at ${outputFilePath}`); const outputStream = fs.createWriteStream(outputFilePath); @@ -150,19 +145,6 @@ function getPageRangeForReorder() { pageRanges.addSinglePage(1); return pageRanges; } - -// Generates a string containing a directory structure and file name for the output file -function createOutputFilePath() { - const filePath = "output/ReorderPages/"; - const date = new Date(); - const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + - ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + - ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); - fs.mkdirSync(filePath, { - recursive: true - }); - return (`${filePath}reorder${dateString}.pdf`); -} ``` #### .Net diff --git a/src/pages/apis/pdf-services/replace-pdf-pages.md b/src/pages/apis/pdf-services/replace-pdf-pages.md index 7fbfe4b15..8393f28d9 100644 --- a/src/pages/apis/pdf-services/replace-pdf-pages.md +++ b/src/pages/apis/pdf-services/replace-pdf-pages.md @@ -75,15 +75,9 @@ const { SDKError, ServiceUsageError, ServiceApiError -} = require("@dcloud/pdfservices-node-sdk"); +} = require("@adobe/pdfservices-node-sdk"); const fs = require("fs"); -/** - * This sample illustrates how to replace specific pages in a PDF file - *

- * Refer to README.md for instructions on how to run the samples. - */ - (async () => { let baseReadStream; let readStream1; @@ -101,9 +95,9 @@ const fs = require("fs"); }); // Creates an asset(s) from source file(s) and upload - baseReadStream = fs.createReadStream("resources/baseInput.pdf"); - readStream1 = fs.createReadStream("resources/replacePagesInput1.pdf"); - readStream2 = fs.createReadStream("resources/replacePagesInput2.pdf"); + baseReadStream = fs.createReadStream("./baseInput.pdf"); + readStream1 = fs.createReadStream("./replacePagesInput1.pdf"); + readStream2 = fs.createReadStream("./replacePagesInput2.pdf"); const [baseAsset, asset1, asset2] = await pdfServices.uploadAssets({ streamAssets: [{ readStream: baseReadStream, @@ -152,7 +146,7 @@ const fs = require("fs"); }); // Creates an output stream and copy result asset's content to it - const outputFilePath = createOutputFilePath(); + const outputFilePath = "./replacePagesOutput.pdf"; console.log(`Saving asset at ${outputFilePath}`); const outputStream = fs.createWriteStream(outputFilePath); @@ -179,19 +173,6 @@ function getPageRangesForFirstFile() { pageRanges.addSinglePage(4); return pageRanges; } - -// Generates a string containing a directory structure and file name for the output file -function createOutputFilePath() { - const filePath = "output/ReplacePages/"; - const date = new Date(); - const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + - ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + - ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); - fs.mkdirSync(filePath, { - recursive: true - }); - return (`${filePath}replace${dateString}.pdf`); -} ``` #### .Net diff --git a/src/pages/apis/pdf-services/rotate-pdf-pages.md b/src/pages/apis/pdf-services/rotate-pdf-pages.md index 274180bdd..d26d91ebe 100644 --- a/src/pages/apis/pdf-services/rotate-pdf-pages.md +++ b/src/pages/apis/pdf-services/rotate-pdf-pages.md @@ -74,14 +74,9 @@ const { SDKError, ServiceUsageError, ServiceApiError -} = require("@dcloud/pdfservices-node-sdk"); +} = require("@adobe/pdfservices-node-sdk"); const fs = require("fs"); -/** - * This sample illustrates how to rotate pages in a PDF file - *

- * Refer to README.md for instructions on how to run the samples. - */ (async () => { let readStream; try { @@ -92,12 +87,10 @@ const fs = require("fs"); }); // Creates a PDF Services instance - const pdfServices = new PDFServices({ - credentials - }); + const pdfServices = new PDFServices({credentials}); // Creates an asset(s) from source file(s) and upload - readStream = fs.createReadStream("resources/rotatePagesInput.pdf"); + readStream = fs.createReadStream("./rotatePagesInput.pdf"); const inputAsset = await pdfServices.upload({ readStream, mimeType: MimeType.PDF @@ -115,15 +108,10 @@ const fs = require("fs"); .setAngleToRotatePagesBy(Angle._180, secondPageRange); // Creates a new job instance - const job = new RotatePagesJob({ - inputAsset, - params - }); + const job = new RotatePagesJob({inputAsset, params}); // Submit the job and get the job result - const pollingURL = await pdfServices.submit({ - job - }); + const pollingURL = await pdfServices.submit({job}); const pdfServicesResponse = await pdfServices.getJobResult({ pollingURL, resultType: RotatePagesResult @@ -131,12 +119,10 @@ const fs = require("fs"); // Get content from the resulting asset(s) const resultAsset = pdfServicesResponse.result.asset; - const streamAsset = await pdfServices.getContent({ - asset: resultAsset - }); + const streamAsset = await pdfServices.getContent({asset: resultAsset}); // Creates a write stream and copy stream asset's content to it - const outputFilePath = createOutputFilePath(); + const outputFilePath = "./rotatePagesOutput.pdf"; console.log(`Saving asset at ${outputFilePath}`); const writeStream = fs.createWriteStream(outputFilePath); @@ -169,19 +155,6 @@ function getSecondPageRangeForRotation() { secondPageRange.addSinglePage(2); return secondPageRange; } - -// Generates a string containing a directory structure and file name for the output file -function createOutputFilePath() { - const filePath = "output/RotatePages/"; - const date = new Date(); - const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + - ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + - ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); - fs.mkdirSync(filePath, { - recursive: true - }); - return (`${filePath}rotate${dateString}.pdf`); -} ``` #### .Net diff --git a/src/pages/apis/pdf-services/secure-pdf.md b/src/pages/apis/pdf-services/secure-pdf.md index 562387f4d..bde43b6da 100644 --- a/src/pages/apis/pdf-services/secure-pdf.md +++ b/src/pages/apis/pdf-services/secure-pdf.md @@ -52,15 +52,9 @@ const { SDKError, ServiceUsageError, ServiceApiError -} = require("@dcloud/pdfservices-node-sdk"); +} = require("@adobe/pdfservices-node-sdk"); const fs = require("fs"); -/** - * This sample illustrates how to convert a PDF file into a password protected PDF file - * The password is used for encrypting PDF contents and will be required for viewing the PDF file - *

- * Refer to README.md for instructions on how to run the samples. - */ (async () => { let readStream; try { @@ -76,7 +70,7 @@ const fs = require("fs"); }); // Creates an asset(s) from source file(s) and upload - readStream = fs.createReadStream("resources/protectPDFInput.pdf") + readStream = fs.createReadStream("./protectPDFInput.pdf") const inputAsset = await pdfServices.upload({ readStream, mimeType: MimeType.PDF @@ -110,7 +104,7 @@ const fs = require("fs"); }); // Creates an output stream and copy stream asset's content to it - const outputFilePath = createOutputFilePath(); + const outputFilePath = "./protectPDFOutput.pdf"; console.log(`Saving asset at ${outputFilePath}`); const outputStream = fs.createWriteStream(outputFilePath); @@ -125,19 +119,6 @@ const fs = require("fs"); readStream?.destroy(); } })(); - -// Generates a string containing a directory structure and file name for the output file -function createOutputFilePath() { - const filePath = "output/ProtectPDF/"; - const date = new Date(); - const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + - ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + - ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); - fs.mkdirSync(filePath, { - recursive: true - }); - return (`${filePath}protect${dateString}.pdf`); -} ``` #### .Net diff --git a/src/pages/apis/pdf-services/split-pdf.md b/src/pages/apis/pdf-services/split-pdf.md index ab860847e..f948e0882 100644 --- a/src/pages/apis/pdf-services/split-pdf.md +++ b/src/pages/apis/pdf-services/split-pdf.md @@ -52,15 +52,9 @@ const { SDKError, ServiceUsageError, ServiceApiError -} = require("@dcloud/pdfservices-node-sdk"); +} = require("@adobe/pdfservices-node-sdk"); const fs = require("fs"); -/** - * This sample illustrates how to split input PDF into multiple PDF files on the basis of the maximum number - * of pages each of the output files can have. - *

- * Refer to README.md for instructions on how to run the samples. - */ (async () => { let readStream; try { @@ -76,7 +70,7 @@ const fs = require("fs"); }); // Creates an asset(s) from source file(s) and upload - readStream = fs.createReadStream("resources/splitPDFInput.pdf") + readStream = fs.createReadStream("./splitPDFInput.pdf") const inputAsset = await pdfServices.upload({ readStream, mimeType: MimeType.PDF @@ -104,14 +98,14 @@ const fs = require("fs"); // Get content from the resulting asset(s) const resultAssets = pdfServicesResponse.result.assets; - let getOutputFilePathForIndex = createOutputFilePath(); + for (let i = 0; i < resultAssets.length; i++) { const streamAsset = await pdfServices.getContent({ asset: resultAssets[i] }); // Creates an output stream and copy stream asset's content to it - const _outputFilePath = getOutputFilePathForIndex(i); + const _outputFilePath = "./SplitPDFByNumberOfPagesOutput_" + i + ".pdf"; console.log(`Saving asset at ${_outputFilePath}`); const writeStream = fs.createWriteStream(_outputFilePath); @@ -127,19 +121,6 @@ const fs = require("fs"); readStream?.destroy(); } })(); - -// Generates a string containing a directory structure and file name for the output file -function createOutputFilePath() { - const filePath = "output/SplitPDFByNumberOfPages/"; - const date = new Date(); - const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + - ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + - ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); - fs.mkdirSync(filePath, { - recursive: true - }); - return (index) => `${filePath}split${dateString}_${index}.pdf`; -} ``` #### .Net diff --git a/src/pages/home/accessbility-auto-tag.md b/src/pages/home/accessbility-auto-tag.md index 6371d0609..82fe995ac 100644 --- a/src/pages/home/accessbility-auto-tag.md +++ b/src/pages/home/accessbility-auto-tag.md @@ -36,17 +36,9 @@ const { MimeType, AutotagPDFJob, AutotagPDFResult, - SDKError, - ServiceUsageError, - ServiceApiError -} = require("@dcloud/pdfservices-node-sdk"); +} = require("@adobe/pdfservices-node-sdk"); const fs = require("fs"); -/** - * This sample illustrates how to generate a tagged PDF. - *

- * Refer to README.md for instructions on how to run the samples. - */ (async () => { let readStream; try { @@ -62,7 +54,7 @@ const fs = require("fs"); }); // Creates an asset(s) from source file(s) and upload - readStream = fs.createReadStream("resources/autotagPDFInput.pdf"); + readStream = fs.createReadStream("./autotagPDFInput.pdf"); const inputAsset = await pdfServices.upload({ readStream, mimeType: MimeType.PDF @@ -89,11 +81,11 @@ const fs = require("fs"); }); // Creates an output stream and copy stream asset's content to it - const outputFilePath = createOutputFilePath(); + const outputFilePath = "./autotag-tagged.pdf"; console.log(`Saving asset at ${outputFilePath}`); - const outputStream = fs.createWriteStream(outputFilePath); - streamAsset.readStream.pipe(outputStream); + let writeStream = fs.createWriteStream(outputFilePath); + streamAsset.readStream.pipe(writeStream); } catch (err) { if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) { console.log("Exception encountered while executing operation", err); @@ -104,19 +96,6 @@ const fs = require("fs"); readStream?.destroy(); } })(); - -// Generates a string containing a directory structure and file name for the output file -function createOutputFilePath() { - const filePath = "output/AutotagPDF/"; - const date = new Date(); - const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + - ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + - ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); - fs.mkdirSync(filePath, { - recursive: true - }); - return (`${filePath}autotag${dateString}.pdf`); -} ``` #### .Net diff --git a/src/pages/home/create-pdf-from-url.md b/src/pages/home/create-pdf-from-url.md index 149ae9fc6..8ddbdcffa 100644 --- a/src/pages/home/create-pdf-from-url.md +++ b/src/pages/home/create-pdf-from-url.md @@ -31,7 +31,7 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/createpd ```js // Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample // Run the sample: -// node src/createpdf/create-pdf-from-docx.js +// node src/createpdf/create-pdf-from-docx.js const { ServicePrincipalCredentials, @@ -42,14 +42,9 @@ const { SDKError, ServiceUsageError, ServiceApiError -} = require("@dcloud/pdfservices-node-sdk"); +} = require("@adobe/pdfservices-node-sdk"); const fs = require("fs"); -/** - * This sample illustrates how to create a PDF file from a DOCX file. - *

- * Refer to README.md for instructions on how to run the samples. - */ (async () => { let readStream; try { @@ -65,7 +60,7 @@ const fs = require("fs"); }); // Creates an asset(s) from source file(s) and upload - readStream = fs.createReadStream("resources/createPDFInput.docx"); + readStream = fs.createReadStream("./createPDFInput.docx"); const inputAsset = await pdfServices.upload({ readStream, mimeType: MimeType.DOCX @@ -92,7 +87,7 @@ const fs = require("fs"); }); // Creates an output stream and copy result asset's content to it - const outputFilePath = createOutputFilePath(); + const outputFilePath = "./createPDFFromDOCX.pdf"; console.log(`Saving asset at ${outputFilePath}`); const outputStream = fs.createWriteStream(outputFilePath); @@ -107,19 +102,6 @@ const fs = require("fs"); readStream?.destroy(); } })(); - -// Generates a string containing a directory structure and file name for the output file -function createOutputFilePath() { - const filePath = "output/CreatePDFFromDOCX/"; - const date = new Date(); - const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + - ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + - ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); - fs.mkdirSync(filePath, { - recursive: true - }); - return (`${filePath}create${dateString}.pdf`); -} ``` #### .Net diff --git a/src/pages/home/dynamic-pdf-document-generation.md b/src/pages/home/dynamic-pdf-document-generation.md index 8ec2c60e7..7aa151220 100644 --- a/src/pages/home/dynamic-pdf-document-generation.md +++ b/src/pages/home/dynamic-pdf-document-generation.md @@ -69,17 +69,9 @@ const { SDKError, ServiceUsageError, ServiceApiError -} = require("@dcloud/pdfservices-node-sdk"); +} = require("@adobe/pdfservices-node-sdk"); const fs = require("fs"); -/** - * This sample illustrates how to merge the Word based document template with the input JSON data to generate - * the output document in the PDF format. - *

- * To know more about document generation and document templates, please see the documentation - *

- * Refer to README.md for instructions on how to run the samples. - */ (async () => { let readStream; try { @@ -94,19 +86,22 @@ const fs = require("fs"); credentials }); + // Setup input data for the document merge process + const jsonDataForMerge = { + customerName: "Kane Miller", + customerVisits: 100 + } + // Creates an asset(s) from source file(s) and upload - readStream = fs.createReadStream("resources/salesOrderTemplate.docx"); + readStream = fs.createReadStream("./documentMergeTemplate.docx"); const inputAsset = await pdfServices.upload({ readStream, mimeType: MimeType.DOCX }); - // Setup input data for the document merge process - const jsonString = fs.readFileSync('resources/salesOrder.json', 'utf-8'); - // Create parameters for the job const params = new DocumentMergeParams({ - jsonDataForMerge: JSON.parse(jsonString), + jsonDataForMerge, outputFormat: OutputFormat.PDF }); @@ -132,7 +127,7 @@ const fs = require("fs"); }); // Creates a write stream and copy stream asset's content to it - const outputFilePath = createOutputFilePath(); + const outputFilePath = "./documentMergeOutput.pdf"; console.log(`Saving asset at ${outputFilePath}`); const writeStream = fs.createWriteStream(outputFilePath); @@ -147,19 +142,6 @@ const fs = require("fs"); readStream?.destroy(); } })(); - -// Generates a string containing a directory structure and file name for the output file -function createOutputFilePath() { - const filePath = "output/MergeDocumentToPDF/"; - const date = new Date(); - const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + - ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + - ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); - fs.mkdirSync(filePath, { - recursive: true - }); - return (`${filePath}merge${dateString}.pdf`); -} ``` #### .Net diff --git a/src/pages/home/e-seal.md b/src/pages/home/e-seal.md index 2ec10c025..6de4aa3c5 100644 --- a/src/pages/home/e-seal.md +++ b/src/pages/home/e-seal.md @@ -79,17 +79,9 @@ const { SDKError, ServiceUsageError, ServiceApiError -} = require("@dcloud/pdfservices-node-sdk"); +} = require("@adobe/pdfservices-node-sdk"); const fs = require("fs"); -/** - * This sample illustrates how to apply electronic seal over the PDF document using default appearance options. - * - *

- * To know more about PDF Electronic Seal, please see the <documentation. - *

- * Refer to README.md for instructions on how to run the samples. - */ (async () => { let sourceFileReadStream; let sealImageReadStream; @@ -106,8 +98,8 @@ const fs = require("fs"); }); // Creates an asset(s) from source file(s) and upload - sourceFileReadStream = fs.createReadStream("resources/sampleInvoice.pdf") - sealImageReadStream = fs.createReadStream("resources/sampleSealImage.png"); + sourceFileReadStream = fs.createReadStream("./sampleInvoice.pdf") + sealImageReadStream = fs.createReadStream("./sampleSealImage.png"); const [sourceFileAsset, sealImageAsset] = await pdfServices.uploadAssets({ streamAssets: [{ readStream: sourceFileReadStream, @@ -202,7 +194,7 @@ const fs = require("fs"); }); // Creates a write stream and copy stream asset's content to it - const outputFilePath = createOutputFilePath(); + const outputFilePath = "./sealedOutput.pdf"; console.log(`Saving asset at ${outputFilePath}`); const writeStream = fs.createWriteStream(outputFilePath); @@ -218,19 +210,6 @@ const fs = require("fs"); sealImageReadStream?.destroy(); } })(); - -// Generates a string containing a directory structure and file name for the output file -function createOutputFilePath() { - const filePath = "output/ElectronicSeal/"; - const date = new Date(); - const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + - ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + - ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); - fs.mkdirSync(filePath, { - recursive: true - }); - return (`${filePath}seal${dateString}.pdf`); -} ``` #### .Net diff --git a/src/pages/home/pdf-content-structure.md b/src/pages/home/pdf-content-structure.md index f68bef85e..01a33cf5a 100644 --- a/src/pages/home/pdf-content-structure.md +++ b/src/pages/home/pdf-content-structure.md @@ -47,14 +47,9 @@ const { SDKError, ServiceUsageError, ServiceApiError -} = require("@dcloud/pdfservices-node-sdk"); +} = require("@adobe/pdfservices-node-sdk"); const fs = require("fs"); -/** - * This sample illustrates how to extract Text Information from PDF. - *

- * Refer to README.md for instructions on how to run the samples & understand output zip file - */ (async () => { let readStream; try { @@ -70,7 +65,7 @@ const fs = require("fs"); }); // Creates an asset(s) from source file(s) and upload - readStream = fs.createReadStream("resources/extractPDFInput.pdf"); + readStream = fs.createReadStream("./extractPDFInput.pdf"); const inputAsset = await pdfServices.upload({ readStream, mimeType: MimeType.PDF @@ -103,7 +98,7 @@ const fs = require("fs"); }); // Creates a write stream and copy stream asset's content to it - const outputFilePath = createOutputFilePath(); + const outputFilePath = "./ExtractTextInfoFromPDF.zip"; console.log(`Saving asset at ${outputFilePath}`); const writeStream = fs.createWriteStream(outputFilePath); @@ -118,19 +113,6 @@ const fs = require("fs"); readStream?.destroy(); } })(); - -// Generates a string containing a directory structure and file name for the output file -function createOutputFilePath() { - const filePath = "output/ExtractTextInfoFromPDF/"; - const date = new Date(); - const dateString = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + - ("0" + date.getDate()).slice(-2) + "T" + ("0" + date.getHours()).slice(-2) + "-" + - ("0" + date.getMinutes()).slice(-2) + "-" + ("0" + date.getSeconds()).slice(-2); - fs.mkdirSync(filePath, { - recursive: true - }); - return (`${filePath}extract${dateString}.zip`); -} ``` #### .Net From 35b56f6e13fd2c19b38be14f1b92a9b54d012743 Mon Sep 17 00:00:00 2001 From: Vignesh Date: Fri, 22 Mar 2024 15:33:36 +0530 Subject: [PATCH 4/5] Updated the pdf auto tag api node js script --- src/pages/apis/pdf-services/accessibility-auto-tag-api.md | 3 +++ src/pages/home/accessbility-auto-tag.md | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/pages/apis/pdf-services/accessibility-auto-tag-api.md b/src/pages/apis/pdf-services/accessibility-auto-tag-api.md index a0a5e3c2b..7c879c739 100644 --- a/src/pages/apis/pdf-services/accessibility-auto-tag-api.md +++ b/src/pages/apis/pdf-services/accessibility-auto-tag-api.md @@ -42,6 +42,9 @@ const { MimeType, AutotagPDFJob, AutotagPDFResult, + SDKError, + ServiceUsageError, + ServiceApiError, } = require("@adobe/pdfservices-node-sdk"); const fs = require("fs"); diff --git a/src/pages/home/accessbility-auto-tag.md b/src/pages/home/accessbility-auto-tag.md index 82fe995ac..04963a39a 100644 --- a/src/pages/home/accessbility-auto-tag.md +++ b/src/pages/home/accessbility-auto-tag.md @@ -36,6 +36,9 @@ const { MimeType, AutotagPDFJob, AutotagPDFResult, + SDKError, + ServiceUsageError, + ServiceApiError, } = require("@adobe/pdfservices-node-sdk"); const fs = require("fs"); From f8a9e6d0fe9726b5317bd531eaf57fa06d375a2d Mon Sep 17 00:00:00 2001 From: Vignesh Date: Mon, 1 Apr 2024 12:26:24 +0530 Subject: [PATCH 5/5] --Removed the Sign API --- src/pages/apis/sign-api.md | 3 --- src/pages/apis/sign-api/partner-with-us.md | 10 ---------- 2 files changed, 13 deletions(-) delete mode 100644 src/pages/apis/sign-api/partner-with-us.md diff --git a/src/pages/apis/sign-api.md b/src/pages/apis/sign-api.md index 74ff367b8..51c6a433a 100644 --- a/src/pages/apis/sign-api.md +++ b/src/pages/apis/sign-api.md @@ -2,7 +2,6 @@ title: Acrobat Sign API | Easy and Secure eSignature API description: Secure, powerful, and easy to use APIs to integrate e-signatures into your platform, app, or workflow quickly. --- -import PartnerWithUsBlade from './sign-api/partner-with-us.md' import TakeYourProject from './sign-api/take-your-project-nxt-lvl.md' import TakeYourProjectCont from './sign-api/take-your-project-content.md' import PartnershipType from './sign-api/partnership-type.md' @@ -23,8 +22,6 @@ apiHeroAssetImg sign-api-hero - [Create account](https://www.adobe.com/sign/developer-form.html) - [View documentation](https://opensource.adobe.com/acrobat-sign/developer_guide/) - - diff --git a/src/pages/apis/sign-api/partner-with-us.md b/src/pages/apis/sign-api/partner-with-us.md deleted file mode 100644 index 9b58f041c..000000000 --- a/src/pages/apis/sign-api/partner-with-us.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: Acrobat Sign API | Easy and Secure eSignature API -description: Secure, powerful, and easy to use APIs to integrate e-signatures into your platform, app, or workflow quickly. ---- - - - -Let's work together to build incredible digital experiences. - -- [Partner with us](https://partners.adobe.com/exchangeprogram/documentcloud/prereg.html)