Articles in this section
Category / Section

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

4 mins read

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:https://www.syncfusion.com/downloads/support/directtrac/general/PdfLightTableTesting-701342478.zi


Conclusion

I hope you enjoyed learning about how to insert the png image in PdfLightTable cell in xamarin IOS Platform.

You can refer to our Xamarin.iOS PDF feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Xamarin.iOS PDF Viewer example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied