using Aspose.BarCode;
using Aspose.BarCode.Generation;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AsposeBarCodeGenerator
{
class Program
{
public enum BarcodeFontTypes
{
None = 0,
Datamatrix = 1,
Pdf417 = 2,
MacroPdf417 = 3,
GS1DataMatrix = 4,
MicroPdf417 = 5,
GS1QR = 6,
MaxiCode = 7,
DotCode = 8,
AustraliaPost = 9,
Postnet = 10,
Planet = 11,
OneCode = 12,
RM4SCC = 13,
DatabarOmniDirectional = 14,
DatabarTruncated = 15,
Aztec = 16,
DatabarLimited = 17,
DatabarExpandedStacked = 18,
DatabarStacked = 19,
DatabarStackedOmniDirectional = 20,
SingaporePost = 21,
AustralianPosteParcel = 22,
SwissPostParcel = 23,
PatchCode = 24,
Code32 = 25,
DataLogic2of5 = 26,
DutchKIX = 27,
UpcaGs1Code128Coupon = 28,
UpcaGs1DatabarCoupon = 29,
CodablockF = 30,
GS1CodablockF = 31,
DatabarExpanded = 32,
QR = 33,
Code16K = 34,
UPCA = 35,
SSCC18 = 36,
SCC14 = 37,
EAN14 = 38,
EAN13 = 39,
EAN8 = 40,
Pharmacode = 41,
GS1Code128 = 42,
Code39Standard = 43,
Code39Extended = 44,
Code93Standard = 45,
Code93Extended = 46,
CodeBlockF = 47,
Code11 = 48,
Codabar = 49,
Code128 = 50,
ISBN = 51,
UPCE = 52,
ISMN = 53,
PZN = 54,
OPC = 55,
DeutschePostLeitcode = 56,
DeutschePostIdentcode = 57,
ISSN = 58,
MSI = 59,
VIN = 60,
Matrix2of5 = 61,
ITF14 = 62,
IATA2of5 = 63,
ItalianPost25 = 64,
Interleaved2of5 = 65,
Standard2of5 = 66,
ITF6 = 67
}
static void Main(string[] args)
{
LoadAsposeLicense();
BuildBarCodeImage(EncodeTypes.GS1Code128);
BuildBarCodeImage(EncodeTypes.GS1DataMatrix);
BuildBarCodeImage(EncodeTypes.PatchCode);
BuildBarCodeImage(EncodeTypes.DatabarExpandedStacked);
BuildBarCodeImage(EncodeTypes.DatabarLimited);
}
private static void SetBarCodeGenerator(BarCodeGenerator barCodeGenerator, float width, float height, float left, float right, bool setWidth)
{
barCodeGenerator.AutoSizeMode = AutoSizeMode.Interpolation;
barCodeGenerator.BarCodeHeight.Inches = height;
barCodeGenerator.Margins.Left.Pixels = left;
barCodeGenerator.Margins.Right.Pixels = right;
if (setWidth)
barCodeGenerator.BarCodeWidth.Inches = width;
}
private static void LoadAsposeLicense()
{
Aspose.BarCode.License bclicense = new Aspose.BarCode.License();
var licenseFile = "Aspose.Total.lic";
try
{
bclicense.SetLicense(licenseFile);
Console.WriteLine("License set successfully.");
}
catch (Exception e)
{
Console.WriteLine("\nThere was an error setting the license: " + e.Message);
}
}
public static void BuildBarCodeImage(SymbologyEncodeType encodeType)
{
BarCodeGenerator barCodeGenerator = new BarCodeGenerator(encodeType);
string fileFolder = "c:\\temp\\asposefonts\\2\\";
string filename = encodeType.TypeName + ".png";
SetBarCodeGenerator(barCodeGenerator, 0, 1f, 0f, 0f, false);
barCodeGenerator.CodeTextStyle.Location = CodeLocation.None;
barCodeGenerator.CodeText = "777777777+D0281726+1+10+0";
try
{
barCodeGenerator.Save(Path.Combine(fileFolder, filename), BarCodeImageFormat.Png);
}
catch (Exception ex)
{
}
}
public static void BuildSquareBarCodeImage(SymbologyEncodeType encodeType)
{
BarCodeGenerator barGen = new BarCodeGenerator(encodeType);
string fileFolder = "c:\\temp\\asposefonts\\2\\";
string filename = encodeType.TypeName + ".png";
SetBarCodeGenerator(barGen, 1f, 1f, 0f, 0f, true);
barGen.CodeTextStyle.Location = CodeLocation.None;
barGen.CodeText = "777777777+D0281726+1+10+0";
try
{
barGen.Save(Path.Combine(fileFolder, filename), BarCodeImageFormat.Png);
}
catch (Exception ex)
{
}
}
}
}