Code Monkey home page Code Monkey logo

pdfservices-node-sdk-samples's Introduction

Samples for the PDF Services Node.js SDK

This sample project helps you get started with the PDF Services Node.js SDK.

The sample JS scripts illustrate how to perform PDF-related actions (such as converting to and from the PDF format) using the SDK. Please note that the PDF Services Node.js SDK supports only server side use cases.

Prerequisites

The sample application has the following requirements:

  • Node.js : Version 18.0 or above. Node installation instructions can be found here.

Authentication Setup

The credentials file for the samples is pdfservices-api-credentials.json. Before the samples can be run, set the environment variables PDF_SERVICES_CLIENT_ID and PDF_SERVICES_CLIENT_SECRET from the pdfservices-api-credentials.json file downloaded at the end of creation of credentials via Get Started workflow by running the following commands :

  1. For MacOS/Linux Users :
export PDF_SERVICES_CLIENT_ID=<YOUR CLIENT ID>
export PDF_SERVICES_CLIENT_SECRET=<YOUR CLIENT SECRET>
  1. For Windows Users :
set PDF_SERVICES_CLIENT_ID=<YOUR CLIENT ID>
set PDF_SERVICES_CLIENT_SECRET=<YOUR CLIENT SECRET>

Client Configurations

The SDK supports setting up custom request timeout for the API calls. Please refer this section to know more.

The SDK also supports setting up Proxy Server configurations which helps in successful API calls for network where all outgoing calls have to go through a proxy else, they are blocked. Please refer this section to know more.

Additionally, SDK can be configured to process the documents in the specified region. Please refer this section section to know more.

Quota Exhaustion

If you receive ServiceUsageError during the Samples run, it means that trial credentials have exhausted their usage quota. Please contact us to get paid credentials.

Build with npm

Run the following command to build the project:

npm install

Note that the PDF Services SDK is listed as a dependency in the package.json and will be downloaded automatically.

A Note on Logging

For logging, this SDK uses the log4js API . Upon running, the SDK searches for a file config/pdfservices-sdk-log4js-config.json in the working directory, and reads the logging properties from there. If no configuration file is provided, default logging, i.e. logging INFO logs to the console is enabled. The clients can change the logging settings as per their needs.

Running the samples

The following sub-sections describe how to run the samples. Prior to running the samples, check that the configuration file is set up as described above and that the project has been built.

The samples code is available under the src folder. Test files used by the samples can be found in the resources folder. When executed, all samples create an output child folder under the project root directory to store their results.

Create a PDF File

These samples illustrate how to convert files of some formats to PDF. Refer the sdk documentation of create-pdf-operation.js to see the list of all supported media types which can be converted to PDF.

Create a PDF File From a DOCX File

The sample script create-pdf-from-docx.js creates a PDF file from a DOCX file.

node src/createpdf/create-pdf-from-docx.js

Create a PDF File From a DOCX File with options

The sample script create-pdf-from-docx-with-options.js creates a PDF file from a DOCX file by setting documentLanguage as the language of input file.

node src/createpdf/create-pdf-from-docx-with-options.js

Create a PDF File From a PPTX File

The sample script create-pdf-from-pptx.js creates a PDF file from a PPTX file.

node src/createpdf/create-pdf-from-pptx.js

Create a PDF File From HTML

These samples illustrate how to convert HTML to PDF. Refer the HTML to PDF API documentation to see instructions on the structure of the zip file.

Create a PDF File From Static HTML file with inline CSS

The sample script html-with-inline-css-to-pdf.js creates a PDF file from an input HTML file with inline CSS.

node src/htmltopdf/html-with-inline-css-to-pdf.js

Create a PDF File From HTML specified via URL

The sample script html-to-pdf-from-url.js creates a PDF file from an HTML specified via URL.

node src/htmltopdf/html-to-pdf-from-url.js

Create a PDF File From Static HTML (via Zip Archive)

The sample script static-html-to-pdf.js creates a PDF file from a zip file containing the input HTML file and its resources. Please refer the sdk documentation of create-pdf-operation.js to see instructions on the structure of the zip file.

node src/htmltopdf/static-html-to-pdf.js

Create a PDF File From Dynamic HTML (via Zip Archive)

The sample script dynamic-html-to-pdf.js converts a zip file, containing the input HTML file and its resources, along with the input data to a PDF file. The input data is used by the javascript in the HTML file to manipulate the HTML DOM, thus effectively updating the source HTML file. This mechanism can be used to provide data to the template HTML dynamically and then, convert it into a PDF file.

node src/htmltopdf/dynamic-html-to-pdf.js

Export PDF To Other Formats

These samples illustrate how to export PDF files to other formats. Refer to the documentation of export-pdf-operation.js and export-pdf-to-images-operation.js for supported export formats.

Export a PDF File To a DOCX File

The sample script export-pdf-to-docx.js converts a PDF file to a DOCX file.

node src/exportpdf/export-pdf-to-docx.js

Export a PDF file to a DOCX file (apply OCR on the PDF file)

The sample script export-pdf-to-docx-with-ocr-options.js converts a PDF file to a DOCX file. OCR processing is also performed on the input PDF file to extract text from images in the document.

node src/exportpdf/export-pdf-to-docx-with-ocr-options.js

Export a PDF File To an Image Format (JPEG)

The sample script export-pdf-to-jpeg.js converts a PDF file's pages to a list of JPEG images.

node src/exportpdftoimages/export-pdf-to-jpeg.js

Export a PDF File To a Zip of Images (JPEG)

The sample script export-pdf-to-jpeg-zip.js converts a PDF file's pages to JPEG images. The resulting file is a ZIP archive containing one image per page of the source PDF file.

node src/exportpdftoimages/export-pdf-to-jpeg-zip.js

Combine PDF Files

These samples illustrate how to combine multiple PDF files into a single PDF file.

Combine Multiple PDF Files

The sample script combine-pdf.js combines multiple PDF files into a single PDF file. The combined PDF file contains all pages of the source files.

node src/combinepdf/combine-pdf.js

Combine Specific Pages of Multiple PDF Files

The sample script combine-pdf-with-page-ranges.js combines specific pages of multiple PDF files into into a single PDF file.

node src/combinepdf/combine-pdf-with-page-ranges.js

OCR PDF File

These samples illustrate how to apply OCR(Optical Character Recognition) to a PDF file and convert it to a searchable copy of your PDF. The supported input format is application/pdf.

Convert a PDF File into a Searchable PDF File

The sample script ocr-pdf.js converts a PDF file into a searchable PDF file.

node src/ocr/ocr-pdf.js

Convert a PDF File into a Searchable PDF File while keeping the original image

The sample script ocr-pdf-with-options.js converts a PDF file to a searchable PDF file with maximum fidelity to the original image and default en-us locale. Refer to the documentation of ocr-options.js to see the list of supported OCR locales and OCR types.

node src/ocr/ocr-pdf-with-options.js

Compress PDF File

The sample illustrates how to reduce the size of a PDF file.

Reduce PDF File Size

The sample script compress-pdf.js reduces the size of a PDF file.

node src/compresspdf/compress-pdf.js

Reduce PDF File Size on the basis of Compression Level

The sample script compress-pdf-with-options.js reduces the size of a PDF file on the basis of provided compression level. Refer to the documentation of compress-pdf-options.js to see the list of supported compression levels.

node src/compresspdf/compress-pdf-with-options.js

Linearize PDF File

The sample illustrates how to convert a PDF file into a Linearized (also known as "web optimized") PDF file. Such PDF files are optimized for incremental access in network environments.

Convert a PDF File into a Web Optimized File

The sample script linearize-pdf.js optimizes the PDF file for a faster Web View.

node src/linearizepdf/linearize-pdf.js

Protect PDF File

These samples illustrate how to secure a PDF file with a password.

Convert a PDF File into a Password Protected PDF File

The sample script protect-pdf.js converts a PDF file into a password protected PDF file.

node src/protectpdf/protect-pdf.js

Protect a PDF File with an Owner Password and Permissions

The sample script protect-pdf-with-owner-password.js secures an input PDF file with owner password and allows certain access permissions such as copying and editing the contents, and printing of the document at low resolution.

node src/protectpdf/protect-pdf-with-owner-password.js

Remove Protection

The sample illustrates how to remove a password security from a PDF document.

Remove Protection from a PDF File

The sample script remove-protection.js removes a password security from a secured PDF document.

node src/removeprotection/remove-protection.js

Rotate Pages

The sample illustrates how to rotate pages in a PDF file.

Rotate Pages in PDF File

The sample script rotate-pdf-pages.js rotates specific pages in a PDF file.

node src/rotatepages/rotate-pdf-pages.js

Delete Pages

The sample illustrates how to delete pages in a PDF file.

Delete Pages from PDF File

The sample script delete-pdf-pages.js removes specific pages from a PDF file.

node src/deletepages/delete-pdf-pages.js

Reorder Pages

The sample illustrates how to reorder the pages in a PDF file.

Reorder Pages in PDF File

The sample script reorder-pdf-pages.js rearranges the pages of a PDF file according to the specified order.

node src/reorderpages/reorder-pdf-pages.js

Insert Pages

