You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Document-Processing/PDF/PDF-Library/NET/Working-with-Barcode.md
+121Lines changed: 121 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -558,6 +558,127 @@ doc.Close(True)
558
558
559
559
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/).
560
560
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))
' 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
+
561
682
## Adding a barcode to the PDF document without displaying the barcode text
562
683
563
684
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