Skip to content

3.8 Draw PDF417 Barcode

OgreTransporter edited this page Mar 2, 2020 · 1 revision

The DrawPdf417Barcode method is an example of drawing a PDF417 barcode.

// Draw Barcode
private void DrawPdf417Barcode()
{
    // save graphics state
    Contents.SaveGraphicsState();

    // create PDF417 barcode
    Pdf417Encoder Pdf417 = new Pdf417Encoder();
    Pdf417.DefaultDataColumns = 3;
    Pdf417.Encode(ArticleLink);
    Pdf417.WidthToHeightRatio(2.5);

    // convert Pdf417 to black and white image
    PdfImage BarcodeImage = new PdfImage(Document);
    BarcodeImage.LoadImage(Pdf417);

    // draw image
    Contents.DrawImage(BarcodeImage, 1.1, 5.2, 2.5);

    // define a web link area coinsiding with the qr code
    double Height = 2.5 * Pdf417.ImageHeight / Pdf417.ImageWidth;
    Page.AddWebLink(1.1, 5.2, 1.1 + 2.5, 5.2 + Height, ArticleLink);

    // restore graphics sate
    Contents.RestoreGraphicsState();
    return;
}
Clone this wiki locally