MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

import java.awt.Color;
import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.Barcode;
import com.lowagie.text.pdf.BarcodeEAN;
import com.lowagie.text.pdf.BarcodeEANSUPP;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;

public class MainClass {

    public static void main(String[] args) throws Exception {
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
        document.open();

        PdfContentByte cb = writer.getDirectContent();
        BarcodeEAN codeEAN = new BarcodeEAN();
        codeEAN.setCode("4512345678906");
        Paragraph p = new Paragraph();

        // EANSUPP
        document.add(new Paragraph("ISBN 0-111-11111-1"));
        codeEAN.setCodeType(Barcode.EAN13);
        codeEAN.setCode("1111111111111");
        BarcodeEAN codeSUPP = new BarcodeEAN();
        codeSUPP.setCodeType(Barcode.SUPP5);
        codeSUPP.setCode("55499");
        codeSUPP.setBaseline(-2);
        BarcodeEANSUPP eanSupp = new BarcodeEANSUPP(codeEAN, codeSUPP);
        document.add(eanSupp.createImageWithBarcode(cb, null, Color.blue));

        document.add(p);
        document.close();
    }
}