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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Centering Barcode onto PDF Document

Thread ID:

Created:

Updated:

Platform:

Replies:

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

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?

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;

           

}

         

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.


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.

Thanks

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 :

 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


CONFIRMATION

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.

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

;