Add Barcodes in HTML to PDF
Beyond providing extensive support for custom fonts such as Google fonts, IronPDF also supports stamping barcode onto your PDF documents. This allows developers to include barcode information in your rendered PDFs with ease.
Steps to Generate a PDF with a Barcode Using IronPDF
First, ensure the IronPDF library is installed and imported into your project. Then, an instance of the ChromePdfRenderer
class is initialized, which allows you to render HTML content into high-quality PDF documents.
Next, you need to create your barcode content. In our case, we have created an HTML string that incorporates a Google Fonts link for the "Libre Barcode 128" font. Then, use the RenderHtmlAsPdf
method to turn the HTML content into a new PDF document.
Following the HTML rendering, a barcode stamp is created with the text "Hello World" and the Code39 encoding format. This stamp is then applied to the PDF document using the ApplyStamp
method.
Finally, the generated PDF is saved to a file named "bc-test.pdf" using the SaveAs
method. This straightforward process enables you to produce a PDF with both styled text and barcode content efficiently in your C# applications. It should be noted that in some cases, this functionality won't support your barcode type, such as with QR Codes. In these instances, an efficient solution would be to use IronBarcode to generate this barcode or QR Code and then add it to your PDF as an image.
Click here to view the How-to Guide, including examples, sample code, and files