How to Convert TEXT file to PDF Online in Node.js

How to Convert TEXT file to PDF Online in Node.js
How to Convert TEXT file to PDF Online in Node.js

TXT files are used to store plain text or to create quick notes in various applications. However, since Notepad files don’t provide advanced features like PDF. So in certain cases, you may need to convert TEXT files to PDF. In order to automate TEXT to PDF conversion programmatically, this article demonstrated how to convert TEXT file to PDF online in Node.js.

The following topics shall be covered in this article:

TEXT to PDF Conversion REST API and Node.js SDK

To convert TEXT to PDF, I will use the Node.js SDK of GroupDocs.Conversion Cloud API. It is a platform-independent library and document conversion solution. It allows you to seamlessly convert your documents and images of any supported file format to any format you need. You can easily convert between more than 50 types of documents and images such as Word, PowerPoint, Excel, PDF, HTML, CAD, raster images, etc. 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 project 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, please add in the code as shown below:

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

You can convert text to pdf in nodejs programmatically on the cloud by following the steps given below:

  1. Upload the TEXT file to the cloud
  2. Convert TEXT to PDF file
  3. Download the converted PDF file

Upload the TEXT File

Firstly, upload the text file to the cloud using the following code sample:

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

Convert TEXT to PDF format in Node.js

You can convert text to pdf programmatically by following the steps as given below:

  • Create an instance of the ConvertApi
  • Create an instance of the ConvertSettings
  • Set storage name and the input text file path
  • Assign “pdf” to the format
  • Now, provide the output pdf file path
  • Create ConvertDocumentRequest with ConvertSettings
  • Convert by calling the convertDocument() method with ConvertDocumentRequest

The following code example shows how to convert TEXT file to PDF format in Nodejs using REST API:

How to convert TEXT to PDF format in Node.js
Convert TEXT to PDF format in Node.js

Download the Converted File

The above code sample will save the converted pdf file on the cloud. Now you know how to convert TEXT to PDF in node. Next, download pdf file using the following code sample:

Free Online TEXT to PDF Converter

How to convert TEXT to PDF online free? Please try the following to online convert text to pdf free, which is developed using the above API.


Text and PDF files are widely used to store and transmit the data. So, this article covered how to turn text into pdf in Node.js applications. Now you know:

  • how to convert text to pdf using Node.js;
  • programmatically upload text file and then download converted pdf file;
  • free online text to pdf converter;

Furthermore, 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

You can ask your queries about how to convert text into pdf format, via our Free Support Forum

See Also