### Convert PDF to Grayscale in JavaScript Source: https://products.aspose.com/pdf/nodejs-cpp/conversion/pdf-to-grayscale This snippet demonstrates how to convert a PDF file to grayscale using the Aspose.PDF API in JavaScript. Ensure the AsposePDFforNode.js module is installed and provide the correct paths for input and output files. ```javascript const AsposePdf = require('../AsposePDFforNode.js'); const pdf_file = '../ReadMe.pdf'; AsposePdf().then(AsposePdfModule => { json = AsposePdfModule.AsposePdfConvertToGrayscale(pdf_file, resultdir + "ResultConvertToGrayscale.pdf"); console.log("AsposePdfConvertToGrayscale => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText); }); ``` -------------------------------- ### Repair PDF Pages with JavaScript/Node.js Source: https://products.aspose.com/pdf/nodejs-cpp/repair This sample code demonstrates how to repair PDF pages using the Aspose.PDF for Node.js via C++ library. Ensure the Aspose PDF library is installed and the PDF file is correctly specified. ```javascript const AsposePdf = require('asposepdfnodejs'); const pdf_file = 'Aspose.pdf'; AsposePdf().then(AsposePdfModule => { /*Repair a PDF-file and save the "ResultPdfRepair.pdf"*/ const json = AsposePdfModule.AsposePdfRepair(pdf_file, "ResultPdfRepair.pdf"); console.log("AsposePdfRepair => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText); }); ``` -------------------------------- ### Convert PDF to DOCX using JavaScript Source: https://products.aspose.com/pdf/nodejs-cpp/conversion/pdf-to-docx This sample code demonstrates how to convert a PDF file to DOCX format using Aspose.PDF for Node.js. Ensure the AsposePDFforNode.js module is installed and provide the correct paths for input and output files. ```javascript const AsposePdf = require('../AsposePDFforNode.js'); const pdf_file = '../ReadMe.pdf'; AsposePdf().then(AsposePdfModule => { /*Convert a PDF-file to DocX and save the "ResultPDFtoDocX.docx"*/ const json = AsposePdfModule.AsposePdfToDocX(pdf_file, "./ResultPDFtoDocX.docX"); console.log("AsposePdfToDoc => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText); }); ``` -------------------------------- ### Convert PDF to EPUB using JavaScript Source: https://products.aspose.com/pdf/nodejs-cpp/conversion/pdf-to-epub Use this JavaScript code to convert a PDF file to EPUB format. Ensure the AsposePDFforNode.js module is installed and provide the correct paths for input and output files. ```javascript const AsposePdf = require('../AsposePDFforNode.js'); const pdf_file = '../ReadMe.pdf'; AsposePdf().then(AsposePdfModule => { json = AsposePdfModule.AsposePdfToEPUB(pdf_file, resultdir + "ResultPdfToEPUB.epub"); console.log("17. AsposePdfToEPUB => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText); }); ``` -------------------------------- ### Convert PDF to DICOM using JavaScript Source: https://products.aspose.com/pdf/nodejs-cpp/conversion/pdf-to-dicom This sample code demonstrates how to convert a PDF file to DICOM format using Aspose.PDF for Node.js. Ensure the AsposePDFforNode.js module is installed and provide the correct paths for input and output files. ```javascript const AsposePdf = require('../AsposePDFforNode.js'); const pdf_file = '../ReadMe.pdf'; AsposePdf().then(AsposePdfModule => { json = AsposePdfModule.AsposePdfPagesToDICOM(pdf_file, resultdir + "ResultPdfToDICOM{0:D2}.dcm", 150); console.log("05. AsposePdfPagesToDICOM => %O", json.errorCode == 0 ? json.filesNameResult : json.errorText); }); ``` -------------------------------- ### Convert PDF to TEX using JavaScript Source: https://products.aspose.com/pdf/nodejs-cpp/conversion/pdf-to-tex This sample code demonstrates PDF to TEX JavaScript Conversion. Ensure the Aspose.PDF module is installed and the input PDF file path is correctly specified. The output TEX file will retain the original document's content and formatting. ```javascript const AsposePdf = require('../AsposePDFforNode.js'); const pdf_file = '../ReadMe.pdf'; AsposePdf().then(AsposePdfModule => { json = AsposePdfModule.AsposePdfToTeX(pdf_file, resultdir + "ResultPdfToTeX.tex"); console.log("AsposePdfToTeX => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText); }); ``` -------------------------------- ### Convert PDF to DOC using JavaScript Source: https://products.aspose.com/pdf/nodejs-cpp/conversion/pdf-to-doc Use this JavaScript code to convert a PDF file to DOC format. Ensure the Aspose.PDF module is installed and provide the correct paths for input and output files. The output filename is specified in the function call. ```javascript const AsposePdf = require('../AsposePDFforNode.js'); const pdf_file = '../ReadMe.pdf'; AsposePdf().then(AsposePdfModule => { /*Convert a PDF-file to DocX and save the "ResultPDFtoDocX.docx"*/ const json = AsposePdfModule.AsposePdfToDoc(pdf_file, "./ResultPDFtoDoc.doc"); console.log("AsposePdfToDoc => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText); }); ``` -------------------------------- ### Extract Text from PDF in JavaScript Source: https://products.aspose.com/pdf/nodejs-cpp/parser/text Use this code to extract text from a PDF file. Ensure Aspose.PDF for Node.js via C++ is installed and the PDF file path is correct. ```javascript const AsposePdf = require('../AsposePDFforNode.js'); const pdf_file = '../ReadMe.pdf'; AsposePdf().then(AsposePdfModule => { /*Extract text from a PDF-file*/ const json = AsposePdfModule.AsposePdfExtractText(pdf_file); console.log("AsposePdfExtractText => %O", json.errorCode == 0 ? json.extractText : json.errorText); }); ``` -------------------------------- ### Convert PDF to TIFF using JavaScript Source: https://products.aspose.com/pdf/nodejs-cpp/conversion/pdf-to-tiff Use this code to convert a PDF file to TIFF format. Ensure the Aspose.PDF module is installed and provide the correct file paths. The output TIFF will maintain the original PDF's content and formatting. ```javascript const AsposePdf = require('../AsposePDFforNode.js'); const pdf_file = '../ReadMe.pdf'; AsposePdf().then(AsposePdfModule => { json = AsposePdfModule.AsposePdfPagesToTiff(pdf_file, resultdir + "ResultPdfToTiff{0:D2}.tiff", 300); console.log("03. AsposePdfPagesToTiff => %O", json.errorCode == 0 ? json.filesNameResult : json.errorText); }); ``` -------------------------------- ### Convert PDF to PPTX using JavaScript Source: https://products.aspose.com/pdf/nodejs-cpp/conversion/pdf-to-pptx Use this JavaScript code to convert a PDF file to PPTX format. Ensure the Aspose.PDF module is installed and provide the correct paths for input and output files. The output will contain either the filename of the converted PPTX or an error message. ```javascript const AsposePdf = require('../AsposePDFforNode.js'); const pdf_file = '../ReadMe.pdf'; AsposePdf().then(AsposePdfModule => { json = AsposePdfModule.AsposePdfToPptX(pdf_file, resultdir + "ResultPdfToPptX.pptx"); console.log("AsposePdfToPptX => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText); }); ``` -------------------------------- ### Decrypt PDF Document using JavaScript Source: https://products.aspose.com/pdf/nodejs-cpp/decrypt Use this code to decrypt a password-protected PDF file. Ensure the Aspose.PDF for Node.js module is installed and the correct file paths and password are provided. ```javascript const AsposePdf = require('../AsposePDFforNode.js'); const pdf_encrypt_file = './ResultEncrypt.pdf'; AsposePdf().then(AsposePdfModule => { /*Decrypt a PDF-file with password is "owner" and save the "ResultDecrypt.pdf"*/ const json = AsposePdfModule.AsposePdfDecrypt(pdf_encrypt_file, "owner", "./ResultDecrypt.pdf"); console.log("AsposePdfDecrypt => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText); }); ``` -------------------------------- ### Split PDF into Two Files using JavaScript Source: https://products.aspose.com/pdf/nodejs-cpp/splitter Use this code to split a PDF document into two separate files at a specified page. Ensure you have Aspose.PDF for Node.js via C++ installed. The output files will be named 'ResultSplit1.pdf' and 'ResultSplit2.pdf'. ```javascript const AsposePdf = require('../AsposePDFforNode.js'); const pdf_file = '../ReadMe.pdf'; AsposePdf().then(AsposePdfModule => { /*Set number a page to split*/ const pageToSplit = 1; /*Split to two PDF-files and save the "ResultSplit1.pdf", "ResultSplit2.pdf"*/ const json = AsposePdfModule.AsposePdfSplit2Files(pdf_file, pageToSplit, "./ResultSplit1.pdf", "./ResultSplit2.pdf"); console.log("AsposePdfSplit2Files => %O", json.errorCode == 0 ? [json.fileNameResult1, json.fileNameResult2] : json.errorText); }); ``` -------------------------------- ### Convert PDF to PDFA using JavaScript Source: https://products.aspose.com/pdf/nodejs-cpp/conversion/pdf-to-pdfa Use this JavaScript code to convert a PDF file to PDF/A format. Ensure you have the AsposePDFforNode.js module installed. The function takes the input PDF file path, the desired PDF/A format, and output file paths for the result and log. ```javascript const AsposePdf = require('../AsposePDFforNode.js'); const pdf_file = '../ReadMe.pdf'; AsposePdf().then(AsposePdfModule => { json = AsposePdfModule.AsposePdfConvertToPDFA(pdf_file,AsposePdfModule.PdfFormat.PDF_A_1A, resultdir + "ResultConvertToPDFA.pdf", resultdir + "ResultConvertToPDFALog.xml"); console.log("13. AsposePdfConvertToPDFA => %O", json.errorCode == 0 ? [json.fileNameResult, json.fileNameLogResult] : json.errorText); }); ``` -------------------------------- ### Convert PDF to JPEG using JavaScript Source: https://products.aspose.com/pdf/nodejs-cpp/conversion/pdf-to-jpeg Use this code to convert a PDF file to JPEG format. Ensure the AsposePDFforNode.js module is installed and provide the correct paths for input and output files. The function AsposePdfPagesToJpg handles the conversion. ```javascript const AsposePdf = require('../AsposePDFforNode.js'); const pdf_file = '../ReadMe.pdf'; AsposePdf().then(AsposePdfModule => { json = AsposePdfModule.AsposePdfPagesToJpg(pdf_file, resultdir + "ResultPdfToJpg{0:D2}.jpg", 150); console.log("AsposePdfPagesToJpg => %O", json.errorCode == 0 ? json.filesNameResult : json.errorText); }); ``` -------------------------------- ### Convert PDF to PNG using JavaScript Source: https://products.aspose.com/pdf/nodejs-cpp/conversion/pdf-to-png Use this JavaScript code to convert a PDF file to a PNG image. Ensure you have the Aspose.PDF module installed. The output PNG will match the original PDF's content and formatting. ```javascript const AsposePdf = require('../AsposePDFforNode.js'); const pdf_file = '../ReadMe.pdf'; AsposePdf().then(AsposePdfModule => { json = AsposePdfModule.AsposePdfPagesToPng(pdf_file, resultdir + "ResultPdfToPng{0:D2}.png", 150); console.log("AsposePdfPagesToPng => %O", json.errorCode == 0 ? json.filesNameResult : json.errorText); }); ``` -------------------------------- ### Convert PDF to SVGZ using JavaScript Source: https://products.aspose.com/pdf/nodejs-cpp/conversion/pdf-to-svgz Use this JavaScript code to convert a PDF file to an SVGZ file. Ensure the AsposePDFforNode.js module is installed and provide the correct paths for input and output files. The output SVGZ will maintain the original PDF's content and formatting. ```javascript const AsposePdf = require('../AsposePDFforNode.js'); const pdf_file = '../ReadMe.pdf'; AsposePdf().then(AsposePdfModule => { json = AsposePdfModule.AsposePdfPagesToSvgZip(pdf_file, resultdir + "ResultPdfToSvgZip.zip"); console.log("AsposePdfPagesToSvgZip => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText); }); ``` -------------------------------- ### Convert PDF to TXT via JavaScript Source: https://products.aspose.com/pdf/nodejs-cpp/conversion/pdf-to-txt Use this JavaScript code to convert a PDF file to a TXT file. Ensure the Aspose.PDF module is installed and the input PDF file path is correctly specified. The output TXT file will retain the original formatting. ```javascript const AsposePdf = require('../AsposePDFforNode.js'); const pdf_file = '../ReadMe.pdf'; AsposePdf().then(AsposePdfModule => { json = AsposePdfModule.AsposePdfToTxt(pdf_file, resultdir + "ResultPdfToTxt.txt"); console.log("11. AsposePdfToTxt => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText); }); ``` -------------------------------- ### Convert PDF to EXCEL via JavaScript Source: https://products.aspose.com/pdf/nodejs-cpp/conversion/pdf-to-excel Use this JavaScript code to convert a PDF file to an Excel (XLSX) file. Ensure the AsposePDFforNode.js module is installed and provide the correct paths for the input PDF and output XLSX files. The conversion process checks for errors and logs the result. ```javascript const AsposePdf = require('../AsposePDFforNode.js'); const pdf_file = '../ReadMe.pdf'; AsposePdf().then(AsposePdfModule => { json = AsposePdfModule.AsposePdfToXlsX(pdf_file, resultdir + "ResultPdfToXlsX.xlsx"); console.log("16. AsposePdfToXlsX => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText); }); ``` -------------------------------- ### Convert PDF to SVG using JavaScript Source: https://products.aspose.com/pdf/nodejs-cpp/conversion/pdf-to-svg Use this JavaScript code to convert a PDF file to an SVG file. Ensure the AsposePDFforNode.js module is installed and provide the correct paths for the input PDF and output SVG files. The output will contain the file name or error text based on the conversion result. ```javascript const AsposePdf = require('../AsposePDFforNode.js'); const pdf_file = '../ReadMe.pdf'; AsposePdf().then(AsposePdfModule => { json = AsposePdfModule.AsposePdfPagesToSvg(pdf_file, resultdir + "ResultPdfToSvg.svg"); console.log("AsposePdfPagesToSvg => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText); }); ``` -------------------------------- ### Convert PDF to CSV using JavaScript Source: https://products.aspose.com/pdf/nodejs-cpp/conversion/pdf-to-csv This snippet demonstrates how to convert a PDF file to CSV format using the Aspose.PDF library in Node.js. Ensure the AsposePDFforNode.js module is installed and provide the correct paths for input and output files. The third argument specifies the separator for the CSV file. ```javascript const AsposePdf = require('../AsposePDFforNode.js'); const pdf_file = '../ReadMe.pdf'; AsposePdf().then(AsposePdfModule => { const json = AsposePdfModule.AsposePdfTablesToCSV(pdf_file, "./ResultPdfTablesToCSV{0:D2}.csv", "\t"); console.log("AsposePdfTablesToCSV => %O", json.errorCode == 0 ? json.filesNameResult : json.errorText); }); ``` -------------------------------- ### Add Image to PDF Document using JavaScript Source: https://products.aspose.com/pdf/nodejs-cpp/images/add Use this JavaScript code to add an image to the end of a PDF document and save the result to a new file. Ensure you have Aspose.PDF for Node.js via C++ installed and the correct paths for your PDF and image files. ```javascript const AsposePdf = require('../AsposePDFforNode.js'); const pdf_file = '../ReadMe.pdf'; const image_file = '../Aspose.jpg'; AsposePdf().then(AsposePdfModule => { /*Add image to end a PDF-file and save the "ResultImage.pdf"*/ const json = AsposePdfModule.AsposePdfAddImage(pdf_file, image_file, "./ResultAddImage.pdf"); console.log("AsposePdfAddImage => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText); }); ``` -------------------------------- ### Convert PDF to XPS via JavaScript Source: https://products.aspose.com/pdf/nodejs-cpp/conversion/pdf-to-xps This sample code demonstrates how to convert a PDF file to XPS format using Aspose.PDF for Node.js. Ensure the PDF file is accessible and specify the output XPS file name. The conversion preserves the original document's content and formatting. ```javascript const AsposePdf = require('../AsposePDFforNode.js'); const pdf_file = '../ReadMe.pdf'; AsposePdf().then(AsposePdfModule => { json = AsposePdfModule.AsposePdfToXps(pdf_file, resultdir + "ResultPdfToXps.xps"); console.log("09. AsposePdfToXps => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText); }); ``` -------------------------------- ### Convert PDF to XPS in Node.js Source: https://products.aspose.com/pdf/nodejs-cpp/conversion Use this Node.js function to convert a PDF file to an XPS file. Ensure the Aspose.PDF module is required and the input PDF file path is correctly specified. ```javascript const AsposePdf = require('../AsposePDFforNode.js'); const pdf_file = '../ReadMe.pdf'; AsposePdf().then(AsposePdfModule => { /*Convert a PDF-file to Xps and save the "ResultPDFtoXps.xps"*/ const json = AsposePdfModule.AsposePdfToXps(pdf_file, "./ResultPDFtoXps.xps"); console.log("AsposePdfToXps => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText); }); ``` -------------------------------- ### Convert PDF Pages to JPG Images in Node.js Source: https://products.aspose.com/pdf/nodejs-cpp Load an existing PDF document and convert each page into a JPG image. Specify the output filename pattern and resolution. Ensure the AsposePDF module is loaded. ```javascript const AsposePdf = require('./AsposePDFforNode.js'); const fs = require("fs"); const os = require("os"); const pdf_file = ''; const resultdir = fs.realpathSync(os.tmpdir()) + '/'; AsposePdf().then(AsposePdfModule => { console.log("Convert from PDF:"); const json = AsposePdfModule.AsposePdfPagesToJpg(pdf_file, resultdir + "ResultPdfToJpg{0:D2}.jpg", 150); console.log("AsposePdfPagesToJpg => %O", json.errorCode == 0 ? json.filesNameResult : json.errorText); }); ``` -------------------------------- ### Encrypt PDF Document with Passwords and Permissions - JavaScript Source: https://products.aspose.com/pdf/nodejs-cpp/encrypt Encrypts a PDF document using specified user and owner passwords. It allows setting print permissions and choosing an encryption algorithm. The output is logged to the console, indicating success or failure. ```javascript const AsposePdf = require('../AsposePDFforNode.js'); const pdf_file = '../ReadMe.pdf'; AsposePdf().then(AsposePdfModule => { /*Encrypt a PDF-file with passwords "user" and "owner", and save the "ResultEncrypt.pdf"*/ const json = AsposePdfModule.AsposePdfEncrypt(pdf_file, "user", "owner", AsposePdfModule.Permissions.PrintDocument, AsposePdfModule.CryptoAlgorithm.RC4x40, "./ResultEncrypt.pdf"); console.log("AsposePdfEncrypt => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText); }); ``` -------------------------------- ### Convert PDF to BMP using JavaScript Source: https://products.aspose.com/pdf/nodejs-cpp/conversion/pdf-to-bmp Use this snippet to convert a PDF file to BMP format. Specify the input PDF file, the output BMP file name pattern, and the desired resolution (DPI). The output filename pattern can include page number formatting. ```javascript const AsposePdf = require('../AsposePDFforNode.js'); const pdf_file = '../ReadMe.pdf'; AsposePdf().then(AsposePdfModule => { /*Convert a PDF-file to BMP with template "ResultPdfToBmp{0:D2}.bmp" ({0}, {0:D2}, {0:D3}, ... format page number), resolution 150 DPI and save*/ const json = AsposePdfModule.AsposePdfPagesToBmp(pdf_file, "./ResultPdfToBmp{0:D2}.bmp", 150); console.log("AsposePdfPagesToBmp => %O", json.errorCode == 0 ? json.filesNameResult : json.errorText); }); ``` -------------------------------- ### Convert PDF to XLSX in Node.js Source: https://products.aspose.com/pdf/nodejs-cpp/conversion This code converts a PDF file to XLSX format. It requires the AsposePDFforNode.js module and a valid path to the input PDF. The converted Excel file will be saved with the specified output name. ```javascript const AsposePdf = require('../AsposePDFforNode.js'); const pdf_file = '../ReadMe.pdf'; AsposePdf().then(AsposePdfModule => { /*Convert a PDF-file to XlsX and save the "ResultPDFtoXlsX.xlsx"*/ const json = AsposePdfModule.AsposePdfToXlsX(pdf_file, "./ResultPDFtoXlsX.xlsx"); console.log("AsposePdfToXlsX => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText); }); ``` -------------------------------- ### Delete Images from Existing PDF File - JavaScript Source: https://products.aspose.com/pdf/nodejs-cpp/images/remove Use this sample code to remove images from a PDF file. Ensure the Aspose.PDF module is imported and the correct file paths are provided. ```javascript const AsposePdf = require('../AsposePDFforNode.js'); const pdf_file = '../ReadMe.pdf'; AsposePdf().then(AsposePdfModule => { /*Delete images a PDF-file and save the "ResultPdfDeleteImages.pdf"*/ const json = AsposePdfModule.AsposePdfDeleteImages(pdf_file, "./ResultPdfDeleteImages.pdf"); console.log("AsposePdfDeleteImages => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText); }); ``` -------------------------------- ### Extract PDF Metadata using JavaScript Source: https://products.aspose.com/pdf/nodejs-cpp/metadata Use this JavaScript code to extract metadata from a PDF file with Aspose.PDF for Node.js. Ensure the Aspose.PDF module is imported and the input PDF file path is correctly defined. The output will log the PDF's title or an error message. ```javascript const AsposePdf = require('../AsposePDFforNode.js'); const pdf_file = '../ReadMe.pdf'; AsposePdf().then(AsposePdfModule => { /*Get info (metadata) from a PDF-file*/ const json = AsposePdfModule.AsposePdfGetInfo(pdf_file); console.log("AsposePdfGetInfo => %O", json.errorCode == 0 ? 'Title: ' + json.title : json.errorText); }); ``` -------------------------------- ### Convert PDF to PNG in Node.js Source: https://products.aspose.com/pdf/nodejs-cpp/conversion This Node.js function converts a PDF file into a series of PNG images. It allows specifying an output filename template with page number formatting and a resolution in DPI. ```javascript const AsposePdf = require('../AsposePDFforNode.js'); const pdf_file = '../ReadMe.pdf'; AsposePdf().then(AsposePdfModule => { /*Convert a PDF-file to PNG with template "ResultPdfToPng{0:D2}.png" ({0}, {0:D2}, {0:D3}, ... format page number), resolution 150 DPI and save*/ const json = AsposePdfModule.AsposePdfPagesToPng(pdf_file, "./ResultPdfToPng{0:D2}.png", 150); console.log("AsposePdfPagesToPng => %O", json.errorCode == 0 ? json.filesNameResult : json.errorText); }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.