<?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: Mohamed Shafnas</title>
    <description>The latest articles on DEV Community by Mohamed Shafnas (@mshafnas125).</description>
    <link>https://dev.to/mshafnas125</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%2F861867%2Fee170bc3-c0c4-4ef9-90a4-6d57b3d2f46c.png</url>
      <title>DEV Community: Mohamed Shafnas</title>
      <link>https://dev.to/mshafnas125</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mshafnas125"/>
    <language>en</language>
    <item>
      <title>PDFToImage PDF Box</title>
      <dc:creator>Mohamed Shafnas</dc:creator>
      <pubDate>Fri, 13 May 2022 08:19:57 +0000</pubDate>
      <link>https://dev.to/mshafnas125/pdftoimage-pdf-box-2mjn</link>
      <guid>https://dev.to/mshafnas125/pdftoimage-pdf-box-2mjn</guid>
      <description>&lt;p&gt;Hi, I am working on a project where I want to convert the pdf file pages into png images then I am compressing the images using the imagemin with imageminpngquant plugin. the process is working fine when I am using the following command line code from the node js.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pdfConvert = spawn('java', [
                        '-jar',
                        `${pdfBoxPath}`,
                        'PDFToImage',
                        '-dpi',
                        dpi,
                        '-imageType',
                        'png',
                        '-outputPrefix',
                        `${rawPdfDir}/page-`,
                        `./${pdfFilePath}`,
                    ]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;but when I want to convert only specfic pages I am using the following code and the image is also getting converted but while compressing it is showing cannot decode image for some images.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (let i = 0; i &amp;lt; requiredPages.length; i++) {
                        // split the page ranges 
                        const range = requiredPages[i].trim().split('-');
                        const startPage = range[0];
                        const endPage = range[1] ? range[1] : range[0];

                        // console.log(`range -&amp;gt; ${range}`);
                        // console.log(`requiredPages -&amp;gt; ${requiredPages[i]}`);

                        pdfConvert = spawn('java', [
                            '-jar',
                            `${pdfBoxPath}`,
                            'PDFToImage',
                            '-dpi',
                            dpi,
                            '-imageType',
                            'png',
                            '-outputPrefix',
                            `${rawPdfDir}/page-`,
                            `./${pdfFilePath}`,
                            `-startPage`,
                            `${startPage}`,
                            `-endPage`,
                            `${endPage}`
                        ]);

                    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I am using the loop in this case.&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>java</category>
    </item>
  </channel>
</rss>
