<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kumaran KM</title>
    <description>The latest articles on DEV Community by Kumaran KM (@kumarankm).</description>
    <link>https://dev.to/kumarankm</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F492942%2F35fb1a41-60aa-4a1d-b96f-9357567aa7ed.jpg</url>
      <title>DEV Community: Kumaran KM</title>
      <link>https://dev.to/kumarankm</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kumarankm"/>
    <language>en</language>
    <item>
      <title>Merging a pdf using Javascript</title>
      <dc:creator>Kumaran KM</dc:creator>
      <pubDate>Sun, 07 Feb 2021 17:24:24 +0000</pubDate>
      <link>https://dev.to/kumarankm/merging-a-pdf-using-javascript-527i</link>
      <guid>https://dev.to/kumarankm/merging-a-pdf-using-javascript-527i</guid>
      <description>&lt;h2&gt; Before merging&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ACDgHoVi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0ggq58qzl8bvdcsmzd4k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ACDgHoVi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0ggq58qzl8bvdcsmzd4k.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Have you heard about pdflib library, you didn't so here is the documentation page for you.&lt;/p&gt;

&lt;h2&gt;Pdflib package&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.npmjs.com/package/pdf-lib"&gt;Pdflib Package&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.npmjs.com/package/multer"&gt;Multer package&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt; After merging &lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hs1GoX_z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5u30460cv79gdmeyb6ki.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hs1GoX_z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5u30460cv79gdmeyb6ki.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for taking the time to read my blog.&lt;br&gt;
Happy coding :)&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>codequality</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
