如何在PDF上加蓋條碼
如何在 C# 中將條碼加蓋於 PDF 文件上
立即在您的專案中使用IronBarcode,並享受免費試用。
在現有的 PDF 頁面上蓋上條碼
Apart from 將條碼匯出為PDFIronBarcode 中最受歡迎的功能之一是能夠蓋章 生成的條碼
直接在使用者現有的 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 類型。pageNumber
:要加章的 PDF 頁數,類型為 System.Int32。請注意,該值是從 1 開始計算的,所以第一頁表示為 1。password
:用於輸入到 PDF 中的 System.String 類型密碼。 此參數是可選的,僅用於受密碼保護的 PDF 文件。 如果需要加蓋的 PDF 沒有被密碼保護,使用者可以將此參數留空。運行上述程式碼片段將會立即將
GeneratedBarcode
印製在 PDF 文件上,無需中間的文件儲存步驟。
在多個PDF頁面上蓋章條碼
有時,同一個條碼需要印在多個頁面上,而不是僅印在一個頁面上。 相較於循環上面的方法將相同的條碼蓋印在多個頁面上,用戶可以使用 StampToExistingPdfPages
。()從 GeneratedBarcode
類別中使用 method
直接進行此操作。 以下程式碼片段演示了如何使用此方法。
: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 沒有被密碼保護,使用者可以將此參數留空。