Convert your web page to PDF instantly using Aspose.PDF cloud SDKs. Single command HTML to PDF conversion.

html to pdf converter

Overview

Are you wondering to enrich your Node.js application with an HTML to PDF converter? You are landed in a right place. Recently, we have published some blog posts such as PDF To DOC Converter – Aspose.PDF Cloud SDKs For Node.js, Convert Excel to PDF in Python | XLS Spreadsheet to PDF, and more. However, this is a new article in the series of Aspose.PDF Cloud Product Family and we will look into the Web to PDF conversion library by covering the following points.

An intro of file format converter(Aspose.PDF)

In our most recent blog post, we have comprehensively described what is Aspose.PDF and how it works. However, our previous blog post was about the conversion of PDF files to DOC using cloud-based SDKs provided by Aspose.PDF. Further, developers can opt for REST(representational state transfer) APIs or SDKs(software development kit). Both versions are available with complete documentation regarding development and usage. Moreover, the subscribers of Aspose.PDF may leverage of forum where they can open any discussion about features. The support team is pretty much alive toward questions/discussions to make the user’s experience hassle-free.

Above all, Aspose.Cloud Product Family comes up with a live editor where you can experience APIs in real-time and hence, you can test the HTML to PDF converter just from the UI. It gives you a really nice user-friendly interface where you can insert data and upload files to test the features. In addition, you can test the web to the PDF conversion feature yourself as shown in the image below.

html to pdf converter

Once you are done with the testing, you can view and select the subscription plan on the dashboard of Aspose.cloud. A free plan is also available to understand the whole ecosystem.

Business benefits of cloud-based document conversion API

In this section, we will explore why is it important to enrich your application with a file format converter and will also look into its business benefits. HTML files are rendered into the web browser and are used to develop business websites. The following benefits are worth mentioning here.

Competitive Edge

Think like you own an online business that is based on cloud services. It will always be a great deal to facilitate your users with maximum features to cope with routine tasks. File format converters are in good business at the current point in time due to various data file structures and Web to PDF conversion is pretty common among them.

Offline Access

As far as the HTML to PDF converter is concerned, the biggest perk of having a PDF version of a web page is that you can save it and can view it offline.

Editable

It is another characteristic attached with PDF files that you can edit all the way you want such as highlighting the text, digital signatures, rich annotations, and more.

Similarly, there are many other pros that come with Aspose.PDF cloud-based SDKs that you can integrate into your online business space in no time. The whole process is quite simple and friendly that you just enable it and the rest of the magic happens seamlessly.

How to convert HTML to PDF using Aspose.PDF cloud SDKs?

So far, we have gone through a file format converter(Aspose.PDF) and also have looked into some core benefits of having a cloud-based document conversion API. Next, we will see how can we set up Aspose.PDF in our Node.js app.

If you are new to our platform, please feel free to visit this tutorial in which we have defined every step regarding setting up Aspose.cloud. In addition, we have also elaborated on the pre-requisites.

As we have set up a basic project in Nestjs(i.e. Nod.js framework) to set up HTML to PDF converter on our localhost. Now, let’s open the “app.controller.ts” file placed inside the ‘src’ folder, and paste the following code to enable Web to PDF conversion in your Node.js app.

import { Controller, Post } from '@nestjs/common';
import { AppService } from './app.service';
import { PdfApi } from 'asposepdfcloud';
import \* as fs from 'fs';
@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}
  @Post('/html-to-pdf')
  async htmlToPdf() {
    const name = 'index.html';
    const SrcFile = '/' + name;
    const detFolder = '/myfolder';
    const resultFile = 'index.pdf';
    const resultPath = 'myfolder/' + resultFile;
    const storageName = 'testing';
    const fileToWrite = process.cwd() + '/' + resultFile;

    const pdfApi = new PdfApi(
      'YOUR-APPSID',
      'YOUR-APPKEY',
    );
    try {
      // Upload file to aspose cloud storage
      const data = fs.readFileSync(name);
      await pdfApi.uploadFile(SrcFile, new Buffer(data), 'testing');
      // Invoke Aspose.Pdf Cloud SDK API to create PDF file from HTML
      await pdfApi.putHtmlInStorageToPdf(
        resultFile,
        SrcFile,
        name,
        null,
        null,
        false,
        null,
        null,
        null,
        null,
        detFolder,
        storageName,
      );

      // Download pdf from cloud storage
      const fileData = await pdfApi.downloadFile(resultPath, storageName, '');
      const writeStream = fs.createWriteStream(fileToWrite);
      writeStream.write(fileData.body);

      return 'Web Page converted to PDF successfully';
    } catch (e) {
      throw e;
    }
  }
}

Finally, restart the server, you can make a post request at http://localhost:3000/html-to-pdf. Now, you should see a file named “index.pdf” in your project’s root folder. That’s all.

Conclusion

This is the end of this Aspose.PDF tutorial article. You have clearly seen how simple the whole process is where you can enrich your Node.js app with an enterprise-level HTML to PDF converter. Further, you can reduce costs associated with repetitive tasks and optimize performance by opting for a cloud-based file format converter. Now, you know how to convert HTML to PDF and are familiar with the Web to PDF conversion library offered by Aspose.PDF. Therefore, it is the right time to subscribe to the cloud-based SDKs for your Node.js application. In addition, there is comprehensive documentation for every feature of every online file convertor. There are various plans available and can opt for a free plan to explore further prior to making a purchase.

Finally, blog.aspose.cloud is writing new blog posts in a consistent manner. Therefore, please stay in touch for regular updates. Moreover, you can follow us on our social media accounts Facebook, LinkedIn, and Twitter.

Ask a question

Feel free to visit our forum which is very active to respond to questions and queries/discussions.

Explore

You may find the following links relevant: