This client library is a wrapper for the Api2Pdf.com REST API. See full REST api documentation at https://www.api2pdf.com/documentation/v2. Api2Pdf is a powerful API that supports HTML to PDF, URL to PDF, HTML to Image, URL to Image, Thumbnail / image pre
npm install api2pdf
a2pClient.chromeUrlToPdf('https://www.github.com')
.then(function(result) {
console.log(result); //successful api call
}, function(rejected) {
console.log(rejected); //an error occurred
}
);
`
$3
{
'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'
}
$3
{
'Success': false,
'Error': 'some reason for the error',
'ResponseId': '6e46637a-650d-46d5-af0b-3d7831baccbb'
}
wkhtmltopdf
Convert HTML to PDF
`
a2pClient.wkHtmlToPdf('Hello, World
').then(function(result) {
console.log(result);
});
`
Convert HTML to PDF (download PDF as a file and specify a file name)
`
a2pClient.wkHtmlToPdf('Hello, World
', { inline: false, filename: 'test.pdf' }).then(function(result) {
console.log(result);
});
`
Convert HTML to PDF (use object for advanced wkhtmltopdf settings)
View full list of wkhtmltopdf options available.
`
var options = { orientation: 'landscape', pageSize: 'A4'};
a2pClient.wkHtmlToPdf('Hello, World
', { options: options }).then(function(result) {
console.log(result);
});
`
Convert URL to PDF
`
a2pClient.wkUrlToPdf('https://www.github.com').then(function(result) {
console.log(result);
});
`
Convert URL to PDF (download PDF as a file and specify a file name)
`
a2pClient.wkUrlToPdf('https://www.github.com', { inline: false, filename: 'test.pdf' }).then(function(result) {
console.log(result);
});
`
Convert URL to PDF (use object for advanced wkhtmltopdf settings)
View full list of wkhtmltopdf options available.
`
var options = { orientation: 'landscape', pageSize: 'A4'};
a2pClient.wkUrlToPdf('https://www.github.com', { options: options }).then(function(result) {
console.log(result);
});
`
---
Headless Chrome
Convert HTML to PDF
`
a2pClient.chromeHtmlToPdf('Hello, World
').then(function(result) {
console.log(result);
});
`
Convert HTML to PDF (download PDF as a file and specify a file name)
`
a2pClient.chromeHtmlToPdf('Hello, World
', { inline: false, filename: 'test.pdf' }).then(function(result) {
console.log(result);
});
`
Convert HTML to PDF (use options for advanced Headless Chrome settings)
View full list of Headless Chrome options available.
`
var options = { landscape: true };
a2pClient.chromeHtmlToPdf('Hello, World
', { options: options }).then(function(result) {
console.log(result);
});
`
Convert URL to PDF
`
a2pClient.chromeUrlToPdf('https://www.github.com').then(function(result) {
console.log(result);
});
`
Convert URL to PDF (download PDF as a file and specify a file name)
`
a2pClient.chromeUrlToPdf('https://www.github.com', { inline: false, filename: 'test.pdf' }).then(function(result) {
console.log(result);
});
`
Convert URL to PDF (use keyword arguments for advanced Headless Chrome settings)
View full list of Headless Chrome options available.
`
var options = { landscape: true };
a2pClient.chromeUrlToPdf('https://www.github.com', { options: options }).then(function(result) {
console.log(result);
});
`
Convert HTML to Image
`
a2pClient.chromeHtmlToImage('Hello, World
').then(function(result) {
console.log(result);
});
`
Convert URL to Image
`
a2pClient.chromeUrlToImage('https://www.github.com').then(function(result) {
console.log(result);
});
`
---
LibreOffice
Convert any office file to PDF, image file to PDF, email file to PDF, HTML to Word, HTML to Excel, and PDF to HTML. Any file that can be reasonably opened by LibreOffice should be convertible. Additionally, we have an endpoint for generating a thumbnail of the first page of your PDF or Office Document. This is great for generating an image preview of your files to users.
You must provide a url to the file. Our engine will consume the file at that URL and convert it.
Convert Microsoft Office Document or Image to PDF
`
a2pClient.libreOfficeAnyToPdf('https://www.api2pdf.com/wp-content/themes/api2pdf/assets/samples/sample-word-doc.docx').then(function(result) {
console.log(result);
});
`
Convert Microsoft Office Document or Image to PDF (download PDF as a file and specify a file name)
`
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);
});
`
Thumbnail or Image Preview of a PDF or Office Document or Email file
`
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 Microsoft Word or Docx
`
a2pClient.libreOfficeHtmlToDocx('http://www.api2pdf.com/wp-content/uploads/2021/01/sampleHtml.html').then(function(result) {
console.log(result);
});
`
Convert HTML to Microsoft Excel or Xlsx
`
a2pClient.libreOfficeHtmlToXlsx('http://www.api2pdf.com/wp-content/uploads/2021/01/sampleTables.html').then(function(result) {
console.log(result);
});
`
Convert PDF to HTML
`
a2pClient.libreOfficePdfToHtml('http://www.api2pdf.com/wp-content/uploads/2021/01/1a082b03-2bd6-4703-989d-0443a88e3b0f-4.pdf').then(function(result) {
console.log(result);
});
`
---
PdfSharp - Merge / Concatenate Two or More PDFs, Add bookmarks to pdfs, add passwords to pdfs
To use the merge endpoint, supply a list of urls to existing PDFs. The engine will consume all of the PDFs and merge them into a single PDF, in the order in which they were provided in the list.
Merge PDFs from list of URLs to existing PDFs
`
var urls = ['url-to-pdf1', 'url-to-pdf2'];
a2pClient.pdfsharpMerge(urls).then(function(result) {
console.log(result);
});
`
Add bookmarks to existing PDF
`
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);
});
`
Add password to existing PDF
`
var url = 'https://LINK-TO-PDF';
var userpassword = "hello";
a2pClient.pdfsharpAddPassword(url, userpassword).then(function(result) {
console.log(result);
});
`
Compress existing PDF
`
var url = 'https://LINK-TO-PDF';
a2pClient.pdfsharpCompress(url).then(function(result) {
console.log(result);
});
`
Extract pages from existing PDF
`
var url = 'https://LINK-TO-PDF';
var start = "2";
var end = null;
a2pClient.pdfsharpExtractPages(url, start, end).then(function(result) {
console.log(result);
});
`
---
Helper Methods
Delete a PDF on Command with delete(responseId)
By default, Api2Pdf will delete your generated file 24 hours after it has been generated. For those with high security needs, you may want to delete your file on command. You can do so by making an DELETE api call with the responseId attribute that was returned on the original JSON payload.
`
var responseId = result.ResponseId //from previous api call
a2pClient.utilityDelete(responseId);
``