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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Adding image to pdf works in iOS but not in android

Thread ID:





144580 May 13,2019 11:28 AM UTC May 14,2019 12:35 PM UTC Xamarin.Forms 1
Tags: PDF
Asked On May 13, 2019 11:28 AM UTC

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.

Sowmiya Loganathan [Syncfusion]
Replied On 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 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon

Live Chat Icon For mobile
Live Chat Icon