Merging a pdf using Javascript

Have you heard about pdflib library, you didn’t so here is the documentation page for you.

Pdflib package

Pdflib Package

So here what I have done, First I have installed the package and Add this package to json file as usual. Then I have imported th…


This content originally appeared on DEV Community and was authored by Kumaran KM

Have you heard about pdflib library, you didn't so here is the documentation page for you.

Pdflib package

Pdflib Package

So here what I have done, First I have installed the package and Add this package to json file as usual. Then I have imported that package on code, Then I have used catch syntax to check for errors.

Then we need to load the pdf that we need to merge with the help of the load method inside the asynchronous function. If you want to get pdf as a user input then you can try multer package, but for now, I don't need it. I will provide a documentation link for multer package below.

Multer package

Then, then with create() method, I have created a new empty document. And then I have added the first pdf file into that document with the help of copyPages() method. Once I have copied the first pdf, then I will concatenate the second pdf with the same copypage method. Then the pdf will get merged into that new document, and now it's time for naming a file. With the help of writeFileSync() I have synced the file and named it with .pdf extension. So here what the output looks like.

After merging
Alt Text

Thanks for taking the time to read my blog.
Happy coding :)


This content originally appeared on DEV Community and was authored by Kumaran KM


Print Share Comment Cite Upload Translate Updates
APA

Kumaran KM | Sciencx (2021-07-27T10:43:40+00:00) Merging a pdf using Javascript. Retrieved from https://www.scien.cx/2021/07/27/merging-a-pdf-using-javascript/

MLA
" » Merging a pdf using Javascript." Kumaran KM | Sciencx - Tuesday July 27, 2021, https://www.scien.cx/2021/07/27/merging-a-pdf-using-javascript/
HARVARD
Kumaran KM | Sciencx Tuesday July 27, 2021 » Merging a pdf using Javascript., viewed ,<https://www.scien.cx/2021/07/27/merging-a-pdf-using-javascript/>
VANCOUVER
Kumaran KM | Sciencx - » Merging a pdf using Javascript. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/07/27/merging-a-pdf-using-javascript/
CHICAGO
" » Merging a pdf using Javascript." Kumaran KM | Sciencx - Accessed . https://www.scien.cx/2021/07/27/merging-a-pdf-using-javascript/
IEEE
" » Merging a pdf using Javascript." Kumaran KM | Sciencx [Online]. Available: https://www.scien.cx/2021/07/27/merging-a-pdf-using-javascript/. [Accessed: ]
rf:citation
» Merging a pdf using Javascript | Kumaran KM | Sciencx | https://www.scien.cx/2021/07/27/merging-a-pdf-using-javascript/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.