title: Generate pdf with barcode in Node.js
body: <p>I am using <a href="https://github.com/devongovett/pdfkit" rel="nofollow noreferrer">https://github.com/devongovett/pdfkit</a> to generate PDF files which I can do simply with something like</p>
  <pre><code>app.get('/get-pdf', (req, res) =&gt; {
    const doc = new PDFDocument();
    const filename = 'my_pdf.pdf';
  
    res.setHeader('Content-disposition', 'attachment; filename=&quot;' + filename + '&quot;');
    res.setHeader('Content-type', 'application/pdf');
  
    const content = &quot;Some content&quot;;
  
    doc.y = 300;
    doc.text(content, 50, 50);
    doc.pipe(res);
    doc.end();
  });
  </code></pre>
  <p>But I also want to generate an UPC-A barcode:</p>
  <p><a href="https://i.stack.imgur.com/0YyTx.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0YyTx.gif" alt="enter image description here" /></a></p>
  <p>I have found the library <a href="https://github.com/lindell/JsBarcode" rel="nofollow noreferrer">https://github.com/lindell/JsBarcode</a> which can generate such barcode from just the 12-digit code. However, it seems the library is mainly used in the client.</p>
  <p>I want to generate a PDF with such barcode, but I don't know how to do it or if JsBarcode isn't too complex for just this single type of barcode.</p>
  <h1>Edit</h1>
  <p>As suggested in the comments, I did try to generate a the barcode with the UPC-A font:</p>
  <pre><code>app.get('/get-pdf', (req, res) =&gt; {
    const doc = new PDFDocument();
    const filename = 'my_pdf.pdf';
  
    res.setHeader('Content-disposition', 'attachment; filename=&quot;' + filename + '&quot;');
    res.setHeader('Content-type', 'application/pdf');
  
    doc.font('/fonts/UPC-A.ttf').fontSize(50).text('012345678905');
    doc.pipe(res);
    doc.end();
  });
  </code></pre>
  <p>from which I get</p>
  <p><a href="https://i.stack.imgur.com/e8mSF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/e8mSF.png" alt="enter image description here" /></a></p>
  <p>which does look good, but it doesn't look exactly like common UPC-A barcodes.</p>
  <p>I used the font at <a href="http://www.fontpalace.com/font-download/UPC-A/" rel="nofollow noreferrer">http://www.fontpalace.com/font-download/UPC-A/</a>.</p>