Bad or Unsup Image Displaying When Drawing Barcode on PDF

Questions, comments and suggestions concerning VintaSoft Barcode .NET SDK.

Moderator: Alex

Post Reply
Posts: 1
Joined: Fri Feb 09, 2018 5:28 pm

Bad or Unsup Image Displaying When Drawing Barcode on PDF

Post by msettlemeyer » Mon Feb 12, 2018 4:54 pm

I'm not sure if this is the correct forum because I believe I'm using Barcode and Imaging as well. I'm able to draw a product price sticker and format it like I expect. However, when I try to get a barcode as a bitmap then render it on a pdf. I get a red box that says Bad or unsup instead of a barcode on the price sticker. I'm able to save the bitmap to a file and it displays as I would have expected. It only causes a problem when I attempt to draw it on PDF page. Here is the code

Code: Select all

public void GeneratePriceSticker(ItemReadModel model, int numberOfStickers)
    _numberToPrint = numberOfStickers;

    using (PdfDocument pdfDocument = new PdfDocument())
        PdfPage pdfPage = new PdfPage(pdfDocument,
                ImageSize.FromInches(1.2, .9, new Resolution(600, 600)));


        var font = pdfDocument.FontManager.GetStandardFont(StandardFontType.Helvetica);

        PdfBrush brush = new PdfBrush(Color.Black);

        using (PdfGraphics graphics = PdfGraphics.FromPage(pdfPage))
            var boundingBox = graphics.GetSourceBoundingBox();
            //calculate interior rectangle with 2.5px margin around edges
            //used for calculating sticker text positions
            var inset = 2.5f;
            var interiorX = boundingBox.X + inset;
            var interiorY = boundingBox.Y + inset;
            var interiorHeight = boundingBox.Height - (inset * 2);
            var interiorWidth = boundingBox.Width - (inset * 2);

            var descWidth = 0f;
            var descHeight = 0f;
            graphics.MeasureString(model.ItemDescription, font, 6, interiorWidth, true, 1, out descWidth, out descHeight);
            var descRect = new RectangleF(interiorX, (interiorHeight - descHeight), descWidth, descHeight);
            graphics.DrawString(model.ItemDescription, font, 6, brush, descRect, PdfContentAlignment.CenterBottom, true);

            var priceWidth = 0f;
            var priceHeight = 0f;
            var priceString = $"${model.SRPCost.ToString()}";
            graphics.MeasureString(priceString, font, 12, out priceWidth, out priceHeight);
            var priceRect = new RectangleF(interiorX, (interiorY + interiorHeight / 2), (interiorWidth * 0.80f), priceHeight);

            graphics.DrawString(priceString, font, 12, brush, priceRect, PdfContentAlignment.Right, true);

            var barcodeWriter = new BarcodeWriter();
            barcodeWriter.Settings.Barcode = BarcodeType.Code128;
            barcodeWriter.Settings.Value = model.ItemGTIN;
            barcodeWriter.Settings.ValueVisible = true;
            barcodeWriter.Settings.PixelFormat = BarcodeImagePixelFormat.Bgr24;
            barcodeWriter.Settings.Code128EncodingMode = Vintasoft.Barcode.BarcodeInfo.Code128EncodingMode.ModeB;
            var barcode = barcodeWriter.GetBarcodeAsBitmap((interiorWidth * .50), (interiorHeight * .50), Vintasoft.Barcode.UnitOfMeasure.Pixels);
            var barcodeRect = new RectangleF((interiorWidth * 0.25f), 0, (interiorWidth * 0.5f), barcode.Height);
            graphics.DrawImage(new VintasoftImage(barcode, true),barcodeRect);

            StringFormat stringFormat = StringFormat.GenericDefault;

            using (var stream = new MemoryStream())
        var image = pdfDocument.Pages[0].Render();
        _collection = new ImageCollection();

        PdfPrintDocument pdfPrintDocument = new PdfPrintDocument();

        pdfPrintDocument.PrintScaleMode = PrintScaleMode.None;

        pdfPrintDocument.BeginPrint += printDocument_BeginPrint;
        pdfPrintDocument.PrintImage +=
            new EventHandler<PrintImageEventArgs>(printDocument_PrintImage);
        pdfPrintDocument.ImagePrinted +=
            new EventHandler<PrintImageEventArgs>(printDocument_EndPrintImage);
        pdfPrintDocument.EndPrint += printDocument_EndPrint;



Site Admin
Posts: 1486
Joined: Thu Jul 10, 2008 2:21 pm

Re: Bad or Unsup Image Displaying When Drawing Barcode on PDF

Post by Alex » Mon Feb 12, 2018 5:24 pm


For understanding your problem, we need reproduce the problem on our side. Could you send us a small working project, which demonstrates your problem? If yes, please send your project to

Best regards, Alexander

Post Reply