-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
52 lines (48 loc) · 1.92 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using BarcodeGenerator;
using BarcodeStandard;
using SkiaSharp;
using System.Drawing;
using System.Drawing.Imaging;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Grid;
using System.Text;
namespace BarcodeGenerator
{
internal class Program
{
static void Main(string[] args)
{
string barcodeData = "ST1050124";
var b = new Barcode();
b.IncludeLabel = true;
SkiaSharp.SKImage img = b.Encode(BarcodeStandard.Type.Code128, barcodeData);
var data = img.Encode(SKEncodedImageFormat.Png, 100);
FileStream stream = new FileStream("barcode.png", FileMode.Open, FileAccess.ReadWrite);
data.SaveTo(stream);
//Create a new PDF document.
PdfDocument document = new PdfDocument();
document.PageSettings.Size = new Syncfusion.Drawing.Size(288, 432);
document.PageSettings.Orientation = PdfPageOrientation.Landscape;
document.PageSettings.Margins.All = 18;
//Add a page to the document.
PdfPage page = document.Pages.Add();
//Create PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Set the standard font.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
//Draw the text.
graphics.DrawString("Hot Bread & Butter Pickles", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0));
PdfBitmap pdfImage = new PdfBitmap(stream);
graphics.DrawImage(pdfImage, 0, 30);
//Save the document.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath("Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
{
document.Save(outputFileStream);
}
//Close the document.
document.Close(true);
}
}
}