HTML
JPG
PDF
XML
DOCX
PDF
Convert HTML to PDF in Node.js SDK
Export HTML documents to multiple formats including PDF with Aspose.PDF Cloud Node.js SDK
Get StartedHow to Convert HTML to PDF Using Node.js SDK
To convert HTML to PDF, we’ll use Aspose.PDF Cloud Node.js SDK This Cloud SDK SDK assists Node.js programmers in developing cloud-based PDF creator, annotator, editor, and converter apps using Node.js programming language via Aspose.PDF REST API. Open NPM package manager, search for Aspose.PDF Cloud, and install. You may also use the following command from the Package Manager Console.
Package Manager Console Command
npm install asposepdfcloud --save
Steps to Convert HTML to PDF via Node.js
Aspose.PDF Cloud Node.js developers can easily load & convert HTML files to PDF in just a few lines of code.
- Load your Application Secret and Key from the JSON file or set credentials in another way
- Create an object to connect to the Cloud API
- Upload your document file
- Perform the conversion using putHtmlInStorageToPdf
- Download the result if needed it
This sample code shows HTML to PDF Cloud Node.js SDK Conversion
const fs = require("fs");
const credentials = require("./credentials.json");
const { PdfApi } = require("asposepdfcloud");
// Load your Application Secret and Key from the JSON file or set credentials in another way
async function convertHTMLtoPDF() {
const localImageFileName = "C:\\Samples\\sample.html";
const storageFileName = "sample.html";
const pdfApi = new PdfApi(credentials.id, credentials.key);
let fileData = await fs.readFile(localImageFileName);
try {
let uploadResult = await pdfApi.uploadFile(storageFileName, fileData);
console.log(uploadResult.response.text);
}
catch (error) {
console.error(error.response.text);
}
try {
let convertResult = await pdfApi.putHtmlInStorageToPdf("sample-html-to-pdf.pdf", storageFileName);
console.log(convertResult.response.text);
const buffer = await pdfApi.downloadFile(STORAGE_FILENAME);
} catch (error) {
console.error(error.response.text);
}
}
Other Supported Conversions
You can also convert MD into many other file formats including few listed below.
BMP TO PDF (Bitmap Image)
CGM TO PDF (Microsoft Word Binary Format)
EMF TO PDF (Office 2007+ Words Document)
EPUB TO PDF (Enhanced Metafile Format)
GIF TO PDF (Graphical Interchange Format)
HTML TO PDF (Hyper Text Markup Language)
JPEG TO PDF (Joint Photographic Experts Group)
LATEX TO PDF (LaTeX Output Text)
PCL TO PDF (Printer Command Language)
MD TO PDF (Markdown)
PDF TO BMP (Bitmap Image)
PDF TO EPUB (E-book Format)
PDF TO GIF (Graphical Interchange Format)
PDF TO HTML (Hyper Text Markup Language)
PDF TO JPEG (Joint Photographic Experts Group)
PDF TO PDF/A (Portable Document Format)
PDF TO PNG (Portable Network Graphics)
PDF TO PPTX (Microsoft PowerPoint)
PDF TO SVG (Scalable Vector Graphics)
PDF TO TEX (Computer Graphics System)
PDF TO TIFF (Tagged Image Format)
PDF TO WORD (Microsoft Word Binary Format)
PDF TO XLSX (Microsoft Excel Open XML Format Spreadsheet file)
PDF TO XPS (XML Paper Specifications)
PNG TO PDF (Portable Network Graphics)
PS TO PDF (PostScript)
SVG TO PDF (Scalable Vector Graphics)
TEXT TO PDF (Text Document)
TIFF TO PDF (Tagged Image Format)
XPS TO PDF (XML Paper Specifications)