PDF jet

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);

        // 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.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();
        bos.Close();
    }

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

}   // End of Example_11.cs

© 2017 Innovatics Inc.