We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Centering Barcode onto PDF Document

Thread ID:





117977 Jan 15,2015 04:57 PM UTC Jan 20,2015 06:05 PM UTC ASP.NET MVC (Classic) 3
Tags: PDF
Gilson Development
Asked On January 15, 2015 04:57 PM UTC


I am creating a PdfCode128ABarcode (guess it doesn't matter which one we use, applies to all). I am currently setting "PdfCode128ABarcode.Draw(PdfPage, new PointF(x, y))" to place my barcode. I want to know if there is a way to center a barcode within a certain sized space? I have a 1"x4" area. The issue I can't figure is how to center the barcode at all times. This is an issue because our barcode data can vary, anywhere from 1-6 characters all the way up to 16 characters. The shorter the data, the more off center the barcode is and looks ugly. Longer data barcodes look just great, its just the shorter ones are not so pretty. The "TextAlignment" or "TextDisplayLocation" will not help me.

The "PdfGraphics.DrawString", for text, has a "PdfStringFormat" that allows me to set the "Alignment = PdfTextAlignment.Center", its what I essentially want for the whole barcode itself. Help?

Abirami Selvan [Syncfusion]
Replied On January 19, 2015 12:51 PM UTC

Hi Gilson ,

Thank you for using Syncfusion Products .

We are created the workaround to draw the barcode at center for variable barcode text length in PDF .Please refer the following code snippet to calculate the width

  //get the barocde image

System.Drawing.Image img= barcode128A.ToImage();


 float width = 0;


//calculate the width respective to the barcode image width


 if(img.Width >page.GetClientSize().Width/2)



    width =page.GetClientSize().Width/4;








  width = (page.GetClientSize().Width/2)-img.Width/2;



We have attached the sample for your reference in below link :


Please try this and  let us know if you have further assistance .

We have logged  the feature request for “ Align the barcode at center of the  Pdf “ . We will let you know once we  have implemented .



Gilson Development
Replied On January 19, 2015 03:47 PM UTC

Hi Abirami Selvan,

I tested out your solution, and it does center on the PDF page, which is great!
In my original post, I mentioned I needed to center the barcode in an "area" of 1" x 4" (example I am doing is a 20-up Avery 1" x 4" labels - http://www.worldlabel.com/assets/thumbnails/wl-75.jpg).
I will see if I can figure something out with what you gave me, to start with. If you have a solution, please let me know.


Abirami Selvan [Syncfusion]
Replied On January 20, 2015 06:05 PM UTC

Hi Gilson,

 We have created the work around sample for your requirement  centering the barcode  in an area.

We have attached the sample  for your reference in below link :


Please try this and let us know if you have any further assistance .





This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon