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. Image for the cookie policy date

Adding image to pdf works in iOS but not in android

I'm creating a PDF on the fly using Syncfusion and Xamarin Forms. Everything is going well in iOS, but in Android, it failed to locate the image (logo).

followed syncfusion PDF getting started but even that it's not working. The image is located in android's resource/drawable. I did also added it in assets.

This is the working code in xamarin forms iOS

//Load the image 
Stream imageStream = System.IO.File.OpenRead("logo.jpg");
//Load the image from the stream 
PdfBitmap image = new PdfBitmap(imageStream); 

Unfortunately, even this doesn't work on Android

//Load the image 
Stream imageStream = DependencyService.Get<ISave>().LoadFromFile(@"logo.jpg");
//Load the image from the stream 
PdfBitmap image = new PdfBitmap(imageStream); 

Your help is appreciated as I'm stuck on this for 3 days now.

1 Reply

SL Sowmiya Loganathan Syncfusion Team May 14, 2019 12:35 PM UTC

Hi John, 

Greetings from Syncfusion. 

We have analysed your requirement of “Adding images to PDF from drawable folder” in Xamarin Android. And found that we could not load the images directly from the drawable folder, instead of we can get it from the resources. Please find the below code snippet for more details, 


var context = Android.App.Application.Context; 
using (var drawable = Xamarin.Forms.Platform.Android.ResourceManager.GetDrawable(context, fileName)) 
using (var bitmap = ((BitmapDrawable)drawable).Bitmap) 
var stream = new MemoryStream(); 
bitmap.Compress(Bitmap.CompressFormat.Png, 100, stream); 
return stream.ToArray(); 

We have created the sample for the same which can be download from following link, 

Kindly try the above sample in your end and let us know if it solves the issue. 

Sowmiya L 

Live Chat Icon For mobile
Up arrow icon