The sample illustrates how to insert pages in a PDF file.

Insert Pages into a PDF File

The sample script insert-pdf-pages.js inserts pages of multiple PDF files into a base PDF file.

node src/insertpages/insert-pdf-pages.js

Replace Pages

The sample illustrates how to replace pages of a PDF file.

Replace PDF File Pages with Multiple PDF Files

The sample script replace-pdf-pages.js replaces specific pages in a PDF file with pages from multiple PDF files.

node src/replacepages/replace-pdf-pages.js

Split PDF File

These samples illustrate how to split PDF file into multiple PDF files.

Split PDF By Number of Pages

The sample script split-pdf-by-number-of-pages.js splits input PDF into multiple PDF files on the basis of the maximum number of pages each of the output files can have.

node src/splitpdf/split-pdf-by-number-of-pages.js

Split PDF Into Number of PDF Files

The sample script split-pdf-into-number-of-files.js splits input PDF into multiple PDF files on the basis of the number of documents.

node src/splitpdf/split-pdf-into-number-of-files.js

Split PDF By Page Ranges

The sample script split-pdf-by-page-ranges.js splits input PDF into multiple PDF files on the basis of page ranges. Each page range corresponds to a single output file having the pages specified in the page range.

node src/splitpdf/split-pdf-by-page-ranges.js

Document Merge

Adobe Document Merge Operation allows you to produce high fidelity PDF and Word documents with dynamic data inputs. Using this operation, you can merge your JSON data with Word templates to create dynamic documents for contracts and agreements, invoices, proposals, reports, forms, branded marketing documents and more. To know more about document generation and document templates, please checkout the documentation

Merge Document to DOCX

The sample script merge-document-to-docx.js merges the Word based document template with the input JSON data to generate the output document in the DOCX format

node src/documentmerge/merge-document-to-docx.js

Merge Document to PDF

This sample script merge-document-to-pdf.js merges the Word based document template with the input JSON data to generate the output document in the PDF format.

node src/documentmerge/merge-document-to-pdf.js

Merge Document to DOCX with Fragments

This sample script merge-document-to-docx-fragments.js merges the Word based document template with the input JSON data and Fragments JSON to generate the output document in the PDF format.

node src/documentmerge/merge-document-to-docx-fragments.js

PDF Electronic Seal

These samples illustrate how to perform electronic seal over PDF documents like agreements, invoices, proposals, reports, forms, branded marketing documents and more. To know more about PDF Electronic Seal, please see the documentation. The following details needs to updated while executing these samples: PROVIDER_NAME, ACCESS_TOKEN, CREDENTIAL_ID and PIN.

Apply Electronic Seal

This sample script electronic-seal.js uses the sealing options with default appearance options to apply electronic seal over the PDF document.

node src/electronicseal/electronic-seal.js

Apply Electronic Seal With Custom Appearance Options

This sample script electronic-seal-with-appearance-options.js uses the sealing options with custom appearance options to apply electronic seal over the PDF document.

node src/electronicseal/electronic-seal-with-appearance-options.js

Apply Electronic Seal With Trusted Timestamp

The sample script electronic-seal-with-stamp-authority.js uses a time stamp authority to apply electronic seal with trusted timestamp over the PDF document.

node src/electronicseal/electronic-seal-with-stamp-authority.js

Extract PDF

These samples illustrate extracting content of PDF in a structured JSON format along with the renditions inside PDF. The output of SDK extract operation is Zip package. The Zip package consists of following:

  • The structuredData.json file with the extracted content & PDF element structure. See the JSON schema. Please refer the Styling JSON schema for a description of the output when the styling option is enabled.
  • A renditions folder(s) containing renditions for each element type selected as input. The folder name is either “tables” or “figures” depending on your specified element type. Each folder contains renditions with filenames that correspond to the element information in the JSON file.

Extract Text Elements

The sample script extract-text-info-from-pdf.js extracts text elements from PDF document.

node src/extractpdf/extract-text-info-from-pdf.js

Extract Text, Table Elements

The sample script extract-text-table-info-from-pdf.js extracts text, table elements from PDF document.

node src/extractpdf/extract-text-table-info-from-pdf.js

Extract Text, Table Elements with Renditions of Table Elements

The sample script extract-text-table-info-with-tables-renditions-from-pdf.js extracts text, table elements along with table renditions from PDF document. Note that the output is a zip containing the structured information along with renditions as described in section.

node src/extractpdf/extract-text-table-info-with-tables-renditions-from-pdf.js

Extract Text, Table Elements with Renditions of Figure, Table Elements

The sample script extract-text-table-info-with-figures-tables-renditions-from-pdf.js extracts text, table elements along with figure and table element's renditions from PDF document. Note that the output is a zip containing the structured information along with renditions as described in section.

