0

I am trying to convert my ZXingBarcodeImageView to a PDFImage to print it using SyncFusion? Is there a way I can access the image of a ZXingBarcodeImageView to draw in a PDF. I am using Syncfusion PDF to draw out my barcode.

Thank you in advance!

a

Mochi
  • 1,059
  • 11
  • 26

2 Answers2

1

We can't convert ZXingBarcodeImageView to PdfImagedirectly.

Check the documentation of PdfImage .

FromFile -- Creates PdfImage from the specified file

FromImage -- Creates a PdfImage from the existing System.Drawing.Image.

FromStream -- Creates PdfImage from the specified data stream

You could try to save ZXingBarcodeImageView into local path , convert it to Image , get its stream and so on ..

ColeX
  • 14,062
  • 5
  • 43
  • 240
  • Is there a way I could directly convert ZXingBarcodeImageView to a regular System.Drawing.Image? I don't need to save it locally, really I'm just trying to print the barcode in my PDF. – Mochi Jun 05 '19 at 21:16
1

I followed this link to create a BarcodeService interface and implement it in both platforms. I then convert that Stream to PDFBitmap to draw in my PDF (code below).

using (PdfDocument document = new PdfDocument())
        {
            document.PageSettings.Size = new SizeF(612, 350);
            document.PageSettings.Orientation = PdfPageOrientation.Landscape;
            document.PageSettings.SetMargins(0);
            // Add a page to the document
            PdfPage page = document.Pages.Add();

            //Create PDF graphics for the page
            PdfGraphics graphics = page.Graphics;
            var qrImage = DependencyService.Get<IBarcodeService>().ConvertImageStream(Vin);
            PdfBitmap image = new PdfBitmap(qrImage);

            graphics.DrawImage(image, 300, -50, 350, 350);
        }

and Viola!

enter image description here

Mochi
  • 1,059
  • 11
  • 26