title: How can I convert the first page of a PDF to a JPG using the NodeJS imagemagick library?
body: <p>I am attempting to convert pdf files into a preview icon jpg
  using the imagemagick library for NodeJS. I am trying to 
  generate a preview of only the <strong>first page</strong> (for multi-page pdfs).</p>
  
  <p>In the normal command line imagemagick program this can be 
  done easily by saying <strong>"convert file.pdf[0] file.jpg"</strong><br>
  where the [0] tells it to only convert the first page. </p>
  
  <p>However I am not sure how to do that with this library.
  I tried concatenating [0] to the filename, but it just 
  reads it as part of the real file name.  Anyone know of 
  a way around this using this library?</p>
  
  <p>I had a look around for a while and found this, but 
  they are not using this library. 
  <a href="https://stackoverflow.com/questions/32903737/convert-pdf-to-png-node-js">Convert PDF to PNG Node.JS</a></p>
  
  <p>The specific library I am using is located here: <a href="https://www.npmjs.com/package/imagemagick" rel="nofollow noreferrer">https://www.npmjs.com/package/imagemagick</a></p>
  
  <p>The code I am working with is below:</p>
  
  <pre><code>            let path = '/tmp/';
              let pageNumber = '[0]';
              let filePath =  path + fileId + fileName + pageNumber; 
              let imgFilePath = path + fileId + '.jpg';
              let writeStream = fs.createWriteStream(filePath);
              writeStream.on('error',err =&gt; {
                reject(err);
              });
              stream.pipe(writeStream);
  
  
                im.convert([
                  filePath,
                  '-background','white',
                  '-alpha','remove',
                  '-resize','192x192',
                  '-quality','100',
                  imgFilePath
                ],
  </code></pre>