node src/extractpdf/extract-text-table-info-with-figures-tables-renditions-from-pdf.js

Extract Text Elements and bounding boxes for Characters present in text blocks

The sample script extract-text-table-info-with-char-bounds-from-pdf.js extracts text elements and bounding boxes for characters present in text blocks. Note that the output is a zip containing the structured information along with renditions as described in section.

node src/extractpdf/extract-text-table-info-with-char-bounds-from-pdf.js

Extract Text, Table Elements and bounding boxes for Characters present in text blocks with Renditions of Table Elements

The sample script extract-text-table-info-with-char-bounds-from-pdf.js extracts text, table elements, bounding boxes for characters present in text blocks and table element's renditions from PDF document. Note that the output is a zip containing the structured information along with renditions as described in section.

node src/extractpdf/extract-text-table-info-with-char-bounds-from-pdf.js

Extract Text, Table Elements with Renditions and CSV's of Table Elements

The sample script extract-text-table-info-with-tables-structure-from-pdf.js extracts text, table elements, table structures as CSV and table element's renditions from PDF document. Note that the output is a zip containing the structured information along with renditions as described in section.

node src/extractpdf/extract-text-table-info-with-tables-structure-from-pdf.js

Extract Text, Table Elements with Styling information of text

The sample script extract-text-table-info-with-styling-info-from-pdf extracts text and table elements along with the styling information of the text blocks. Note that the output is a zip containing the structured information along with renditions as described in section.

node src/extractpdf/extract-text-table-info-with-styling-info-from-pdf.js

PDF Properties

This sample illustrates how to fetch properties of a PDF file.

Fetch PDF Properties

The sample script get-pdf-properties.js fetches the properties of an input PDF.

node src/pdfproperties/get-pdf-properties.js

Custom Client Configuration

These samples illustrate how to provide a custom client configurations(timeouts, proxy etc.).

Create a PDF File From a DOCX File (By providing custom value for timeouts)

The sample script create-pdf-with-custom-timeouts highlights how to provide the custom value for timeout.

node src/customconfigurations/create-pdf-with-custom-timeouts.js

Create a PDF File From a DOCX File (By providing Proxy Server settings)

The sample script create-pdf-with-proxy-server.js highlights how to provide Proxy Server configurations to allow all API calls via that proxy Server.

node src/customconfigurations/create-pdf-with-proxy-server.js

Create a PDF File From a DOCX File (By providing Proxy Server settings with authentication)

The sample script create-pdf-with-authenticated-proxy-server.js highlights how to provide Proxy Server configurations to allow all API calls via that proxy Server that requires authentication.

node src/customconfigurations/create-pdf-with-authenticated-proxy-server.js

Export a PDF File to a DOCX File (By providing the region)

The sample script export-pdf-with-specified-region.js highlights how to configure the SDK to process the documents in the specified region.

node src/customconfigurations/export-pdf-with-specified-region.js

Create Tagged PDF

These samples illustrate how to create a PDF document with enhanced readability from existing PDF document. All tags from the input file will be removed except for existing alt-text images and a new tagged PDF will be created as output. However, the generated PDF is not guaranteed to comply with accessibility standards such as WCAG and PDF/UA as you may need to perform further downstream remediation to meet those standards.

Create Tagged PDF from a PDF

The sample script autotag-pdf highlights how to add tags to PDF document to make the PDF more accessible.

node src/autotag/autotag-pdf.js

Create Tagged PDF from a PDF along with a report and shift the headings in the output PDF file

The sample script autotag-pdf-with-options highlights how to add tags to PDF documents to make the PDF more accessible and also shift the headings in the output PDF file. Also, it generates a tagging report which contains the information about the tags that the tagged output PDF document contains.

node src/autotag/autotag-pdf-with-options.js

Create Tagged PDF from a PDF by setting options with command line arguments

The sample script autotag-pdf-parameterised highlights how to add tags to PDF documents to make the PDF more accessible by setting options through command line arguments.

Here is a sample list of command line arguments and their description:
--input < input file path >
--output < output file path >
--report { If this argument is present then the output will be generated with the tagging report }
--shift_headings { If this argument is present then the headings will be shifted in the output PDF document }

node src/autotag/autotag-pdf-parameterised.js --report --shift_headings --input resources/autotagPdfInput.pdf --output output/

External Input / Output Storage

These samples illustrate how to use external input and output storage for the supported operations.

Create a PDF File From a DOCX File Using External Input Storage

The sample script external-input-create-pdf-from-docx.js creates a PDF file from a DOCX file stored at external storage.

