Using the BarCode class to draw Code128 barcodes

Example_11.pdf
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;

using PDFjet.NET;


/**
 *  Example_11.cs
 *
 */
public class Example_11 {

    public Example_11() {

        FileStream fos = new FileStream("Example_11.pdf", FileMode.Create);
        BufferedStream bos = new BufferedStream(fos);

        PDF pdf = new PDF(bos);
        // Before you enable this flag please read PDFJET.ZLIB.TXT
        // in the "optional" directory.
        // pdf.setCompressor(Compressor.ORIGINAL_ZLIB);

        // Font f1 = new Font(pdf, CoreFont.HELVETICA);

        Font f1 = new Font(pdf,
                new FileStream(
                        "fonts/DroidFonts/DroidSans.otf", FileMode.Open),
                CodePage.UNICODE,
                Embed.YES);

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

        BarCode code = new BarCode(BarCode.CODE128, "Hello, World!");
        code.SetPosition(170.0, 70.0);
        code.SetModuleLength(1.00);
        code.SetFont(f1);
        code.DrawOn(page);

        code = new BarCode(BarCode.CODE128, "G86513JVW0C");
        code.SetPosition(170.0, 170.0);
        code.SetModuleLength(0.75);
        code.SetDirection(BarCode.TOP_TO_BOTTOM);
        code.SetFont(f1);
        code.DrawOn(page);

        code = new BarCode(BarCode.CODE39, "WIKIPEDIA");
        code.SetPosition(270.0, 370.0);
        code.SetModuleLength(0.75);
        code.SetFont(f1);
        code.DrawOn(page);

        code = new BarCode(BarCode.CODE39, "CODE39");
        code.SetPosition(400.0, 70.0);
        code.SetModuleLength(0.75);
        code.SetDirection(BarCode.TOP_TO_BOTTOM);
        code.SetFont(f1);
        code.DrawOn(page);
        
        code = new BarCode(BarCode.CODE39, "CODE39");
        code.SetPosition(450.0, 70.0);
        code.SetModuleLength(0.75);
        code.SetDirection(BarCode.BOTTOM_TO_TOP);
        code.SetFont(f1);
        code.DrawOn(page);
        
        code = new BarCode(BarCode.UPC, "712345678904");
        code.SetPosition(450.0, 270.0);
        code.SetModuleLength(0.75);
        code.SetDirection(BarCode.BOTTOM_TO_TOP);
        code.SetFont(f1);
        code.DrawOn(page);

        pdf.Flush();
        bos.Close();
    }


    public static void Main(String[] args) {
        try {
            new Example_11();
        } catch (Exception e) {
            Console.WriteLine(e.StackTrace);
        }
    }

}   // End of Example_11.cs

© 2011 Innovatics Inc.