UNPKG

@raymondcamden/pdfservice_sdk_foxit

Version:

A SDK wrapper for Foxit's PDF Services and Document Generation APIs.

72 lines (50 loc) 3.54 kB
# Foxit PDF Services SDK This SDK lets developers more easily use the Foxit APIs, including [PDF Services](https://developer-api.foxit.com/pdf-services/) and [Document Generation](https://developer-api.foxit.com/document-generation/). You will need a [free set of credentials](https://app.developer-api.foxit.com/pricing) in order to call the APIs. ## Usage Copy your credentials to the environment and then instantiate the SDK. Here's a sample: ```js import { PDFServiceSDK } from "./PDFServiceSDK.mjs"; const clientId = process.env.CLIENT_ID; const clientSecret = process.env.CLIENT_SECRET; const pdfService = new PDFServiceSDK(clientId, clientSecret); await pdfService.wordToPDF('assets/input/input.docx', 'assets/output/output_from_nodesdk.pdf'); console.log("PDF conversion completed successfully."); // v2 change that uses new conversion method await pdfService.conversion('assets/input/input.docx', 'assets/output/output_from_nodesdk_v2.pdf'); console.log("PDF conversion (second version)completed successfully."); ``` You can optionally pass credentials for the 4th and 5th parameter to the constructor: ```js const clientId = process.env.CLIENT_ID; const clientSecret = process.env.CLIENT_SECRET; const dgClientId = process.env.DG_CLIENT_ID; const dgClientSecret = process.env.DG_CLIENT_SECRET; const host = process.env.HOST; const pdfService = new PDFServiceSDK(clientId, clientSecret, host, dgClientId, dgClientSecret); ``` If you don't know the host, it is `https://na1.fusion.foxit.com`. ## Methods Supported * conversion(inputPath, outputPath) - general conversion method * excelToPDF, htmlToPDF, imageToPDF, pdfToExcel, pdfToHTML, pdfToImage, pdfToPowerpoint, pdfToText, pdfToWord, powerpointToWord, textToPDF, wordToPDF - all take an inputPath and outputPath argument * url_to_pdf(url, outputPath) - convert a URL to pdf * extractPDF(inputPath, outputPath, type (one of TEXT, IMAGE, PAGE), page_range) - extracts either text, images (zip), or pages (new pdf) * download(docId, outputPath) - given a document id and path, will stream the data down * upload(path) - upload a document and return a path * compress(inputPath,outputPath,compressionLevel) - compresses a PDF, default level is LOW * linearize(inputPath,outputPath) - linearizes a PDF * flatten(inputPath,outputPath) - flattens a PDF * combine(inputPaths[], outputPath, options) - combines a set of PDFs * removePassword(inputPath,outputPath,password) - removes password * protectPDF(input_path, output_path, config) - modifies permissions for a PDF - see [API ref](https://docs.developer-api.foxit.com/#0e822637-c4cd-41b6-b201-ab4eaf29e93c) for details on the `config` param * splitPDF(inputPath,outputPath,pageCount) - splits a PDF into `pageCount` new PDFs. Returns a zip of the PDFs. * manipulatePDF(inputPath, outputPath, operations) - performs multiple operations for a PDF - see [API ref](https://docs.developer-api.foxit.com/#91d60db7-793e-49c7-88b6-320ad3c1cea6) for details on the `operations` param * docgen(inputPath,outputPath,data) - document generation using data ## To Do: * Make output path optional and just return the doc id * Make checking a task public and a utility pollTask to handle repeating (this and the previous two methods would let devs chain calls) ## History | Date | Change | |------|-----------| | 8/11/2025 | Added splitPDF, manipulatePDF, compare, docgen. | | 8/7/2025 | Added remove password. Corrected wrong method names above. Removed unused var in Linearize. Added protectPDF | | ??? | Initial release |