Articles in this section
Category / Section

How to create stamp annotation with barcode appearance in a PDF document using C# and VB.NET

5 mins read

The Syncfusion Essential® PDF is a feature-rich and high-performance .NET PDF library that is used to create, read, and edit PDF documents programmatically without Adobe dependencies. Using this library, you can create a stamp annotation with barcode appearance in a PDF document using C# and VB.NET.

Steps to create a stamp annotation with barcode appearance in a PDF document using C# programmatically

1. Create a new C# console application project.

Create a console application

2. Install the Syncfusion.PDF.WinForms NuGet packages as a reference to your .NET Framework application from NuGet.org.

Install nuget packages

3. Include the following namespaces in the Program.cs file.

C#

using Syncfusion.Pdf;
using Syncfusion.Pdf.Barcode;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Interactive;

 

VB.NET

Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Barcode
Imports Syncfusion.Pdf.Interactive
Imports Syncfusion.Pdf.Graphics

 

4. The following code example shows how to create stamp annotation with barcode appearance in a PDF document using C#.

C#

//Creating a new PDF Document.
PdfDocument document = new PdfDocument();
//Add the margins.
document.PageSettings.Margins.All = 0;
//Adding a new page to a PDF document.
PdfPage page = document.Pages.Add();
//Initialize a new PdfCode39Barcode instance.
PdfCode39Barcode barcode = new PdfCode39Barcode();
//Set the height and text for barcode.
barcode.BarHeight = 45;
barcode.Text = "CODE39$";
//Convert the barcode to image.
Image barcodeImage = barcode.ToImage(new SizeF(180, 100));
//Creates a new pdf rubber stamp annotation.
RectangleF rectangle = new RectangleF(40, 60, 180, 100);
PdfRubberStampAnnotation rubberStampAnnotation = new PdfRubberStampAnnotation(rectangle, " Barcode Rubber Stamp Annotation");
rubberStampAnnotation.Appearance.Normal.Graphics.DrawImage(new PdfBitmap(barcodeImage), 0, 0, rectangle.Width, rectangle.Height);
rubberStampAnnotation.Text = "Barcode Properties Rubber Stamp Annotation";
//Adds annotation to the page.
page.Annotations.Add(rubberStampAnnotation);
//Save and closes the document.
document.Save("../../Barcode.pdf");
document.Close(true);

 

VB.NET

'Creating a new PDF Document.
Dim document As PdfDocument = New PdfDocument()
'Add the margins.
document.PageSettings.Margins.All = 0
'Adding a new page to a PDF document.
Dim page As PdfPage = document.Pages.Add()
'Initialize a new PdfCode39Barcode instance.
Dim barcode As PdfCode39Barcode = New PdfCode39Barcode()
'Set the height and text for barcode.
barcode.BarHeight = 45
barcode.Text = "CODE39$"
'Convert the barcode to image.
Dim barcodeImage As Image = barcode.ToImage(New SizeF(180, 100))
'Creates a new pdf rubber stamp annotation.
Dim rectangle As RectangleF = New RectangleF(40, 60, 180, 100)
Dim rubberStampAnnotation As PdfRubberStampAnnotation = New PdfRubberStampAnnotation(rectangle, " Barcode Rubber Stamp Annotation")
rubberStampAnnotation.Appearance.Normal.Graphics.DrawImage(new PdfBitmap(barcodeImage), 0, 0, rectangle.Width, rectangle.Height);
rubberStampAnnotation.Text = "Barcode Properties Rubber Stamp Annotation";
'Adds annotation to the page.
page.Annotations.Add(rubberStampAnnotation)
'Save and closes the document.
document.Save("../../Barcode.pdf")
document.Close(true)

 

By executing the program, you will get the PDF document as follows.

Output screenshot

A complete working sample can be downloaded from AnnotationSample.zip.

Take a moment to peruse the documentation. You can also find the options like adding one-dimensional and two-dimensional barcodes to the PDF document, set location and size to the barcode, and customizing the barcode appearance.

Refer to this link to explore a rich set of Syncfusion Essential® PDF features.

An online sample link to the creation of a barcode in a PDF document.

 

Note:

Starting with v16.2.0.x, if you reference Syncfusion® assemblies from the trial setup or NuGet feed, include a license key in your projects. Refer to this link to learn about generating and registering the Syncfusion® license key in your application to use the components without trail message.

 

Also see:

https://help.syncfusion.com/file-formats/pdf/working-with-barcode

https://www.syncfusion.com/kb/9543/how-to-add-or-draw-barcode-in-a-pdf-using-c-and-vb-net

https://www.syncfusion.com/kb/9803/how-to-convert-barcode-to-image-using-c-and-vb-net

https://www.syncfusion.com/kb/11502/how-to-convert-the-barcode-to-image-in-the-asp-net-core-platform

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied