PDF jet

Using the BarCode class to draw Code128 barcodes


Example_11.pdf
import java.io.*;

import com.pdfjet.*;


/**
 *  Example_11.java
 *
 */
public class Example_11 {

    public Example_11() throws Exception {

        FileOutputStream fos = new FileOutputStream("Example_11.pdf");

        PDF pdf = new PDF(fos);

        // Font f1 = new Font(pdf, CoreFont.HELVETICA);
        Font f1 = new Font(pdf,
                new BufferedInputStream(getClass().getResourceAsStream(
                        "/fonts/DroidFonts/DroidSans.otf")),
                CodePage.UNICODE,
                Embed.YES);

        Page page = new Page(pdf, Letter.PORTRAIT);

        BarCode code = new BarCode(BarCode.CODE128, "Hello, World!");
        code.setPosition(170.0f, 70.0f);
        code.setModuleLength(0.75f);
        code.setFont(f1);
        code.drawOn(page);

        code = new BarCode(BarCode.CODE128, "G86513JVW0C");
        code.setPosition(170.0f, 170.0f);
        code.setModuleLength(0.75f);
        code.setDirection(BarCode.TOP_TO_BOTTOM);
        code.setFont(f1);
        code.drawOn(page);

        code = new BarCode(BarCode.CODE39, "WIKIPEDIA");
        code.setPosition(270.0f, 370.0f);
        code.setModuleLength(0.75f);
        code.setFont(f1);
        code.drawOn(page);

        code = new BarCode(BarCode.CODE39, "CODE39");
        code.setPosition(400.0f, 70.0f);
        code.setModuleLength(0.75f);
        code.setDirection(BarCode.TOP_TO_BOTTOM);
        code.setFont(f1);
        code.drawOn(page);
        
        code = new BarCode(BarCode.CODE39, "CODE39");
        code.setPosition(450.0f, 70.0f);
        code.setModuleLength(0.75f);
        code.setDirection(BarCode.BOTTOM_TO_TOP);
        code.setFont(f1);
        code.drawOn(page);
        
        code = new BarCode(BarCode.UPC, "712345678904");
        code.setPosition(450.0f, 270.0f);
        code.setModuleLength(0.75f);
        code.setDirection(BarCode.BOTTOM_TO_TOP);
        code.setFont(f1);
        code.drawOn(page);

        pdf.flush();
        fos.close();
    }

    public static void main(String[] args) {
        try {
            new Example_11();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}   // End of Example_11.java

© 2017 Innovatics Inc.