Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
July 27, 2021 10:43 am GMT

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 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 :)


Original Link: https://dev.to/kumarankm4/merging-a-pdf-using-javascript-48c9

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To