|
@@ -34,6 +34,7 @@ namespace Business.Core.Utilities
|
|
|
Spire.Barcode.BarcodeSettings settings = new BarcodeSettings();
|
|
Spire.Barcode.BarcodeSettings settings = new BarcodeSettings();
|
|
|
settings.Type = BarCodeType.QRCode;
|
|
settings.Type = BarCodeType.QRCode;
|
|
|
settings.Data = context;
|
|
settings.Data = context;
|
|
|
|
|
+ settings.Data2D = context;
|
|
|
settings.X = 0.7f;
|
|
settings.X = 0.7f;
|
|
|
settings.LeftMargin = 0;
|
|
settings.LeftMargin = 0;
|
|
|
settings.ShowText = false;
|
|
settings.ShowText = false;
|
|
@@ -59,9 +60,38 @@ namespace Business.Core.Utilities
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
/// 生成条形码
|
|
/// 生成条形码
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
- public void GenerateBarcode()
|
|
|
|
|
- {
|
|
|
|
|
-
|
|
|
|
|
|
|
+ /// <param name="filePath"></param>
|
|
|
|
|
+ /// <param name="context"></param>
|
|
|
|
|
+ public void GenerateBarcode(string filePath, string context, string savePath)
|
|
|
|
|
+ {
|
|
|
|
|
+ PdfDocument pdf = new PdfDocument();
|
|
|
|
|
+ //读取文件
|
|
|
|
|
+ pdf.LoadFromFile(filePath);
|
|
|
|
|
+ PdfPageBase pb = pdf.Pages.Add();
|
|
|
|
|
+ pdf.Pages.Remove(pb);
|
|
|
|
|
+
|
|
|
|
|
+ //使用Spire.Barcode的BarcodeSettings和BarcodeGenerator类创建条形码图形
|
|
|
|
|
+ Spire.Barcode.BarcodeSettings settings = new BarcodeSettings();
|
|
|
|
|
+ settings.Type = BarCodeType.Codabar;
|
|
|
|
|
+ settings.Data = context;
|
|
|
|
|
+ settings.Data2D = context;
|
|
|
|
|
+ settings.ShowText = false;
|
|
|
|
|
+ settings.ShowTopText = false;
|
|
|
|
|
+ settings.ShowTextOnBottom = false;
|
|
|
|
|
+ settings.ShowCheckSumChar = false;
|
|
|
|
|
+ Spire.Barcode.BarCodeGenerator generator = new BarCodeGenerator(settings);
|
|
|
|
|
+ Image image = generator.GenerateImage(new Size(40,20));
|
|
|
|
|
+
|
|
|
|
|
+ //绘制二维码图形到PDF
|
|
|
|
|
+ PdfImage pdfImage = PdfImage.FromImage(image);
|
|
|
|
|
+ for (int i = 0; i < pdf.Pages.Count; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ var page = pdf.Pages[i];
|
|
|
|
|
+ page.Canvas.DrawImage(pdfImage, page.Size.Width / 2 - pdfImage.Width / 2, page.Size.Height - pdfImage.Height);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //保存文档
|
|
|
|
|
+ pdf.SaveToFile(savePath);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|