Skip to content

Commit 127fd9c

Browse files
Merge pull request #1479 from syncfusion-content/260113-ug
260113-ug: Enhanced UG Documentation with Quiet Zone Barcode Implementation
2 parents 3ac53ed + ece5ce4 commit 127fd9c

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

Document-Processing/PDF/PDF-Library/NET/Working-with-Barcode.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,127 @@ doc.Close(True)
558558

559559
You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Barcode/Set-location-and-size-to-the-barcode-in-a-PDF-document/).
560560

561+
## Adding quiet zones to a barcode
562+
563+
Quiet zones are blank spaces surrounding a barcode that ensure accurate scanning by preventing interference from surrounding content. They serve as critical visual boundaries that help scanners identify the start and end of the barcode symbology. Without sufficient quiet zones, barcode readers may fail to decode the symbol correctly due to visual noise or misalignment.
564+
565+
To add quiet zones to a barcode in a PDF document, you can use the [PdfBarcodeQuietZones](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Barcode.PdfBarcodeQuietZones.html) class. The following code sample demonstrates how to implement quiet zones for a barcode.
566+
567+
{% tabs %}
568+
569+
{% highlight c# tabtitle="C# [Cross-platform]" %}
570+
571+
//Create a new PDF document.
572+
PdfDocument document = new PdfDocument();
573+
574+
//Create a new page.
575+
PdfPage page = document.Pages.Add();
576+
577+
// Create barcode with quiet zones
578+
PdfCode128Barcode barcode = new PdfCode128Barcode
579+
{
580+
Text = "SYNCFUSION",
581+
BarHeight = 40,
582+
QuietZone = new PdfBarcodeQuietZones
583+
{
584+
Left = 15, // 15 points = ~5.3mm
585+
Right = 15,
586+
Top = 8, // 8 points = ~2.8mm
587+
Bottom = 8
588+
}
589+
};
590+
591+
//Draw a barcode on the new page.
592+
barcode.Draw(page, new PointF(10, 10));
593+
594+
//Draw a rectangle based on the barcode size.
595+
page.Graphics.DrawRectangle(PdfPens.Red, new RectangleF(10, 10, barcode.Size.Width, barcode.Size.Height));
596+
597+
//Create file stream.
598+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
599+
{
600+
//Save the PDF document to file stream.
601+
document.Save(outputFileStream);
602+
}
603+
604+
//Close the document.
605+
document.Close(true);
606+
607+
{% endhighlight %}
608+
609+
{% highlight c# tabtitle="C# [Windows-specific]" %}
610+
611+
//Create a new PDF document.
612+
PdfDocument document = new PdfDocument();
613+
614+
//Create a new page.
615+
PdfPage page = document.Pages.Add();
616+
617+
// Create barcode with quiet zones
618+
PdfCode128Barcode barcode = new PdfCode128Barcode
619+
{
620+
Text = "SYNCFUSION",
621+
BarHeight = 40,
622+
QuietZone = new PdfBarcodeQuietZones
623+
{
624+
Left = 15, // 15 points = ~5.3mm
625+
Right = 15,
626+
Top = 8, // 8 points = ~2.8mm
627+
Bottom = 8
628+
}
629+
};
630+
631+
//Draw a barcode on the new page.
632+
barcode.Draw(page, new PointF(10, 10));
633+
634+
//Draw a rectangle based on the barcode size.
635+
page.Graphics.DrawRectangle(PdfPens.Red, new RectangleF(10, 10, barcode.Size.Width, barcode.Size.Height));
636+
637+
//Save the document to disk.
638+
document.Save("PdfBarcode1.pdf");
639+
640+
//Close the document.
641+
document.Close(true);
642+
643+
{% endhighlight %}
644+
645+
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
646+
647+
' Create a new PDF document.
648+
Dim document As New PdfDocument()
649+
650+
' Add a new page to the PDF document.
651+
Dim page As PdfPage = document.Pages.Add()
652+
653+
' Create a new Code128 barcode and set its properties.
654+
Dim barcode As New PdfCode128Barcode() With {
655+
.Text = "SYNCFUSION", ' Set the barcode text.
656+
.BarHeight = 40, ' Set the height of the bars.
657+
.QuietZone = New PdfBarcodeQuietZones() With {
658+
.Left = 15, ' Left quiet zone (15 points ≈ 5.3mm).
659+
.Right = 15, ' Right quiet zone.
660+
.Top = 8, ' Top quiet zone (8 points ≈ 28mm).
661+
.Bottom = 8 ' Bottom quiet zone.
662+
}
663+
}
664+
' Draw the barcode on the PDF page at position (10, 10).
665+
barcode.Draw(page, New PointF(10, 10))
666+
667+
' Draw a red rectangle around the barcode to visualize its size.
668+
page.Graphics.DrawRectangle(PdfPens.Red, New RectangleF(10, 10, barcode.Size.Width, barcode.Size.Height))
669+
670+
' Save the PDF document to disk.
671+
document.Save("PdfBarcode1.pdf")
672+
673+
' Close the document and release resources.
674+
document.Close(True)
675+
676+
{% endhighlight %}
677+
678+
{% endtabs %}
679+
680+
You can download a complete working sample from GitHub.
681+
561682
## Adding a barcode to the PDF document without displaying the barcode text
562683

563684
The following code example shows how to add a barcode to the PDF document without displaying the barcode text by specifying the [TextDisplayLocation](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Barcode.PdfUnidimensionalBarcode.html#Syncfusion_Pdf_Barcode_PdfUnidimensionalBarcode_TextDisplayLocation) as **None** through the [TextLocation](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Barcode.TextLocation.html) Enum.

0 commit comments

Comments
 (0)