How to Stamp Barcodes on PDFs
How to Stamp Barcodes on PDF Documents in C#
- Download C# library to stamp barcode on PDF
- Create a barcode with a specified barcode type and value
- Specify the barcode size
- Utilize the
StampToExistingPdfPage
method to stamp the barcode on a single PDF page - Use the
StampToExistingPdfPages
method to stamp the barcode on multiple PDF pages
Start using IronBarcode in your project today with a free trial.
Stamp Barcode on Existing PDF Page
Apart from exporting barcodes as PDF, one of the most popular functionalities in IronBarcode is the ability to stamp the GeneratedBarcode
directly onto a user's existing PDF document. The follow code snippet demonstrates how to do this.
: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")
From the code snippet above, we simply call the StampToExistingPdfPage()
method with a GeneratedBarcode
object to stamp the object onto the PDF document. Below are the parameters used in this method:
pdfFilePath
: A System.String of the path that points to the PDF document in memory.x
: A System.Int32 of the horizontal position of the PDF page in pixels.y
: A System.Int32 of the vertical position of the PDF page in pixels.pageNumber
: A System.Int32 of the PDF page to stamp. Note this value is 1-indexed, so the first page is represented as 1.password
: A System.String of a password to input into the PDF. This argument is optional and is only used for PDF documents protected by a password. Users can leave this argument blank if the PDF to be stamped is not password-protected.
Running the code snippet above will stamp the GeneratedBarcode
immediately into the PDF document without an intermediate document saving step.
Stamp Barcode on Multiple PDF Pages
Sometimes, the same barcode is needed to be stamped on multiple pages rather than on one page. Instead of looping the above method to stamp the same barcode on multiple pages, users can use StampToExistingPdfPages()
method from the GeneratedBarcode
class to do this directly. The following code snippet demonstrates how this method can be used.
: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")
Below are the parameters used in this method:
pdfFilePath
: A System.String of the path that points to the PDF document in memory.x
: A System.Int32 of the horizontal position of the PDF page in pixels.y
: A System.Int32 of the vertical position of the PDF page in pixels.pageNumbers
: A IEnumerableof the PDF pages to stamp. Note these values are 1-indexed, so the first page of a PDF is represented as 1. password
: A System.String of a password to input into the PDF. This argument is optional and is only used for PDF documents protected by a password. Users can leave this argument blank if the PDF to be stamped is not password-protected.