In this tutorial, we will show you how to create a PDF from a scratch in JavaScript using PDF.co Web API

  1. JavaScript Sample Code
  2. PDF.co API Key
  3. Source File and Destination
  4. Setup Text Annotations
  5. Run Program
  6. Generated PDF Output
  7. PDF from Scratch Demo

Step 1: JavaScript Sample Code

  • To begin. First, enter the JavaScript sample code in the Visual Studio Code editor. You can also use your favorite editor in JavaScript. You can get the source code at this link.

Step 2: PDF.co API Key

  • In line 10, add your PDF.co API Key. You can get the API Key in your PDF.co dashboard.

PDF.co API Key

Step 3: Source File and Destination

  • In line 14, blank the source file to create a new PDF.
  • In line 23, type in your desired output PDF file name.

Source File and Destination

Step 4: Setup Text Annotation

Let’s set up the text annotation

  • In lines 27 and 28, enter the text coordinates values of X and Y. Kindly click this link to find X and Y coordinates for placing text.
  • In line 29, add your text value to set for this field.
  • In lines 30-32, set the value of your font name, font size, and text color.

Setup Text Annotations

Step 5: Run Program

  • Now, let’s run the program. In your terminal, type node your_program_name.js to see the result.

Step 6: Generated PDF Output

  • Here’s the generated PDF output from scratch.
Generated PDF Output
Generated PDF Output

Step 7: PDF from Scratch Demo

  • Here’s a quick demo to create a PDF from scratch
PDF from Scratch Demo
PDF from Scratch Demo

In this tutorial, you learned how to create PDFs from scratch using JavaScript. You also learned how to use the PDF.co Web API to generate PDF.

Related Pages: