We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to insert the png image in PdfLightTable cell in xamarin IOS Platform?

How to insert the PNG images in PDF in Xamarin IOS Platform?

 

Currently Essential PDF for Xamarin support only jpeg images. We can also insert PNG images in PDF by converting the PNG to JPEG by using the UIImage class available in Xamarin IOS. Please note that the transparent graphics won’t be preserved in this workaround.

The below code snippet used to convert the PNG image into jpeg images.

[C#]

public Stream ToStream(string path)

{

Stream stream = new MemoryStream();

stream = UIImage.FromBundle(path).AsJPEG().AsStream();

//stream.Position = 0;

return stream;

}

 

Then we can use the PdfImage class to load the jpeg image and draw it to the pdf, to add an image into the PdfLightTable cell we need to initialize the begin cell event.

Please refer the below code snippet to draw the image into PdfLightTable cell.

[C#]

 

pdfLightTable.BeginCellLayout += new BeginCellLayoutEventHandler(pdfLightTable_BeginCellLayout);

 

 

void pdfLightTable_BeginCellLayout(object sender, BeginCellLayoutEventArgs args)

{

if (args.RowIndex > -1 && args.CellIndex > -1)

{

 

if (args.CellIndex % 2 == 0 && !string.IsNullOrEmpty(args.Value))

{

//Drawing the image

args.Skip = true;

PdfImage image = PdfImage.FromStream (ToStream("pdf.png"));

Syncfusion.Drawing.RectangleF rect = args.Bounds;

args.Graphics.DrawImage (image, new Syncfusion.Drawing.RectangleF (rect.X + 2, rect.Y + 2, rect.Width - 2, rect.Height - 2));

}

}

}

 

 

Sample:

http://www.syncfusion.com/downloads/support/directtrac/general/PdfLightTableTesting-701342478.zip

Article ID: Published Date: Last Revised Date: Platform: Control:
2691 11/18/2014 11/18/2014 Windows Forms PDF
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.