Skip to content

Commit 45950ea

Browse files
Merge pull request #40 from aspose-barcode/agent/two-dimensional-barcode-types/2026-04-25-012903
Add generated Aspose.BarCode examples for two-dimensional-barcode-types
2 parents 1188fbf + 1783cd8 commit 45950ea

7 files changed

Lines changed: 290 additions & 0 deletions
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using Aspose.BarCode;
3+
using Aspose.BarCode.Generation;
4+
5+
class Program
6+
{
7+
static void Main()
8+
{
9+
// Sample text to encode
10+
const string codeText = "Rectangular DataMatrix";
11+
12+
// Create a DataMatrix barcode generator
13+
using (var generator = new BarcodeGenerator(EncodeTypes.DataMatrix, codeText))
14+
{
15+
// The exact 10x30 rectangular size is not available in the DataMatrixVersion enum.
16+
// Choose the nearest rectangular ECC200 version (12 rows x 36 columns).
17+
generator.Parameters.Barcode.DataMatrix.DataMatrixVersion = DataMatrixVersion.ECC200_12x36;
18+
19+
// Save the barcode image as PNG
20+
generator.Save("datamatrix.png");
21+
}
22+
23+
Console.WriteLine("DataMatrix barcode generated: datamatrix.png");
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using Aspose.BarCode;
3+
using Aspose.BarCode.Generation;
4+
5+
class Program
6+
{
7+
static void Main()
8+
{
9+
// Sample payload that benefits from a larger symbol size
10+
string payload = "This is a longer text payload intended to demonstrate a larger Han Xin barcode generation.";
11+
12+
// Create a Han Xin barcode generator with the payload
13+
using (var generator = new BarcodeGenerator(EncodeTypes.HanXin, payload))
14+
{
15+
// Han Xin supports only square symbols. Rectangular shapes or custom row/column
16+
// configurations are not available. The version is set to Auto so the library
17+
// selects the appropriate square size based on the payload length.
18+
generator.Parameters.Barcode.HanXin.Version = HanXinVersion.Auto; // Han Xin supports square formats only
19+
20+
// Optional: set error correction level (L2 provides moderate recovery)
21+
generator.Parameters.Barcode.HanXin.ErrorLevel = HanXinErrorLevel.L2;
22+
23+
// Save the generated barcode image
24+
generator.Save("HanXin.png");
25+
}
26+
27+
Console.WriteLine("Han Xin barcode generated and saved as HanXin.png");
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System;
2+
using System.IO;
3+
using Aspose.BarCode.Generation;
4+
using Aspose.BarCode.BarCodeRecognition;
5+
using Aspose.Drawing.Imaging;
6+
7+
class Program
8+
{
9+
static void Main()
10+
{
11+
// Sample GS1 Composite codetext: linear part (01) and 2D part (21) separated by '|'
12+
string codeText = "(01)12345678901231|(21)A123";
13+
14+
// Create a generator for GS1 Composite Bar with default linear component (GS1Code128)
15+
using (var generator = new BarcodeGenerator(EncodeTypes.GS1CompositeBar, codeText))
16+
{
17+
// Save image to memory stream
18+
using (var defaultStream = new MemoryStream())
19+
{
20+
generator.Save(defaultStream, BarCodeImageFormat.Png);
21+
defaultStream.Position = 0;
22+
23+
// Read barcode and verify default linear component type
24+
using (var reader = new BarCodeReader(defaultStream, DecodeType.GS1CompositeBar))
25+
{
26+
var result = reader.ReadBarCodes()[0];
27+
var extended = result.Extended.GS1CompositeBar;
28+
if (extended.OneDType != DecodeType.GS1Code128)
29+
{
30+
Console.WriteLine("FAILED: Default linear component type is not GS1Code128.");
31+
}
32+
else
33+
{
34+
Console.WriteLine("PASS: Default linear component type is GS1Code128.");
35+
}
36+
}
37+
}
38+
39+
// Change linear component type to EAN13
40+
generator.Parameters.Barcode.GS1CompositeBar.LinearComponentType = EncodeTypes.EAN13;
41+
42+
// Save updated barcode to another memory stream
43+
using (var changedStream = new MemoryStream())
44+
{
45+
generator.Save(changedStream, BarCodeImageFormat.Png);
46+
changedStream.Position = 0;
47+
48+
// Read barcode and verify changed linear component type
49+
using (var reader = new BarCodeReader(changedStream, DecodeType.GS1CompositeBar))
50+
{
51+
var result = reader.ReadBarCodes()[0];
52+
var extended = result.Extended.GS1CompositeBar;
53+
if (extended.OneDType != DecodeType.EAN13)
54+
{
55+
Console.WriteLine("FAILED: Linear component type change to EAN13 not reflected in decoded data.");
56+
}
57+
else
58+
{
59+
Console.WriteLine("PASS: Linear component type successfully changed to EAN13.");
60+
}
61+
}
62+
}
63+
}
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.IO;
3+
using Aspose.BarCode;
4+
using Aspose.BarCode.Generation;
5+
using Aspose.Pdf;
6+
7+
class Program
8+
{
9+
static void Main()
10+
{
11+
// Output PDF file path
12+
const string outputPdfPath = "qr_form.pdf";
13+
14+
// Generate QR code and save to a memory stream as PNG
15+
using (var barcodeStream = new MemoryStream())
16+
{
17+
using (var generator = new BarcodeGenerator(EncodeTypes.QR))
18+
{
19+
generator.CodeText = "https://example.com";
20+
generator.Parameters.Barcode.QR.ErrorLevel = QRErrorLevel.LevelH;
21+
generator.Save(barcodeStream, BarCodeImageFormat.Png);
22+
}
23+
24+
// Reset stream position before reading
25+
barcodeStream.Position = 0;
26+
27+
// Create PDF document and add the barcode image
28+
using (var pdfDoc = new Document())
29+
{
30+
var page = pdfDoc.Pages.Add();
31+
// Place the image at specified rectangle (llx, lly, urx, ury)
32+
page.AddImage(barcodeStream, new Aspose.Pdf.Rectangle(100, 500, 300, 700));
33+
pdfDoc.Save(outputPdfPath);
34+
}
35+
}
36+
37+
Console.WriteLine("QR code added to PDF as a static image. Interactive ButtonField image embedding requires System.Drawing support not available in this runner.");
38+
}
39+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using System.IO;
3+
using Aspose.BarCode;
4+
using Aspose.BarCode.Generation;
5+
using Aspose.Drawing;
6+
using Aspose.Drawing.Imaging;
7+
8+
class Program
9+
{
10+
static void Main()
11+
{
12+
// Data to encode in the QR code
13+
string codeText = "https://example.com";
14+
15+
// Local file path for the thumbnail image
16+
string localPath = "qr_thumbnail.jpg";
17+
18+
// Create and configure the QR code generator
19+
using (var generator = new BarcodeGenerator(EncodeTypes.QR, codeText))
20+
{
21+
// Use interpolation auto‑size mode and set image dimensions
22+
generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation;
23+
generator.Parameters.ImageWidth.Point = 200f;
24+
generator.Parameters.ImageHeight.Point = 200f;
25+
26+
// QR specific settings
27+
generator.Parameters.Barcode.QR.ErrorLevel = QRErrorLevel.LevelM;
28+
29+
// Visual appearance
30+
generator.Parameters.Barcode.BarColor = Color.Black;
31+
generator.Parameters.BackColor = Color.White;
32+
33+
// Generate the image into a memory stream as JPEG
34+
using (var ms = new MemoryStream())
35+
{
36+
generator.Save(ms, BarCodeImageFormat.Jpeg);
37+
ms.Position = 0;
38+
39+
// Save locally
40+
File.WriteAllBytes(localPath, ms.ToArray());
41+
42+
// Real cloud upload (commented out – SDK not available in the runner)
43+
// Example for Azure Blob Storage:
44+
// var blobClient = new BlobClient(connectionString, containerName, blobName);
45+
// blobClient.Upload(ms);
46+
// Example for AWS S3:
47+
// var s3Client = new AmazonS3Client(accessKey, secretKey, RegionEndpoint.USEast1);
48+
// var putRequest = new PutObjectRequest
49+
// {
50+
// BucketName = bucketName,
51+
// Key = objectKey,
52+
// InputStream = ms,
53+
// ContentType = "image/jpeg"
54+
// };
55+
// s3Client.PutObjectAsync(putRequest).Wait();
56+
}
57+
}
58+
59+
Console.WriteLine($"QR code thumbnail saved to '{localPath}'.");
60+
}
61+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using Aspose.BarCode.Generation;
3+
using Aspose.BarCode;
4+
5+
class Program
6+
{
7+
static void Main()
8+
{
9+
const string outputFile = "qr_mask3.bmp";
10+
11+
using (BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.QR, "Sample QR Code"))
12+
{
13+
// Mask pattern setting is not available in this version of Aspose.BarCode.
14+
// The QR code will be generated with default settings.
15+
generator.Save(outputFile);
16+
}
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System;
2+
using System.IO;
3+
using Aspose.BarCode;
4+
using Aspose.BarCode.Generation;
5+
using Aspose.Pdf;
6+
using Aspose.Drawing;
7+
8+
class Program
9+
{
10+
static void Main()
11+
{
12+
// Output PDF file path
13+
string pdfPath = "BarcodeDocument.pdf";
14+
15+
// Generate barcode image into a memory stream
16+
using (var barcodeStream = new MemoryStream())
17+
{
18+
using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "1234567890"))
19+
{
20+
// Optional visual settings
21+
generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Black;
22+
generator.Parameters.BackColor = Aspose.Drawing.Color.White;
23+
24+
// Save barcode as PNG to the stream
25+
generator.Save(barcodeStream, BarCodeImageFormat.Png);
26+
barcodeStream.Position = 0;
27+
}
28+
29+
// Create a new PDF document and embed the barcode image
30+
using (var pdfDoc = new Aspose.Pdf.Document())
31+
{
32+
// Add a page to the document
33+
var page = pdfDoc.Pages.Add();
34+
35+
// Define placement rectangle (points)
36+
float llx = 100f; // lower-left X
37+
float lly = 500f; // lower-left Y
38+
float width = 200f; // desired width
39+
float height = 100f; // desired height
40+
float urx = llx + width; // upper-right X
41+
float ury = lly + height; // upper-right Y
42+
43+
// Add the barcode image at the specified coordinates
44+
page.AddImage(barcodeStream, new Aspose.Pdf.Rectangle(llx, lly, urx, ury));
45+
46+
// Save the PDF document
47+
pdfDoc.Save(pdfPath);
48+
}
49+
}
50+
51+
Console.WriteLine("PDF created at: " + Path.GetFullPath(pdfPath));
52+
}
53+
}

0 commit comments

Comments
 (0)