- Home
- Forum
- Xamarin.Forms
- Load image in PDF
Load image in PDF
I would like to put an image into my pdf but I can't access my resource folder (iOS) in the class. Where can I save an image in my project folder and how can I access it? I need this for android as well.
SIGN IN To post a reply.
6 Replies
SK
Sasi Kumar Sekar
Syncfusion Team
June 1, 2018 06:56 AM UTC
Hi Caleb,
Thank you for contacting Syncfusion support.
We can add image in existing PDF document by drawing image in existing document page. Please find the UG document link below for your reference.
UG link:
The image should be saved in Xamarin.Form.Portable project and it can be accessed by using below code snippet.
|
//Read the image stream by specifying projectname.imagename
Stream imageStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("GettingStarted.Xamarin_JPEG.jpg");
|
Note: Image property should be set as Embedded Resource and copy always
Please find the sample that we are adding image in existing PDF document using Xamarin.Forms.
Regards,
Sasi Kumar S.
CK
Caleb Kliewer
June 1, 2018 02:16 PM UTC
Thanks for the reply! I tried this and it returns the Stream as null. Under further investigation I noticed it says: Method `GetTypeInfo' not found in type `System.RuntimeType'.
I have 'using System.Reflection;' so I can't figure out where this problem exists. Any ideas?
SK
Sasi Kumar Sekar
Syncfusion Team
June 4, 2018 10:10 AM UTC
Hi Caleb,
Thank you for your update.
In compilation “Type does not contain definition for ‘GetTypeInfo’” error can be resolved by referring System.Reflection namespace. The image stream is null can be resolved by setting the image property as Embedded Resource and Copy always, otherwise the null stream only returned from GetManifestResourceStream. Kindly check the sample updated in previous update and confirm your side.
Please try our suggestion and let us know whether the issue is resolved from your side.
Regards,
Sasi Kumar S.
WI
Winson
January 31, 2020 03:10 AM UTC
what if I want to dynamic load the image from file and show in PDF ? how can I do that? thanks!
SL
Sowmiya Loganathan
Syncfusion Team
January 31, 2020 01:18 PM UTC
Hi Winson,
Currently we are working to achieve your requirement. We will update the further details on 3rd February, 2020.
Regards,
Sowmiya Loganathan
PV
Prakash Viswanathan
Syncfusion Team
February 3, 2020 12:01 PM UTC
Hi Winson,
Thank you for your patience.
In Xamarin.Form we can get stream from file path using DependencyService. Please follow below steps to get stream from the file path. For dependency service we should implement dependency methods in Android, iOS and UWP platforms and implementation in below for your reference.
|
Platform |
Code example |
|
Android |
public Stream LoadFromFile(string fileName)
{
string root = null;
if (Android.OS.Environment.IsExternalStorageEmulated)
{
root = Android.OS.Environment.ExternalStorageDirectory.ToString();
}
else
root = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
return System.IO.File.OpenRead(root+"/Syncfusion/"+fileName.ToString());
}
Note: The input image file should be in Syncfusion folder.
|
|
iOS |
public Stream LoadFromFile(string filename)
{
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string filePath = Path.Combine(path, filename);
return System.IO.File.OpenRead(filePath)
}
Note: The input image file should be in MyDocument folder.
|
|
UWP |
public stream LoadFromFile(string fileName)
{
LoadFile1(filename).Result;
}
public async Task<Stream> LoadFile1(string filename)
{
StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
StorageFile sampleFile = await storageFolder.GetFileAsync(filename);
Stream outStream = await sampleFile.OpenStreamForReadAsync();
return outStream;
}
Note: The input image file should be in Current.LocalFolder location.
|
Created a simple sample based on above instruction. Please find the sample below for your reference.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Forums_137879-193391698.zip
Please try the above sample and let us know if it is suites your requirement.
Regards,
Prakash V
SIGN IN To post a reply.
- 6 Replies
- 5 Participants
-
CK Caleb Kliewer
- May 31, 2018 04:14 PM UTC
- Feb 3, 2020 12:01 PM UTC