locked
Form a barcode in pdf? use C# RRS feed

  • Question

  • I already have found the way to form a barcode , then how to put it on PDF? As a image or stream, Please offer a way, thanks. 
    Friday, April 3, 2015 6:00 AM

Answers

  • A third party PDF component can do this for U ,after add reference ,here is the code:

    //draw Codabar
     PdfTextWidget text = new PdfTextWidget();
     text.Font = font1;
     text.Text = "Codabar:";
     PdfLayoutResult result = text.Draw(page, 0, y);
     page = result.Page;
     y = result.Bounds.Bottom + 2;
    
     PdfCodabarBarcode barcode1 = new PdfCodabarBarcode("00:12-3456/7890");
     barcode1.BarcodeToTextGapHeight = 1f;
     barcode1.EnableCheckDigit = true;
     barcode1.ShowCheckDigit = true;
     barcode1.TextDisplayLocation = TextLocation.Bottom;
     barcode1.TextColor = Color.Green;
     barcode1.Draw(page, new PointF(0, y));
     y = barcode1.Bounds.Bottom + 5;
    
    
     //draw Barcode
     text.Text = "Code123:";
     result = text.Draw(page, 0, y);
     page = result.Page;
     y = result.Bounds.Bottom + 2;
    
     PdfCode11Barcode barcode2 = new PdfCode11Barcode("123-4567890");
     barcode2.BarcodeToTextGapHeight = 1f;
     barcode2.TextDisplayLocation = TextLocation.Bottom;
     barcode2.TextColor = Color.OrangeRed;
     barcode2.Draw(page, new PointF(0, y));
     y = barcode2.Bounds.Bottom + 5;
    You can set barcode format and some properties such as text display location, color etc.

    • Marked as answer by Caillen Wednesday, April 15, 2015 9:32 AM
    Friday, April 3, 2015 6:02 AM