Skip to content

barcode-bakery/example-dotnet-pdf417

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

This example repository will allow you to generate PDF417 barcodes. You can find more information on our Barcode Bakery website.

This is based on the barcode PDF417 library.

The library is not free, you must purchase a license in order to obtain it.

Installation

There are two ways to install our library:

  • With the command line, get the file from GitHub, run the following command.
PM> dotnet add PROJECT package BarcodeBakery.BarcodePDF417 --version 3.0.2

Requirements

  • .NET Standard 2.0
  • .NET Core 2.0+
  • .NET Framework 4.6.1+

Example usages

For a full example of how to use each symbology type, visit our API page.

Saving a PDF417 to a MemoryStream

public static async Task CreateAsync(string filePath, string? text = null)
{
    // Loading Font
    var font = new BCGFont("Arial", 18);

    // Don't forget to sanitize user inputs
    text = text?.Length > 0 ? text : "PDF417";

    // Label, this part is optional
    var label = new BCGLabel();
    label.SetFont(font);
    label.SetPosition(BCGLabel.Position.Bottom);
    label.SetAlignment(BCGLabel.Alignment.Center);
    label.SetText(text);

    // The arguments are R, G, B for color.
    var colorBlack = new BCGColor(0, 0, 0);
    var colorWhite = new BCGColor(255, 255, 255);

    Exception? drawException = null;
    BCGBarcode? barcode = null;
    try
    {
        var code = new BCGpdf417();
        code.SetScale(2);
        code.SetRatio(1);
        code.SetErrorLevel(2);
        code.SetCompact(false);
        code.SetQuietZone(true);
        code.SetForegroundColor(colorBlack); // Color of bars
        code.SetBackgroundColor(colorWhite); // Color of spaces

        code.AddLabel(label);

        code.Parse(text);
        barcode = code;
    }
    catch (Exception exception)
    {
        drawException = exception;
    }

    var drawing = new BCGDrawing(barcode, colorWhite);
    if (drawException != null)
    {
        drawing.DrawException(drawException);
    }

    // Saves the barcode into a MemoryStream
    var memoryStream = new System.IO.MemoryStream();
    await drawing.FinishAsync(BCGDrawing.ImageFormat.Png, memoryStream);
}

Saving the image to a file

Replace the last line of the previous code with the following:

// Saves the barcode into a file.
await drawing.FinishAsync(BCGDrawing.ImageFormat.Png, filePath);

This will generate the following:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages