We often need to convert HTML files to PDF owing to several strengths of PDF file format. Considering the features of PDF files, Aspose.PDF Cloud API has been structured and designed to cater to all of your PDF related needs. You can create, edit or manipulate supported file formats. Among other file format conversions, HTML to PDF conversion is one of the famous use cases.

Aspose.PDF Cloud is a REST API so you would not need any complicated environment configurations or setups. Several SDKs are also available so that you can easily achieve the requirements. You can work with any of the SDK including .NET, Java, PHP, Android, Python, Ruby, Node.js, Swift or Go. Get started today by signing up with existing GitHub, Twitter, Facebook or Google account. A generous free trial is granted when you sign up.

Convert HTML to PDF file

You can convert HTML to PDF by following below steps:

  1. Upload the HTML file and related CSS, JS, Images as a single ZIP file to Cloud Storage
  2. Get JSON Web Token for authentication
  3. Call the API
  4. Save generated PDF file received as API response

Following cURL code follows these steps and converts the HTML file:

You can also notice several optional parameters specified with the API call in above code. These include page dimensions and page margins of the generated PDF document which can be specified beforehand. Please note that the standard unit in Aspose APIs is point, where 72 points equal 1 inch. Therefore, according to passed values, the margin is set to half-inch and the page dimensions equal to A4 size.

Input HTML file

Output PDF file

High fidelity PDF rendering with Aspose.PDF Cloud API via single API call is noteworthy in the screenshot. Likewise, this simple yet powerful feature is capable of rendering even complicated documents in WYSIWYG format.

Moreover, Aspose Cloud APIs support 3rd party cloud storages including Google Drive, Dropbox etc. The following cURL example is using Amazon S3 Storage for conversion:

This code will upload source file to AWS S3 Storage and will save generated PDF file on local storage. It also sets the page size of PDF document as of A4 standard, which can be verified from the document’s properties tab as in the screenshot below:

Java Example

Let us now consider a Java example to convert HTML to PDF with Aspose.PDF Cloud SDK for Java. The SDK is a wrapper around REST API in Java that allows you to process documents while gaining all benefits of strong types and IDE highlights. You can install it by adding below dependency in the project’s POM file:


Aspose.PDF Cloud SDK also includes a suite of unit tests. The unit tests also serve the purpose of examples that explain how to work with Aspose.PDF Cloud SDK for Java. Learn more.
Following is the Java code to convert HTML file to PDF document:

These are some simple and basic demonstrations of high fidelity rendering of PDF documents. Furthermore, the API is rich in features and comes with free trial without any watermarks or limitations. In case you have any concerns, questions or suggestions, get in touch with us via free support forums and we would love to assist you. Happy coding!

Suggested Articles: