Show text above the barcode on Code128

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF CoreSuite for .NET (v9)  /  Re: Show text above the barcode on Code128

DynamicPDF CoreSuite for .NET (v9) Forum

I am using Code128 class in order to get a barcode.
Is possible to show the text above the barcode instead below it?
Thanks.
Posted by a ceTe Software moderator
Hello,

You can achieve your requirements by adding the barcode text using a Label page element above the Code128 barcode. You  will need to set the ShowText property of the Code128 object to false to hide the below text. Below is the code sample. Also please note that there is no direct property or method to add the barcode text above the Code128 barcode.

            Document document = new Document();
            Page page = new Page();
            document.Pages.Add(page);

            string barcodeText=@"123456789";
            Code128 barCode128Obj = new Code128(barcodeText, 100, 100, 50);
            barCode128Obj.ShowText = false;
          
            float yposition = barCode128Obj.Y ;
            Label barcodeLabel = new Label(barcodeText, barCode128Obj.X, yposition, barCode128Obj.GetSymbolWidth(), 30);
            barcodeLabel.Align = TextAlign.Center;
            Font font = barcodeLabel.Font;
            float  fontSize = barcodeLabel.FontSize;
            float textHeight = font.GetAscender(fontSize) + font.GetDescender(fontSize) ;
            barcodeLabel.Height = textHeight;
            page.Elements.Add(barcodeLabel);

            barCode128Obj.Y = barCode128Obj.Y + barcodeLabel.Height+5;

            page.Elements.Add(barCode128Obj);
            document.Draw(@"C:\Temp\MyDocument.pdf");

Thanks,
ceTe Software Support Team.

All times are US Eastern Standard time. The time now is 3:46 AM.