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!
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!
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 ..
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!