How to add quite zones to barcode in PDF using C# and VB.NET in WinForms?
The Syncfusion Essential® PDF is a .NET PDF Library used to create, read, and edit PDF documents. Using this library, you can add quiet zones to barcode in the PDF document using C# and VB.NET.
Quiet zone: Quiet zone is the blank margin located at either end of a barcode which is used to tell the barcode reader that where a barcode symbology starts and stops.
Steps to add quite zones to barcode in the PDF document programmatically:
- Create a new C# console application project.
- Install the Syncfusion.Pdf.WinForms NuGet package as a reference to your .NET Framework application from NuGet.org.
- Include the following namespaces in Program.cs file.
C#
using Syncfusion.Pdf; using Syncfusion.Pdf.Barcode; using Syncfusion.Pdf.Graphics; using System.Drawing;
VB.NET
Imports Syncfusion.Pdf Imports Syncfusion.Pdf.Barcode Imports Syncfusion.Pdf.Graphics Imports System.Drawing
- Use the following code sample to add quiet zones to the barcode in a PDF document.
C#
//Create a new PDF document. PdfDocument document = new PdfDocument(); //Creates a new page. PdfPage page = document.Pages.Add(); //Creates a new PdfCode93Barcode. PdfCode93Barcode code93 = new PdfCode93Barcode("CODE93"); //Creates a new PdfBarcodeQuietZones. PdfBarcodeQuietZones quietZones = new PdfBarcodeQuietZones(); quietZones.All = 50f; //Sets the barcode quiet zone. code93.QuietZone = quietZones; //Draws a barcode on the new page. code93.Draw(page, new PointF(10, 10)); //Draw a rectangle based on the barcode size. page.Graphics.DrawRectangle(PdfPens.Red, new RectangleF(10, 10, code93.Size.Width, code93.Size.Height)); //Save the document to disk. document.Save("PdfBarcode.pdf"); //This will open the PDF file and the result will be seen in the default PDF Viewer. Process.Start("PdfBarcode.pdf");
VB.NET
'Create a new PDF document. Dim document As PdfDocument = New PdfDocument() 'Creates a new page. Dim page As PdfPage = document.Pages.Add() 'Creates a new PdfCode93Barcode. Dim code93 As PdfCode93Barcode = New PdfCode93Barcode("CODE93") 'Creates a new PdfBarcodeQuietZones. Dim quietZones As PdfBarcodeQuietZones = New PdfBarcodeQuietZones() quietZones.All = 50.0F 'Sets the barcode quiet zone to all sides. code93.QuietZone = quietZones 'Draws a barcode on the new page. code93.Draw(page, New PointF(10, 10)) 'Draw a rectangle based on the barcode size. page.Graphics.DrawRectangle(PdfPens.Red, New RectangleF(10, 10, code93.Size.Width, code93.Size.Height)) 'Save the document to disk. document.Save("PdfBarcode.pdf") 'This will open the PDF file and the result will be seen in the default PDF Viewer. Process.Start("PdfBarcode.pdf")
A complete working sample can be download from BarcodeSample.zip.
By executing the program, you will get the output document as follows,
If we set the quiet zone to 0, then you will get the output document as follows,
Take a moment to peruse the documentation. You can also find other options like adding a one-dimensional or two-dimensional barcode in a PDF document, export a barcode as an image, adding a barcode to PDF without displaying the barcode text.
Refer to this link to explore a rich set of Syncfusion Essential® PDF features.
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from trial setup or the NuGet feed, include a license key in your product. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without trail message.
Also see:
Draw barcode in PDF using C# and VB.NET
Draw barcode in PDF table cell
Set width to the barcode in PDF document
Align barcode text in PDF document
Conclusion
I hope you enjoyed learning about how to add quite zones to barcode in PDF using C# and VB.NET in WinForms.
You can refer to our WinForms PDF feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms PDF example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!