This API allows you to merge two PDF files into a single PDF file. It is built using Node.js, Express, and pdf-lib.
-
Clone the repository:
git clone <repository-url> cd <repository-name>
-
Install the required dependencies:
npm install
-
Create the necessary directories:
mkdir uploads
-
Start the server:
npm start
The server will start running on port 5000 (or the port specified in the environment variable
PORT). -
Use a tool like Postman or
curlto send a POST request to the/mergeendpoint with two PDF files.Example
curlcommand:curl -F "pdf1=@path/to/your/first.pdf" -F "pdf2=@path/to/your/second.pdf" http://localhost:5000/merge -o merged.pdf
This command sends a POST request with two PDF files and saves the merged PDF as
merged.pdf.
- Description: Merges two PDF files into one.
- Request: Multipart/form-data with two files.
pdf1: The first PDF file.pdf2: The second PDF file.
- Response:
- On success: The merged PDF file is returned as a download.
- On error: A JSON response with an error message.
curl -F "pdf1=@path/to/first.pdf" -F "pdf2=@path/to/second.pdf" http://localhost:5000/merge -o merged.pdf- If exactly two PDF files are not uploaded, the server responds with a 400 status code and a message: "Please upload exactly 2 PDF files."
- If an internal server error occurs, the server responds with a 500 status code and a JSON message: "something went wrong - check all inputs."