node src/externalstorage/external-input-create-pdf-from-docx.js

Create a PDF File From a DOCX File Using External Input Storage and Store the Result in External Output Storage

The sample script external-input-and-output-create-pdf-from-docx.js creates a PDF file from a DOCX file stored at external storage and stores the result in external output storage.

node src/externalstorage/external-input-and-output-create-pdf-from-docx.js

Licensing

This project is licensed under the MIT License. See LICENSE for more information.

pdfservices-node-sdk-samples's People

Contributors

abhigamb avatar adityaganotra avatar anubhav-mhjn avatar hitesh-kumar-mahour avatar jasnoors avatar khushboobaheti avatar nconder avatar piyuverma avatar piyverma avatar pulkit-maheshwr avatar vardhi avatar varkumaradobe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pdfservices-node-sdk-samples's Issues

Using extract-text-info-from-pdf with font Times New Roman-13299 not transform good

Hey when I use extract-text-info-from-pdf with pdf file with font Times New Roman-13299 and the text is in Hebrew language the text output is not good, I Get : 09/2023 tlli1n7 l:ltll tll17n 02/ .
Now if the font was just Times New Roman the output is good.
The same happen when I copy paste the text from the Adobe Acrobat Pro DC software or when I change the font not only when I try to convert the text by code.
Some how the used font used corresponds to the display in its use and trying to convert it destroys the information.

how to parse scan pdf with Chinese?

Expected Behaviour

I parse scan pdf with Chinese, the result can't understand

Platform and Version

python-3.8.13

Sample Code that illustrates the problem

`
import logging
import os.path as osp
import os
import re

import PyPDF2
from PyPDF2 import PdfReader
from adobe.pdfservices.operation.auth.credentials import Credentials
from adobe.pdfservices.operation.client_config import ClientConfig
from adobe.pdfservices.operation.exception.exceptions import ServiceApiException, ServiceUsageException, SdkException
from adobe.pdfservices.operation.pdfops.options.extractpdf.extract_pdf_options import ExtractPDFOptions
from adobe.pdfservices.operation.pdfops.options.extractpdf.extract_element_type import ExtractElementType
from adobe.pdfservices.operation.execution_context import ExecutionContext
from adobe.pdfservices.operation.io.file_ref import FileRef
from adobe.pdfservices.operation.pdfops.extract_pdf_operation import ExtractPDFOperation
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))

def parse(pdfile, jsonfile, fp):
try:
# get base path.
base_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(file))))
# Initial setup, create credentials instance.
credentials = Credentials.service_account_credentials_builder()
.from_file(base_path + "/pdfservices-api-credentials.json")
.build()
client_config = ClientConfig.builder().with_connect_timeout(10000).with_read_timeout(1000000)
.build()
# Create an ExecutionContext using credentials and create a new operation instance.
execution_context = ExecutionContext.create(credentials, client_config)
extract_pdf_operation = ExtractPDFOperation.create_new()

    # Set operation input from a source file.
    source = FileRef.create_from_local_file(pdfile)
    print(source)
    extract_pdf_operation.set_input(source)

    # Build ExtractPDF options and set them into the operation
    extract_pdf_options: ExtractPDFOptions = ExtractPDFOptions.builder() \
        .with_element_to_extract(ExtractElementType.TEXT) \
        .build()
    extract_pdf_operation.set_options(extract_pdf_options)

    # Execute the operation.
    result: FileRef = extract_pdf_operation.execute(execution_context)

    # Save the result to the specified location.
    print(jsonfile)
    result.save_as(jsonfile)
    fp.write(pdfname+' success'+'\n')
except (ServiceApiException, SdkException):
    logging.exception("Exception encountered while executing operation")
    fp.write(pdfname+' failed'+'\n')

pdfname = './test.pdf'
jsonname = './test.zip'
parse(pdfname, jsonname, fp)
`

Logs taken while reproducing problem

the json file can't encode.
test.zip

HTML-Conversion unsupported: Operation cannot be performed on the specified input media type : text/html

Error: Operation cannot be performed on the specified input media type : text/html
at validateAllowedMediaType (/var/task/node_modules/@adobe/documentservices-pdftools-node-sdk/src/internal/util/validation-util.js:86:9)
at CreatePDFOperation.validate (/var/task/node_modules/@adobe/documentservices-pdftools-node-sdk/src/operation/create-pdf-operation.js:414:3)
at CreatePDFOperation.execute (/var/task/node_modules/@adobe/documentservices-pdftools-node-sdk/src/operation/create-pdf-operation.js:397:9)

Expected Behaviour

Convert html content to a PDF file

Actual Behaviour

Throw an exception

Reproduce Scenario (including but not limited to)

PDFToolsSdk.FileRef.createFromStream(Readable.from([htmlContent]),'text/html')

Steps to Reproduce

PDFToolsSdk.FileRef.createFromStream(Readable.from([htmlContent]),'text/html')

Platform and Version

Docker (Amazon Linux 2)

Sample Code that illustrates the problem

PDFToolsSdk.FileRef.createFromStream(Readable.from([htmlContent]),'text/html')

Unable to use in Angular App

I recently came across this repo and trying to implement it in an Angular application. Below are my queries in this regard.

  1. Can this npm package be used in an angular application ? Is it recommended ?

  2. I don't see a typescript definition file for this package. Is there one available ?

  3. I signed up for account access and received the required credentials. I added the required logic to generate PDF in a small angular application and when I compiled the code, I ran into below issues. Can you let me know the reason for below errors ?

    Error: ./node_modules/@adobe/documentservices-pdftools-node-sdk/node_modules/log4js/lib/clustering.js
    Module not found: Error: Can't resolve 'cluster' in 'C:\Projects\Stash\poc\xps\node_modules@adobe\documentservices-pdftools-node-sdk\node_modules\log4js\lib'.

    Error: ./node_modules/@adobe/documentservices-pdftools-node-sdk/node_modules/fs-extra/lib/index.js
    Module not found: Error: Can't resolve 'fs' in 'C:\Projects\Stash\poc\xps\node_modules@adobe\documentservices-pdftools-node-sdk\node_modules\fs-extra\lib'

Error: ./node_modules/@adobe/documentservices-pdftools-node-sdk/node_modules/fs-extra/lib/empty/index.js
Module not found: Error: Can't resolve 'fs' in 'C:\Projects\Stash\poc\xps\node_modules@adobe\documentservices-pdftools-node-sdk\node_modules\fs-extra\lib\empty'

Error: ./node_modules/@adobe/documentservices-pdftools-node-sdk/node_modules/log4js/lib/log4js.js
Module not found: Error: Can't resolve 'fs' in 'C:\Projects\Stash\poc\xps\node_modules@adobe\documentservices-pdftools-node-sdk\node_modules\log4js\lib'

Error: ./node_modules/@adobe/documentservices-pdftools-node-sdk/src/client-config.js
Module not found: Error: Can't resolve 'fs' in 'C:\Projects\Stash\poc\xps\node_modules@adobe\documentservices-pdftools-node-sdk\src'

Error: ./node_modules/@adobe/documentservices-pdftools-node-sdk/src/auth/service-account-credentials-builder.js
Module not found: Error: Can't resolve 'fs' in 'C:\Projects\Stash\poc\xps\node_modules@adobe\documentservices-pdftools-node-sdk\src\auth'

Error: ./node_modules/@adobe/documentservices-pdftools-node-sdk/src/internal/logger.js
Module not found: Error: Can't resolve 'fs' in 'C:\Projects\Stash\poc\xps\node_modules@adobe\documentservices-pdftools-node-sdk\src\internal'

Error: ./node_modules/@adobe/documentservices-pdftools-node-sdk/src/internal/api/cpf-api.js
Module not found: Error: Can't resolve 'fs' in 'C:\Projects\Stash\poc\xps\node_modules@adobe\documentservices-pdftools-node-sdk\src\internal\api'

Error: ./node_modules/@adobe/documentservices-pdftools-node-sdk/src/internal/io/file-info.js
Module not found: Error: Can't resolve 'fs' in 'C:\Projects\Stash\poc\xps\node_modules@adobe\documentservices-pdftools-node-sdk\src\internal\io'

Error: ./node_modules/@adobe/documentservices-pdftools-node-sdk/src/internal/util/validation-util.js
Module not found: Error: Can't resolve 'fs' in 'C:\Projects\Stash\poc\xps\node_modules@adobe\documentservices-pdftools-node-sdk\src\internal\util'

Error: ./node_modules/@adobe/documentservices-pdftools-node-sdk/src/internal/util/file-util.js
Module not found: Error: Can't resolve 'fs' in 'C:\Projects\Stash\poc\xps\node_modules@adobe\documentservices-pdftools-node-sdk\src\internal\util'

Error: ./node_modules/@adobe/documentservices-pdftools-node-sdk/node_modules/streamroller/lib/RollingFileWriteStream.js
Module not found: Error: Can't resolve 'zlib' in 'C:\Projects\Stash\poc\xps\node_modules@adobe\documentservices-pdftools-node-sdk\node_modules\streamroller\lib'

Error: ./node_modules/@adobe/documentservices-pdftools-node-sdk/src/internal/http/http-client.js
Module not found: Error: Can't resolve 'zlib' in 'C:\Projects\Stash\poc\xps\node_modules@adobe\documentservices-pdftools-node-sdk\src\internal\http'

Newlines / Paragraphs are not supported in Word Template

@adobe/pdfservices-node-sdk to create PDF from a dynamic word template does not support text with multiple paragraphs / new lines, it will be escaped and merged into a single string.

Expected Behaviour

Hi, how are you ?

Hope you are doing good.

Actual Behaviour

Hi, how are you ? Hope you are doing good.

Compression file

Compression file gives file limit exceed error when file size is 190 mb

@adobe/pdfservices-node-sdk depends on vulnerable versions of jsonwebtoken <=8.5.1 (npm high severity vulnerability)

Reproduce Scenario (including but not limited to)

npm install @adobe/pdfservices-node-sdk

Platform and Version

Node v18.12.1

Logs taken while reproducing problem

jsonwebtoken <=8.5.1
Severity: high
jsonwebtoken's insecure implementation of key retrieval function could lead to Forgeable Public/Private Tokens from RSA to HMAC - GHSA-hjrf-2m68-5959
jsonwebtoken vulnerable to signature validation bypass due to insecure default algorithm in jwt.verify() - GHSA-qwph-4952-7xr6
jsonwebtoken unrestricted key type could lead to legacy keys usage - GHSA-8cf7-32gw-wr33
jsonwebtoken has insecure input validation in jwt.verify function - GHSA-27h2-hvpr-p74q
No fix available
node_modules/jsonwebtoken
@adobe/pdfservices-node-sdk *
Depends on vulnerable versions of jsonwebtoken
node_modules/@adobe/pdfservices-node-sdk

Remove all margins around the created document

I'm using HTML template to create a new PDF. And I have a large background image for the cover page.
I already removed header and footer, but I still have white margins on all 4 sides of the document when it is created.
the document size is set to pageLayout.setPageSize(8, 11.5);
is it possible to white margins?

