如何在 PDF 文件上加印条形码
如何用 C# 在 PDF 文档上加印 BarCode
立即在您的项目中开始使用IronBarcode,并享受免费试用。
在现有 PDF 页面上添加条形码
除了 将 BarCode 导出为 PDF在 IronBarcode 中,最受欢迎的功能之一是可以在.NET、Java、Python 或 Node js 上加盖印章。 生成的条形码
用户可以直接在现有的 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")
从上面的代码片段中,我们只需调用 StampToExistingPdfPage()使用
GeneratedBarcode对象的
方法将该对象印到 PDF 文档上。 以下是此方法中使用的参数:
- pdfFilePath`:指向内存中 PDF 文档的路径的 System.String 。
x
:PDF 页面水平位置的 System.Int32,单位为像素。y
:PDF 页面垂直位置的 System.Int32,单位为像素。- 页面编号要加盖戳记的 PDF 页面的System.Int32。请注意,此值为 1-索引,因此第一页表示为 1。
密码要输入 PDF 的密码的 System.String 。 此参数为可选参数,仅用于受密码保护的 PDF 文档。 如果要加盖印章的 PDF 没有密码保护,用户可以将此参数留空。
运行上面的代码片段后,"生成的条形码 "将立即加盖到 PDF 文档中,而无需中间的文档保存步骤。
在多个PDF页面上添加条形码
有时,需要在多个页面而不是一个页面上加盖相同的 BarCode。 用户可以使用 StampToExistingPdfPages 代替循环使用上述方法在多个页面上加盖相同的 BarCode()您可以使用
GeneratedBarcode类中的
方法来直接完成这项工作。 下面的代码片段演示了如何使用这种方法。
: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,单位为像素。- 页面编号要加盖戳记的 PDF 页面的IEnumerable
。请注意,这些值以 1 为索引,因此 PDF 的第一页表示为 1。 - 密码要输入 PDF 的密码的 System.String 。 此参数为可选参数,仅用于受密码保护的 PDF 文档。 如果要加盖印章的 PDF 没有密码保护,用户可以将此参数留空。