In this tutorial, We will show you how you can use Ghostscript with NodeJs to merge multiple PDF files into single file. Using Ghostscript, it is possible to merge multiple PDF files into a single PDF file with a single command from your terminal or command line.
Type the command
sudo apt-get install Ghostscript to download and install the Ghostscript package and all of the packages it depends on.
Merging PDFs with Ghostscript
Here is the Ghostscript command to merge two are more PDFs in a single file:
In the above command, we are merging two Pdf files called
file_2.pdf files into single Pdf file called
NOTE: The order of the input files matters and determines the merging order in the final PDF.
Merging PDFs with NodeJs using Ghostscript
We can run the preceding gs command with NodeJs’s
exec() function and we can also pass the filenames to it. Below is the sample php script:
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.
I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.