### Install api2pdf.node Source: https://github.com/api2pdf/api2pdf.node/blob/master/README.md Installs the api2pdf.node package using npm. ```javascript npm install --save api2pdf ``` -------------------------------- ### Extract Pages from PDF Source: https://github.com/api2pdf/api2pdf.node/blob/master/README.md Extracts a specific range of pages from an existing PDF. The start page is inclusive, and the end page can be null to extract to the end of the document. ```javascript var url = 'https://LINK-TO-PDF'; var start = "2"; var end = null; a2pClient.pdfsharpExtractPages(url, start, end).then(function(result) { console.log(result); }); ``` -------------------------------- ### Initialize Api2Pdf Client Source: https://github.com/api2pdf/api2pdf.node/blob/master/README.md Initializes the Api2Pdf client with your API key. ```javascript var Api2Pdf = require('api2pdf'); var a2pClient = new Api2Pdf('YOUR-API-KEY'); ``` -------------------------------- ### Generate Thumbnail from Office Document or PDF with LibreOffice Source: https://github.com/api2pdf/api2pdf.node/blob/master/README.md Generates a thumbnail image of the first page of a PDF or Office Document using the LibreOffice engine. ```javascript a2pClient.libreOfficeThumbnail('https://www.api2pdf.com/wp-content/themes/api2pdf/assets/samples/sample-word-doc.docx').then(function(result) { console.log(result); }); ``` -------------------------------- ### Convert HTML to Docx with LibreOffice Source: https://github.com/api2pdf/api2pdf.node/blob/master/README.md Converts HTML content to a Microsoft Word (Docx) file using the LibreOffice engine. ```javascript a2pClient.libreOfficeHtmlToDocx('http://www.api2pdf.com/wp-content/uploads/2021/01/sampleHtml.html').then(function(result) { console.log(result); }); ``` -------------------------------- ### Convert HTML to Xlsx with LibreOffice Source: https://github.com/api2pdf/api2pdf.node/blob/master/README.md Converts HTML content containing tables to a Microsoft Excel (Xlsx) file using the LibreOffice engine. ```javascript a2pClient.libreOfficeHtmlToXlsx('http://www.api2pdf.com/wp-content/uploads/2021/01/sampleTables.html').then(function(result) { console.log(result); }); ``` -------------------------------- ### Convert URL to PDF using Headless Chrome Source: https://github.com/api2pdf/api2pdf.node/blob/master/README.md Converts a given URL to a PDF using the Headless Chrome engine. The result is a promise that resolves with the PDF file URL or rejects with an error. ```javascript a2pClient.chromeUrlToPdf('https://www.github.com') .then(function(result) { console.log(result); //successful api call }, function(rejected) { console.log(rejected); //an error occurred }); ``` -------------------------------- ### Convert PDF to HTML with LibreOffice Source: https://github.com/api2pdf/api2pdf.node/blob/master/README.md Converts a PDF file to HTML content using the LibreOffice engine. ```javascript a2pClient.libreOfficePdfToHtml('http://www.api2pdf.com/wp-content/uploads/2021/01/1a082b03-2bd6-4703-989d-0443a88e3b0f-4.pdf').then(function(result) { console.log(result); }); ``` -------------------------------- ### Convert URL to PDF with Headless Chrome Source: https://github.com/api2pdf/api2pdf.node/blob/master/README.md Converts a given URL to a PDF file using the Headless Chrome engine. Supports specifying output filename and advanced Chrome options. ```javascript a2pClient.chromeUrlToPdf('https://www.github.com').then(function(result) { console.log(result); }); ``` ```javascript a2pClient.chromeUrlToPdf('https://www.github.com', { inline: false, filename: 'test.pdf' }).then(function(result) { console.log(result); }); ``` ```javascript var options = { landscape: true }; a2pClient.chromeUrlToPdf('https://www.github.com', { options: options }).then(function(result) { console.log(result); }); ``` -------------------------------- ### Convert HTML to PDF with Headless Chrome Source: https://github.com/api2pdf/api2pdf.node/blob/master/README.md Converts HTML content to a PDF file using the Headless Chrome engine. Supports specifying output filename and advanced Chrome options. ```javascript a2pClient.chromeHtmlToPdf('
Hello, World
').then(function(result) { console.log(result); }); ``` ```javascript a2pClient.chromeHtmlToPdf('Hello, World
', { inline: false, filename: 'test.pdf' }).then(function(result) { console.log(result); }); ``` ```javascript var options = { landscape: true }; a2pClient.chromeHtmlToPdf('Hello, World
', { options: options }).then(function(result) { console.log(result); }); ``` -------------------------------- ### Convert HTML to Image with Headless Chrome Source: https://github.com/api2pdf/api2pdf.node/blob/master/README.md Converts HTML content to an image file using the Headless Chrome engine. ```javascript a2pClient.chromeHtmlToImage('Hello, World
').then(function(result) { console.log(result); }); ``` -------------------------------- ### Convert URL to Image with Headless Chrome Source: https://github.com/api2pdf/api2pdf.node/blob/master/README.md Converts a given URL to an image file using the Headless Chrome engine. ```javascript a2pClient.chromeUrlToImage('https://www.github.com').then(function(result) { console.log(result); }); ``` -------------------------------- ### Convert URL to PDF using wkhtmltopdf Source: https://github.com/api2pdf/api2pdf.node/blob/master/README.md Converts a given URL to a PDF document using the wkhtmltopdf engine. Supports options for inline display or downloading with a specified filename, and advanced wkhtmltopdf settings. ```javascript a2pClient.wkUrlToPdf('https://www.github.com').then(function(result) { console.log(result); }); ``` ```javascript a2pClient.wkUrlToPdf('https://www.github.com', { inline: false, filename: 'test.pdf' }).then(function(result) { console.log(result); }); ``` ```javascript var options = { orientation: 'landscape', pageSize: 'A4'}; a2pClient.wkUrlToPdf('https://www.github.com', { options: options }).then(function(result) { console.log(result); }); ``` -------------------------------- ### Convert HTML to PDF using wkhtmltopdf Source: https://github.com/api2pdf/api2pdf.node/blob/master/README.md Converts raw HTML content to a PDF document using the wkhtmltopdf engine. Supports options for inline display or downloading with a specified filename, and advanced wkhtmltopdf settings. ```javascript a2pClient.wkHtmlToPdf('Hello, World
').then(function(result) { console.log(result); }); ``` ```javascript a2pClient.wkHtmlToPdf('Hello, World
', { inline: false, filename: 'test.pdf' }).then(function(result) { console.log(result); }); ``` ```javascript var options = { orientation: 'landscape', pageSize: 'A4'}; a2pClient.wkHtmlToPdf('Hello, World
', { options: options }).then(function(result) { console.log(result); }); ``` -------------------------------- ### Add Bookmarks to PDF Source: https://github.com/api2pdf/api2pdf.node/blob/master/README.md Adds bookmarks to an existing PDF. Bookmarks are defined by an array of objects, each specifying a page number and a title. ```javascript var url = 'https://LINK-TO-PDF'; var bookmarks = [ { Page: 0, Title: "Introduction"}, { Page: 1, Title: "Second page"} ] a2pClient.pdfsharpAddBookmarks(url, bookmarks).then(function(result) { console.log(result); }); ``` -------------------------------- ### Convert Office Document or Image to PDF with LibreOffice Source: https://github.com/api2pdf/api2pdf.node/blob/master/README.md Converts various file types including Microsoft Office documents and images to PDF using the LibreOffice engine. Supports specifying output filename. ```javascript a2pClient.libreOfficeAnyToPdf('https://www.api2pdf.com/wp-content/themes/api2pdf/assets/samples/sample-word-doc.docx').then(function(result) { console.log(result); }); ``` ```javascript a2pClient.libreOfficeAnyToPdf('https://www.api2pdf.com/wp-content/themes/api2pdf/assets/samples/sample-word-doc.docx', { inline: false, filename: 'test.pdf' }).then(function(result) { console.log(result); }); ``` -------------------------------- ### Compress PDF Source: https://github.com/api2pdf/api2pdf.node/blob/master/README.md Compresses an existing PDF file to reduce its size, optimizing it for storage or faster transfer. ```javascript var url = 'https://LINK-TO-PDF'; a2pClient.pdfsharpCompress(url).then(function(result) { console.log(result); }); ``` -------------------------------- ### Api2Pdf Result Format Source: https://github.com/api2pdf/api2pdf.node/blob/master/README.md Describes the structure of the result object returned by the Api2Pdf API calls, including success status, file URL, cost, and error information. ```APIDOC Successful Result Format: { 'FileUrl': 'https://link-to-file-only-available-for-24-hours', 'MbOut': 0.08830547332763672, 'Cost': 0.00017251586914062501, 'Success': true, 'Error': null, 'ResponseId': '6e46637a-650d-46d5-af0b-3d7831baccbb' } Failed Result Format: { 'Success': false, 'Error': 'some reason for the error', 'ResponseId': '6e46637a-650d-46d5-af0b-3d7831baccbb' } ``` -------------------------------- ### Add Password to PDF Source: https://github.com/api2pdf/api2pdf.node/blob/master/README.md Sets a user password for an existing PDF file. This protects the PDF from unauthorized access. ```javascript var url = 'https://LINK-TO-PDF'; var userpassword = "hello"; a2pClient.pdfsharpAddPassword(url, userpassword).then(function(result) { console.log(result); }); ``` -------------------------------- ### Merge PDFs from URLs Source: https://github.com/api2pdf/api2pdf.node/blob/master/README.md Merges multiple PDFs specified by their URLs into a single PDF. The order of URLs determines the order in the merged document. ```javascript var urls = ['url-to-pdf1', 'url-to-pdf2']; a2pClient.pdfsharpMerge(urls).then(function(result) { console.log(result); }); ``` -------------------------------- ### Delete Generated PDF Source: https://github.com/api2pdf/api2pdf.node/blob/master/README.md Manually deletes a generated PDF file using its unique response ID. By default, files are deleted after 24 hours. ```javascript var responseId = result.ResponseId //from previous api call a2pClient.utilityDelete(responseId); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.