UPDATE: Never mind, I figured it out. It is absolutely not obvious and it is not mentioned anywhere in the docs (which aren't very elaborated by the way), but the trick is to add something like this somewhere in the head of html file:

<style>
    @page  {
        margin: 0;
        padding: 0;
        size: letter; /*or width x height 150mm 50mm*/
    }
</style>

exportpdftoimages : error ServiceApiError

Hello, I'm new and I'm trying to use @adobe/pdfservices-node-sdk to convert pdf to jpeg.
some time ago, I managed to convert, but since yesterday impossible and I have an error "Exception encountered while executing operation ServiceApiError"

2023-05-15T11:01:53.681:[INFO]: All validations successfully done. Beginning Export PDF to Images Operation execution Exception encountered while executing operation ServiceApiError at rejectWithServiceApiError (..\node_modules\@adobe\pdfservices-node-sdk\src\internal\http\http-client.js:31:17) at handleJsonResponse (..\node_modules\@adobe\pdfservices-node-sdk\src\internal\http\http-client.js:55:3) at handleErrorResponse (..\node_modules\@adobe\pdfservices-node-sdk\src\internal\http\http-client.js:117:2) at onEnd (..\node_modules\@adobe\pdfservices-node-sdk\src\internal\http\http-client.js:176:3) at IncomingMessage.<anonymous> (..\node_modules\@adobe\pdfservices-node-sdk\src\internal\http\http-client.js:216:5) at IncomingMessage.emit (events.js:412:35) at endReadableNT (internal/streams/readable.js:1333:12) at processTicksAndRejections (internal/process/task_queues.js:82:21) { requestTrackingId: undefined, statusCode: 400, errorCode: 'UNKNOWN'

I applied the same code present in "src/exportpdftoimages/export-pdf-to-jpeg.js", copy the credential.json file and my private key.

Can you help me?

Exception encountered while executing operation SyntaxError: Unexpected token “ in JSON at position 0

Logging configuration found at config/pdftools-sdk-log4js-config.json.
Exception encountered while executing operation SyntaxError: Unexpected token “ in JSON at position 0
at JSON.parse ()
at ServiceAccountCredentialsBuilder.fromFile (/var/www/html/pdftools-node-sdk-samples-master/node_modules/@adobe/documentservices-pdftools-node-sdk/src/auth/service-account-credentials.js:175:37)
at Object. (/var/www/html/pdftools-node-sdk-samples-master/src/exportpdf/export-pdf-to-docx.js:24:10)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)

Where is the Node SDK repository?

Hi Adobe team. I'm getting started using the Node SDK for PDF to PPTX conversion but have found the OOTB methods involved in this process don't support my use case. I'm able to modify the package locally to do what I need, but ideally I'd like to fork the Node SDK and apply some modifications so I can use that as a project dependency for deployments. I can't seem to find the repo for this SDK anywhere.

Could someone please point me to it?

Custom header, footer and page numbers

I'm looking to generate a multipage document from a dynamic html file with custom header and custom footer (both should auto appear on all pages) which would also contain page current page number / total pages (e.g 2/10). Is this at all possible?

There is similar a post in Adobe Community but nobody ever answered the man in 11 months.

@adobe/pdfservices-node-sdk v3.0.0 has CRITICAL vulnerability.

Hi Adobe Team,

Wanted to share the vulnerability which we found on @adobe/pdfservices-node-sdk v3.0.0 NPM package.

  1. CRITICAL | https://nvd.nist.gov/vuln/detail/CVE-2018-6873 (Dependency - jsonwebtoken 8.5.1)
  2. CRITICAL | https://nvd.nist.gov/vuln/detail/CVE-2022-23541 (Dependency - jsonwebtoken 8.5.1)
  3. CRITICAL | https://nvd.nist.gov/vuln/detail/CVE-2022-23541 (Dependency - jsonwebtoken 8.5.1)
  4. CRITICAL | https://nvd.nist.gov/vuln/detail/CVE-2022-23540 (Dependency - jsonwebtoken 8.5.1)
  5. CRITICAL | https://nvd.nist.gov/vuln/detail/CVE-2022-23529 (Dependency - jsonwebtoken 8.5.1)
  6. HIGH | https://nvd.nist.gov/vuln/detail/CVE-2017-17068 (Dependency - jsonwebtoken 8.5.1)
  7. HIGH | https://nvd.nist.gov/vuln/detail/CVE-2018-6874 (Dependency - jsonwebtoken 8.5.1)
  8. HIGH | https://nvd.nist.gov/vuln/detail/CVE-2018-7307 (Dependency - jsonwebtoken 8.5.1)
  9. HIGH | https://nvd.nist.gov/vuln/detail/CVE-2022-23539 (Dependency - jsonwebtoken 8.5.1)
  10. Medium | https://nvd.nist.gov/vuln/detail/CVE-2020-5263 (Dependency - jsonwebtoken 8.5.1)

I am not able to get past through our product's release, as there are CRITICAL vulnerability in the NPM package. Please provide an update to the package at the earliest, so that we can move ahead for the product release with @adobe/pdfservices-node-sdk package.

Erroe

Exception encountered while executing operation ServiceApiError: Could not match JWT signature to any of the bindings
i have used the same configuration file structure as provided in the esample

Possibility of loading files through the buffer

Hello, there is the possibility of being able to load the documents that you want to convert to odf through a buffer, the only way to load these documents is through the fs or an existing file.

Thanks

createFromURL is not working as expected

Expected Behaviour

const input = PDFServicesSdk.FileRef.createFromURL(
		"https://stc.aeplcdn.com/f/brochure/72/1385/17bqrvc.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) => {
			console.log(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);
			}
		});

The above code should create the exportPdfOutput.docx file in the specified location

Actual Behaviour

This throws the error as below
Screenshot 2021-10-22 at 12 17 07 PM

Reproduce Scenario (including but not limited to)

Try executing the above code

Platform and Version

Node js SDK @adobe/pdfservices-node-sdk version 2.1.0

Sample Code that illustrates the problem

const input = PDFServicesSdk.FileRef.createFromURL(
		"https://stc.aeplcdn.com/f/brochure/72/1385/17bqrvc.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) => {
			console.log(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);
			}
		});

Logs taken while reproducing problem

Screenshot 2021-10-22 at 12 17 07 PM

Permissions not actively loaded

Expected Behaviour

Setting the permissions in a PDF Protect operation should determine edit/copy/print permissions in the resulting PDF

Actual Behaviour

Permissions are always set to:

"permissions": {
      "assistive_technology": true,
      "form_filling": false,
      "copying": false,
      "page_extraction": true,
      "document_assembly": false,
      "commenting": false,
      "printing": "none",
      "editing": false
    }

Reproduce Scenario (including but not limited to)

I've merged this sample:
https://github.com/adobe/pdfservices-node-sdk-samples/blob/master/src/protectpdf/protect-pdf-with-owner-password.js
With this sample:
https://github.com/adobe/pdfservices-node-sdk-samples/blob/master/src/pdfproperties/pdf-properties-as-json.js

And the resulting PDF's properties indicate that permissions haven't been set correctly AFAIK

Platform and Version

Currently using
"@adobe/pdfservices-node-sdk": "^2.1.0"
With
node.js v16.5.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.