Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
In this tutorial, we explore the process of stamping barcodes on PDF files using Iron Barcode. To begin, ensure Iron Barcode is installed on your machine. The process starts by importing the Iron Barcode namespace and utilizing the CreateBarcode
method, which requires the content, encoding type, and dimensions for the barcode. In this example, a URL is encoded into a 100x100 pixel QR code.
Next, specify the PDF pages to be modified by creating a list of integers. Use the StampToExistingPdfPages
method to apply the barcode. This involves providing the PDF path, X and Y coordinates for placement, and pages for modification, with an optional password for protected files. Running the program applies the barcode to the defined pages, as demonstrated in the output PDF. The QR code, when scanned, redirects to the encoded URL. The tutorial concludes by inviting viewers to try a 30-day trial of the software for firsthand experience.
Here is an example code snippet to demonstrate the process:
// Import the necessary namespace
using IronBarCode;
class BarcodeExample
{
static void Main()
{
// Define the URL to be encoded in the QR code
string url = "https://www.example.com";
// Create a QR code with specified content, format, and size
var qrCode = QRCodeWriter.CreateQrCode(url, 100);
// Specify the path of the PDF file to be modified
string pdfFilePath = "input.pdf";
// Specify the pages to modify. For example, pages 1 and 2
var pagesToModify = new List<int> { 1, 2 };
// Specify the X and Y coordinates for where the barcode will be placed
int xCoordinate = 300;
int yCoordinate = 450;
// Optionally, specify a password for the PDF if it's protected
string pdfPassword = "password"; // Leave empty if no password
// Stamp the barcode onto specified PDF pages
qrCode.StampToExistingPdfPages(pdfFilePath, xCoordinate, yCoordinate, pagesToModify, pdfPassword);
// Successfully applied the QR code onto the specified pages of the PDF
Console.WriteLine("Barcode stamped on PDF successfully.");
}
}
// Import the necessary namespace
using IronBarCode;
class BarcodeExample
{
static void Main()
{
// Define the URL to be encoded in the QR code
string url = "https://www.example.com";
// Create a QR code with specified content, format, and size
var qrCode = QRCodeWriter.CreateQrCode(url, 100);
// Specify the path of the PDF file to be modified
string pdfFilePath = "input.pdf";
// Specify the pages to modify. For example, pages 1 and 2
var pagesToModify = new List<int> { 1, 2 };
// Specify the X and Y coordinates for where the barcode will be placed
int xCoordinate = 300;
int yCoordinate = 450;
// Optionally, specify a password for the PDF if it's protected
string pdfPassword = "password"; // Leave empty if no password
// Stamp the barcode onto specified PDF pages
qrCode.StampToExistingPdfPages(pdfFilePath, xCoordinate, yCoordinate, pagesToModify, pdfPassword);
// Successfully applied the QR code onto the specified pages of the PDF
Console.WriteLine("Barcode stamped on PDF successfully.");
}
}
' Import the necessary namespace
Imports IronBarCode
Friend Class BarcodeExample
Shared Sub Main()
' Define the URL to be encoded in the QR code
Dim url As String = "https://www.example.com"
' Create a QR code with specified content, format, and size
Dim qrCode = QRCodeWriter.CreateQrCode(url, 100)
' Specify the path of the PDF file to be modified
Dim pdfFilePath As String = "input.pdf"
' Specify the pages to modify. For example, pages 1 and 2
Dim pagesToModify = New List(Of Integer) From {1, 2}
' Specify the X and Y coordinates for where the barcode will be placed
Dim xCoordinate As Integer = 300
Dim yCoordinate As Integer = 450
' Optionally, specify a password for the PDF if it's protected
Dim pdfPassword As String = "password" ' Leave empty if no password
' Stamp the barcode onto specified PDF pages
qrCode.StampToExistingPdfPages(pdfFilePath, xCoordinate, yCoordinate, pagesToModify, pdfPassword)
' Successfully applied the QR code onto the specified pages of the PDF
Console.WriteLine("Barcode stamped on PDF successfully.")
End Sub
End Class
Explanation of the Code:
IronBarCode
namespace at the beginning of your program.QRCodeWriter.CreateQrCode
method by providing the URL and desired dimensions.StampToExistingPdfPages
method to apply the QR code to the specified PDF pages.Further Reading: How to Stamp Barcodes on PDFs