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. Image for the cookie policy date

Centering Barcode onto PDF Document

Hi,

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?

3 Replies

AS Abirami Selvan Syncfusion Team 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;

           

}

         

else

           

{

            

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

           

}

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

http://www.syncfusion.com/downloads/support/directtrac/general/BarcodeSample-1378717508.zip

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 .

Thanks,

Abirami.



GD Gilson Development 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.

Thanks


AS Abirami Selvan Syncfusion Team 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 :

 http://www.syncfusion.com/downloads/support/directtrac/general/BarcodeSample1420795576.zip

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

 

Thanks,

Abirami


Loader.
Live Chat Icon For mobile
Up arrow icon