Convert HTML to PDF Online using Node.js API

Convert HTML to PDF Online using Node.js API

HTML is a fundamental file format for webpages and a majority of web browsers support HTML format as the default rendering language. As a node.js developer, you can convert your HTML files to PDF documents programmatically on the cloud using GroupDocs.Conversion Cloud API. The online HTML to PDF converter API allows you to convert single or multiple HTML pages to PDF documents for reading offline articles and sharing files in a portable format. So in this article, we are going to discuss the steps on how to convert HTML to PDF online using Node.js API.

The following topics shall be covered in this article:

HTML to PDF Conversion REST API and Node.js SDK Installation

In order to convert HTML page to PDF file format, I will be using the Node.js SDK of GroupDocs.Conversion Cloud API. This API allows you to convert your documents to any file format you need. It supports the conversion of more than 50 types of documents and images such as Word, Excel, PowerPoint, PDF, HTML, JPG/JPEG, PNG, CAD. It also provides .NET, Java, PHP, Ruby, Android, and Python SDKs as its document conversion family members for the Cloud API.

You can install GroupDocs.Conversion Cloud to your Node.js applications using the following command in the console:

npm install groupdocs-conversion-cloud

Please get your Client ID and Client Secret from the dashboard before you start following the steps and available code examples. Once you have your ID and secret, add in the code as shown below:

How to Convert HTML to PDF file in Node.js using REST API

You can convert HTML file to PDF file by following the simple steps given below:

  1. Upload the HTML file to the cloud
  2. Convert HTML to PDF online in Node.js
  3. Download the converted PDF file

Upload the file

Firstly, upload the HTML file to the Cloud using the following code sample:

As a result, the uploaded HTML file will be available in the files section of your dashboard on the cloud.

Convert HTML to PDF using Node.js

Please follow the steps mentioned below to convert HTML to PDF file programmatically:

  • Create an instance of ConvertApi
  • Create ConvertSettings instance
  • Set your storage name
  • next, set the input file path
  • Now, provide “pdf” to format
  • Set the output file path
  • Create ConvertDocumentRequest instance
  • Further, get results by calling the ConvertApi.convertDocument() method

The following code example shows how to convert HTML to PDF format using REST API in Node.js:

How to convert HTML to PDF using Node.js

Convert HTML to PDF using Node.js

Download the Converted File

The above code sample will save the converted PDF file on the cloud. You can download it using the following code sample:

Convert HTML to PDF format with Advanced Options in Node.js

You can convert HTML to PDF using the steps mentioned below with some advanced settings:

  • Create an instance of ConvertApi
  • Create ConvertSettings instance
  • Set your storageName
  • Set the html file path
  • Assign “pdf” to format
  • Define HtmlConvertOptions
  • Set various convert settings such as fromPage, pagesCount, fixedLayout , etc.
  • Provide convertOptions and set output file path
  • Next, create an object of ConvertDocumentRequest class
  • Get results by calling the ConvertApi.convertDocument() method

The following code example shows how to convert HTML to PDF file online using advanced convert options:

Convert HTML to PDF Online Free

How to use HTML to PDF converter online free? Please try the following free HTML to PDF converter online, which is developed using the above API.

Conclusion

In this article, you have learned:

  • how to convert HTML to PDF format on the cloud;
  • upload the HTML file and then download the converted PDF file from the cloud;
  • how to convert HTML to PDF file in Node.js using advanced options;

You can learn more about GroupDocs.Conversion Cloud API using the documentation. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser.

Ask a question

Feel free to ask your queries/question about how to convert HTML to PDF file, via our Forum.

FAQs

How do I convert HTML to PDF ?

Install our js library to convert HTML to PDF online programmatically. You can visit the documentation for complete API details.

How long does it take to convert HTML to PDF in node js?

JavaScript HTML to PDF library works very fast and you can convert HTML to PDF quickly, in a few seconds.

How to convert HTML to PDF file using REST API?

Create an instance of ConvertApi, set the values of the convert settings and invoke the convertDocument method with ConvertDocumentRequest to for converting HTML file to PDF file.

How to convert HTML file into PDF free online?

HTML file to PDF converter free online allows you to export HTML file to PDF format, quickly and easily. Once the conversion is completed, you can download the PDF file.

How can I save a webpage as a PDF online for free?

  • Open our free HTML to PDF converter online.
  • Click inside the file drop area to upload HTML webpage or drag & drop HTML file.
  • Click on Convert Now button. Your HTML file will be uploaded and converted to PDF format using our node.js html2pdf library.
  • Download link of output files will be available instantly after conversion.

How to install HTML to PDF converter free download library?

Install HTML file into PDF converter free download Java library to create, and convert HTML to PDF file programmatically.

How do I convert Word to JPG offline in windows?

Please visit this link to download HTML file to PDF converter software free for windows. This online HTML to PDF converter free download software can be used to transform HTML file to PDF file in windows quickly, with a single click.

Is it safe to use HTML to PDF converter free online?

Yes, no one has access to your uploaded files and the uploaded files will be deleted after 24 hours.

See Also

We recommend you to visit the following articles to learn about: