How to add barcode to PDF
Contents
[
Hide
]
PDFs are a popular medium for generating reports or any official documents in many organizations. Aspose.PDF is part of Conholdate.Total for .NET to generate PDF documents in .NET. It is easy to add barcodes to PDF by integrating Aspose.BarCode with Aspose.PDF. This article briefly describes how to add high-quality barcode images to PDFs.
Create barcode in C#
To create a barcode, follow these simple steps:
- Create an object of the BarcodeGenerator class.
- Set the text using CodeText property of the BarcodeGenerator object.
- Set the barcode type (Code128 as an example) from the EncodeTypes enumeration.
Following code shows the steps in detail.
Save barcode to MemoryStream
Once the barcode is generated (in the first step), it can be saved to MemoryStream as shown in the following code.
Create PDF in C#.NET and add barcode iamge
Barcode image is saved to a MemoryStream, so we can now create a PDF and add barcode to it as shown in the steps below.
- Create a PDF by creating an object of Aspose.Pdf.Document class.
- Add a new page to the PDF
- Use Aspose.Pdf.Facades.PdfFileMend class object to add the image to PDF
Following code shows these steps in detail