The HTML to PDF Conversion Service is a utility that allows you to convert HTML content into PDF files. It provides three different API endpoints for PDF generation:
- Generate PDF from a URL
- Generate PDF from HTML data in the request body
- Generate PDF from an HTML file provided in the request body
These instructions will help you get started with the service on your local machine.
- Install the wkhtmltopdf command line tool on your system
- Be sure the wkhtmltopdf command line tool is in your PATH when you're done installing
- Node.js and npm installed on your system
-
Clone this repository to your local machine:
git clone https://github.com/rg-rupeee/html-to-pdf.git
-
Navigate to the project directory:
cd html-to-pdf
-
Install the project dependencies:
npm install
-
Create a new file in the same directory and name it
.env.local
. This will be your local environment configuration file. Locate the.example.env
file in your project directory. This file should contain sample configuration keys and values. -
Start the service:
npm run start:local
-
Access the Swagger documentation at
http://localhost:3010/swagger
in your web browser.Here, you can explore the available API endpoints, view request examples, and even try out the API calls using the interactive Swagger UI interface.
The service offers the following API endpoints for HTML to PDF conversion:
- Endpoint:
/api/v1/html-pdf/wkhtmltopdf/url
- Method: POST
- Description: Convert HTML content from a given URL to a PDF file.
- Endpoint:
/api/v1/html-pdf/wkhtmltopdf/data
- Method: POST
- Description: Convert HTML content provided in the request body to a PDF file.
- Endpoint:
/api/v1/html-pdf/wkhtmltopdf/file
- Method: POST
- Description: Convert HTML content from a file provided in the request body to a PDF file.
You can use tools like curl
to make API calls to the service. Here are some example curl
commands for each endpoint:
curl --location '{{BASE_URL}}/api/v1/html-pdf/wkhtmltopdf/url' \
--header 'Content-Type: application/json' \
--data '{
"url": "https://www.google.com",
"callbackUri": "https://webhook.site/d0a1ec94-93d5-4071-96ea-f8b35749dcd5"
}'
curl --location '{{BASE_URL}}/api/v1/html-pdf/wkhtmltopdf/data' \
--header 'Content-Type: application/json' \
--data '{
"fileData": "<h1>Hello I am Rupesh</h1>",
"callbackUri": "https://webhook.site/d0a1ec94-93d5-4071-96ea-f8b35749dcd5"
}'
curl --location '{{BASE_URL}}/api/v1/html-pdf/wkhtmltopdf/file' \
--header 'Content-Type: application/json' \
--form 'callbackUri="https://webhook.site/d0a1ec94-93d5-4071-96ea-f8b35749dcd5"' \
--form 'file=@"/path/to/your/html/file.html"'
- This service uses the
wkhtmltopdf
library for HTML to PDF conversion.
This project is licensed under the MIT License - see the LICENSE file for details.