
- #ITEXT EXPRESS PDF#
- #ITEXT EXPRESS CODE#
The main principles of using the iText 7 library for barcode generation have been explained above.
#ITEXT EXPRESS CODE#
Since the library supports many 1D barcodes, I use a generalized code to avoid duplication. Linear (1D) barcodes are represented by lines and spaces of various widths that create specific patterns. The screenshot of Data Matrix (including encoded URL value) taken from example-datamatrix.pdf.
#ITEXT EXPRESS PDF#
Additionally, we may add the barcode value into the pdfDocument(line 20) in order to test PDF generation easily (lines 27-30). Finally, we just add the image as the codeImage variable into the pdfDocument (line 18). We do that by using the createCodeImage method (lines 33-37) and storing it as a codeImage variable for use in the next step. Also, we need to convert the form referenced by the codeFormObject instance into an Image instance (line 17). Here we need to pass the pdfDocument instance. Next, we create an instance of the PdfFormXObject class from our codeFormObject variable (line 16). This instance is assigned into the codeFormObject variable to be used next. First, we need to create an instance of the BarcodeQRCode class dedicated to handling the QR code where we pass the barcode value (to be encoded into the QR code) as the constructor argument (line 15). To create our first QR code, we should proceed with several steps in order to add a barcode instance into the pdfDocument properly. This instance represents the root element where any desired content can be added (lines 11-13). Create an instance of the PdfDocument class as the pdfDocument variable will be used as the main entry point to the PDF content. To start QR code generation, follow these steps: QR CodeĪ QR code (abbreviated from Quick Response code) often contains data for a locator, identifier, or tracker that points to a website or application. Let's start with QR codes as this barcode is pretty common these days. IText 7 supports, as already mentioned, only two types of 2D barcodes: QR codes and Data Matrixes. Matrix or multi-dimensional (2D) barcodes are represented by black and white "dots." These barcodes are compact and capable of holding high-capacity symbols in the unit area. Additionally, my project has recently been upgraded to the latest libraries (Spring Boot 2.4.2 and iText 7.1.14). Please check my previous article where I covered that. Prerequisite: All the codes below, expect iText 7, are basic knowledge. Therefore, I'll begin with an explanation of generating the 2D barcodes, because there are only two of them. The section dedicated to 1D barcodes contains some generalization as there are five supported barcodes. Nevertheless, I believe the library supports all the common ones. IText 7 library supports many barcodes, but not all the options mentioned on Wikipedia. In general, we recognize two basic barcode types: If you want to see some examples of barcodes, please check the barcode sheet on their site. Most barcode standards are managed by the GS1 organization. Here is a simple definition of ‘barcode’ according to Wikipedia:Ī barcode or bar code is a method of representing data in a visual, machine-readable form. Firstly, I'll provide a short overview of barcodes, and then demonstrate barcode generation for every supported barcode type in the library. Here, I focus on the barcode support provided by the iText 7 library. In my previous article, I reviewed the basics of iText 7.