如何在 PDF 文件上加印条形码
如何用 C# 在 PDF 文档上加印 BarCode
- 下载 C# 库以在 PDF 上加盖条形码
- 使用指定的条形码类型和值创建条形码
- 指定条形码尺寸
- 利用
StampToExistingPdfPage
方法在单个PDF页面上盖上条形码 - 使用
StampToExistingPdfPages
方法在多个 PDF 页面上加盖条形码
立即在您的项目中开始使用IronBarcode,并享受免费试用。
在现有 PDF 页面上添加条形码
除了将条形码导出为PDF之外,IronBarcode中最受欢迎的功能之一是能够将GeneratedBarcode
直接盖章到用户现有的PDF文档上。 以下代码片段演示了如何做到这一点。
:path=/static-assets/barcode/content-code-examples/how-to/StampBarcodeOnExistingPdfPage.cs
using IronBarCode;
GeneratedBarcode myBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode/", BarcodeEncoding.Code128, 200, 100);
myBarcode.StampToExistingPdfPage("pdf_file_path.pdf", x: 200, y: 100, 3, "password");
Imports IronBarCode
Private myBarcode As GeneratedBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode/", BarcodeEncoding.Code128, 200, 100)
myBarcode.StampToExistingPdfPage("pdf_file_path.pdf", x:= 200, y:= 100, 3, "password")
从上面的代码片段中,我们只需使用GeneratedBarcode
对象调用StampToExistingPdfPage()
方法,将对象盖印到PDF文档上。 以下是此方法中使用的参数:
pdfFilePath
:指向内存中PDF文档路径的System.String。x
: PDF页面水平位置的System.Int32,单位为像素。y
:PDF页面在像素中的垂直位置的System.Int32。pageNumber
:PDF 页要加盖印章的System.Int32。请注意,此值是从1开始索引的,因此第一页表示为1。-
password
:输入到PDF中的密码的System.String。 此参数是可选的,仅用于受密码保护的PDF文档。 如果要加盖印章的 PDF 没有密码保护,用户可以将此参数留空。运行上述代码片段将会立即将
GeneratedBarcode
印入PDF文档,而无需中间的文档保存步骤。
在多个PDF页面上添加条形码
有时,需要在多个页面而不是一个页面上加盖相同的 BarCode。 用户可以直接使用GeneratedBarcode
类中的StampToExistingPdfPages()
方法,而不是循环上述方法以在多个页面上加盖相同的条形码。 下面的代码片段演示了如何使用这种方法。
:path=/static-assets/barcode/content-code-examples/how-to/StampBarcodeOnMultiplePdfPages.cs
using IronBarCode;
using System.Collections.Generic;
GeneratedBarcode myBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode/", BarcodeEncoding.Code128, 200, 100);
List<int> pages = new List<int>();
pages.Add(1);
pages.Add(2);
pages.Add(3);
myBarcode.StampToExistingPdfPages("pdf_file_path.pdf", x: 200, y: 100, pages, "password");
Imports IronBarCode
Imports System.Collections.Generic
Private myBarcode As GeneratedBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode/", BarcodeEncoding.Code128, 200, 100)
Private pages As New List(Of Integer)()
pages.Add(1)
pages.Add(2)
pages.Add(3)
myBarcode.StampToExistingPdfPages("pdf_file_path.pdf", x:= 200, y:= 100, pages, "password")
以下是此方法中使用的参数:
pdfFilePath
:指向内存中PDF文档路径的System.String。x
: PDF页面水平位置的System.Int32,单位为像素。y
:PDF页面在像素中的垂直位置的System.Int32。pageNumbers
:要加盖印章的 PDF 页面 IEnumerable。请注意,这些值是从 1 开始索引的,因此 PDF 的第一页表示为 1。 password
:输入到PDF中的密码的System.String。 此参数是可选的,仅用于受密码保护的PDF文档。 如果要加盖印章的 PDF 没有密码保护,用户可以将此参数留空。