- Home
- Forum
- Xamarin.Forms
- Unable to show image on image field in fillable pdf
Unable to show image on image field in fillable pdf
Hi,
Attachment: pdf_7b47bb3c.zip
I have a fillable pdf with an image field where I would like to put in an image I have in the Assets folder in my project. I used sample code from thread ID 146749: https://www.syncfusion.com/forums/146749/field-image. My code is as follows:
PdfLoadedButtonField loadedButtonField = loadedForm.Fields[7] as PdfLoadedButtonField;
PdfButtonField field = new PdfButtonField(loadedButtonField.Page, loadedButtonField.Name);
field.Bounds = loadedButtonField.Bounds;
field.BorderColor = loadedButtonField.BorderColor;
field.BorderStyle = loadedButtonField.BorderStyle;
field.BorderWidth = loadedButtonField.BorderWidth;
Stream streamxx = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("Saki.SamsTrack.Assets.dummy.jpg");
PdfBitmap image = new PdfBitmap(streamxx);
//Add image to the appearance stream of the created field
field.Appearance.Normal.Graphics.DrawImage(image, new RectangleF(0,0, field.Appearance.Normal.Width, field.Appearance.Normal.Height) );
// remove the existing field
loadedForm.Fields.Remove(loadedButtonField);
//Add the new field
loadedForm.Fields.Add(field);
After the execution of the above code, I save the document in a memory stream and save the pdf to the iOS device and load it into an SfPdfViewer. The image does not show up in the image field, only the label shows up. I have named my image field "Signature" (screenshot attached).
Do I need to change any of the properties of the image field I place in the fillable pdf under the Options or Actions tab (screenshots attached)?
Pls share a working project with above example working and a dummy fillable pdf with image field just to see what properties I should have for my image field and the code should look like
Thanks,
Madhu
Attachment: pdf_7b47bb3c.zip
SIGN IN To post a reply.
13 Replies
SL
Sowmiya Loganathan
Syncfusion Team
July 31, 2020 01:07 PM UTC
Hi Madhu,
Thank you for contacting Syncfusion support.
We have analyzed the reported issue. We were able to see the issue (image does not show up in the button field) while trying the provided code snippet. However, we can overcome this issue by setting SetDefaultAppearance as false. Please refer the below code snippet for more details,
|
//Load PDF document
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);
//Load form
PdfLoadedForm loadedForm = loadedDocument.Form;
//Set default appearance as false
loadedForm.SetDefaultAppearance(false);
for (int i = 0; i < loadedForm.Fields.Count; i++)
{
if (loadedForm.Fields[i] is PdfLoadedButtonField)
{
//Load existing button field
PdfLoadedButtonField loadedField = loadedForm.Fields[i] as PdfLoadedButtonField;
//Create new field and clone its parameters
PdfButtonField field = new PdfButtonField(loadedField.Page, loadedField.Name);
field.Bounds = loadedField.Bounds;
field.BorderColor = loadedField.BorderColor;
field.BorderStyle = loadedField.BorderStyle;
field.BorderWidth = loadedField.BorderWidth;
//Load image from a stream
Stream imageStream =typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("GettingStarted.Assets.logo.png");
PdfImage image = new PdfBitmap(imageStream);
//Add image to the appearance stream of the created field
field.Appearance.Normal.Graphics.DrawImage(image, new RectangleF(0, 0, field.Appearance.Normal.Width, field.Appearance.Normal.Height));
//Remove the existing field
loadedForm.Fields.Remove(loadedField);
//Add the new field
loadedForm.Fields.Add(field);
}
}
|
Note: There is no need to change the properties of the button field.
Please find the sample for the same from below,
Please try the above solution at your end and let us know the result.
Regards,
Sowmiya Loganathan
MG
Madhu Ganesh
August 3, 2020 08:12 PM UTC
The following line of code doesn't make a difference in my case:
loadedForm.SetDefaultAppearance(false);
In the sample project provided, it does work when I am taking one pdf and adding an image to it and then viewing the pdf in the native iOS viewer. But in my app I combine or merge several pdf files and it does not work. So in the sample project I did something similar to a merge and it did not work there either. Here is the code:
void OnButtonClicked(object sender, EventArgs args)
{
//Load the image as stream
Stream docStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("GettingStarted.Assets.Button_Field.pdf");
//Load PDF document
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);
//Load form
PdfLoadedForm loadedForm = loadedDocument.Form;
//Set default appearance as false
loadedForm.SetDefaultAppearance(false);
for (int i = 0; i < loadedForm.Fields.Count; i++)
{
if (loadedForm.Fields[i] is PdfLoadedButtonField)
{
//Load existing button field
PdfLoadedButtonField loadedField = loadedForm.Fields[i] as PdfLoadedButtonField;
//Create new field and clone its parameters
PdfButtonField field = new PdfButtonField(loadedField.Page, loadedField.Name);
field.Bounds = loadedField.Bounds;
field.BorderColor = loadedField.BorderColor;
field.BorderStyle = loadedField.BorderStyle;
field.BorderWidth = loadedField.BorderWidth;
//Load image from stream
Stream imageStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("GettingStarted.Assets.logo.png");
PdfImage image = new PdfBitmap(imageStream);
//Add image to the appearance stream of the created field
field.Appearance.Normal.Graphics.DrawImage(image, new RectangleF(0, 0, field.Appearance.Normal.Width, field.Appearance.Normal.Height));
//Remove the existing field
loadedForm.Fields.Remove(loadedField);
//Add the new field
loadedForm.Fields.Add(field);
}
}
//Save the document to the stream
MemoryStream stream = new MemoryStream();
loadedDocument.Save(stream);
//Close the document
loadedDocument.Close(true);
stream.Position = 0;
//Save the stream as a file in the device and invoke it for viewing
Xamarin.Forms.DependencyService.Get<ISave>().SaveAndView("Sample.pdf", "application/pdf", stream);
stream.Position = 0;
Stream[] source = { stream};
//Create a new PDF document
PdfDocument final_document = new PdfDocument();
//Merge the documents
PdfDocumentBase.Merge(final_document, source);
//Save the PDF document to stream
MemoryStream final_stream = new MemoryStream();
final_document.Save(final_stream);
//Close the documents
final_document.Close(true);
final_stream.Position = 0;
//Save the stream as a file in the device and invoke it for viewing
Xamarin.Forms.DependencyService.Get<ISave>().SaveAndView("Sample2.pdf", "application/pdf", final_stream);
}
The Sample2 document does not show the png file.
Thanks,
Madhu
PH
Praveenkumar H
Syncfusion Team
August 4, 2020 12:04 PM UTC
Hi Madu,
Thank you for your code snippets,
We can able reproduce the issue along with your code snippets, currently, we are validating the issue and we will update the further details on 6 August 2020.
Regards,
Praveen
SL
Sowmiya Loganathan
Syncfusion Team
August 6, 2020 08:58 AM UTC
Hi Madhu,
We have confirmed that the issue with “Image does not shows in button field when perform merging PDF files” is a defect and logged a defect report for this. We will update the patch for this issue on August 13, 2020.
The status of this issue can be tracked through the following feedback link,
Regards,
Sowmiya Loganathan
SL
Sowmiya Loganathan
Syncfusion Team
August 13, 2020 03:11 PM UTC
Hi Madhu,
The issue with “Image does not shows in button field when perform merging PDF files” has been fixed and the patch for this fix can be downloaded from the following location.
The issue with “Image does not shows in button field when perform merging PDF files” has been fixed and the patch for this fix can be downloaded from the following location.
The status of this feedback can be tracked through the following feedback link,
Recommended approach - exe will perform automatic configuration
Please find the patch setup from below location:
http://syncfusion.com/Installs/support/patch/18.2.0.44/1188935/F156528/SyncfusionPatch_18.2.0.44_1188935_8132020085359292_F156528.exe
Advanced approach – use only if you have specific needs and can directly replace existing assemblies for your build environment
Please find the patch assemblies alone from below location:
http://syncfusion.com/Installs/support/patch/18.2.0.44/1188935/F156528/SyncfusionPatch_18.2.0.44_1188935_8132020085359292_F156528.zip
NuGet package: http://syncfusion.com/Installs/support/patch/18.2.0.44/1188935/F156528/SyncfusionNuget_18.2.0.44_1188935_8132020085359292_F156528.zip
Assembly Version: 18.2.0.44
Installation Directions :
This patch should replace the files “Syncfusion.Pdf.Portable.dll” under the following folder.
$system drive:\ Files\Syncfusion\Essential Studio\18.2.0.44\precompiledassemblies\18.2.0.44\2.0
Eg : $system drive:\Program Files\Syncfusion\Essential Studio\9.3.0.61\precompiledassemblies\9.3.0.61\4.0
To automatically run the Assembly Manager, please check the Run assembly manager checkbox option while installing the patch. If this option is unchecked, the patch will replace the assemblies in precompiled assemblies’ folder only. Then, you will have to manually copy and paste them to the preferred location or you will have to run the Syncfusion Assembly Manager application (available from the Syncfusion Dashboard, installed as a shortcut in the Application menu) to re-install assemblies.
Note :
To change how you receive bug fixes, ask your license management portal admin to change your project’s patch delivery mode.
https://www.syncfusion.com/account/license
Disclaimer :
Please note that we have created this patch for version 18.2.0.44 specifically to resolve the following issue(s) reported in this/the forum(s). 156528
If you have received other patches for the same version for other products, please apply all patches in the order received.
This fix will be included in our Volume 3 release which will be available in end of September, 2020.
Regards,
Sowmiya Loganathan
MG
Madhu Ganesh
August 13, 2020 06:27 PM UTC
I am working with Visual Studio for Mac to build my Xamarin.Forms app so can you please share executable or some installation directions for that will work on Mac
Thanks,
Madhu
SL
Sowmiya Loganathan
Syncfusion Team
August 14, 2020 09:40 AM UTC
Hi Madhu,
Please find the below UG and KB documentation to install the patch,
Install patch NuGet in MacOS: https://www.syncfusion.com/kb/10474/how-to-install-the-customer-patch-nuget-in-macos-machine
Install patch setup: https://www.syncfusion.com/kb/968/how-to-install-a-patch-setup-that-i-got-from-support
Apply patch for major or service pack version: https://help.syncfusion.com/common/essential-studio/apply-the-patch-for-major-or-service-pack-version
Please try the above in your end and let us know if you need any further assistance on this.
Regards,
Sowmiya Loganathan
MG
Madhu Ganesh
August 18, 2020 06:09 AM UTC
I have tried this solution and it is not working. I have tried it in my project as well as the sample project you had previously provided before in this thread and it does not work in both.
I removed all the related Pdf nugets such as Syncfusion.Xamarin.Pdf and Syncfusion.Xamarin.PdfViewer and added the nuget for the Syncfusion.Xamarin.Pdf version 18.2.0.44 provided and downgraded the Syncfusion.Xamarin.PdfViewer to 18.2.0.44.
Please provide a sample project with image showing up in a merged pdf.
SL
Sowmiya Loganathan
Syncfusion Team
August 19, 2020 03:21 PM UTC
Hi Madhu,
We ensured the fix with provided patch and its working fine and we have created simple sample with provided patch NuGet. Please find the download link for the same from below,
Please try the above sample in your end and let us know the result.
Regards,
Sowmiya Loganathan
MG
Madhu Ganesh
August 19, 2020 06:37 PM UTC
Hi,
Attachment: Screen_Shot_20200819_at_10.49.32_AM_4e820b46.zip
The provided fix is not working for me. The only line I changed in the project was:
//Get the root path in iOS device.
string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
I was not able to save to SpecialFolder.MyMusic in the emulator so I changed it to SpecialFolder.Personal. I did not touch any of the packages or do any upgrades on them.
I have attached a screenshot of what I am getting on my end. Pls advise
Attachment: Screen_Shot_20200819_at_10.49.32_AM_4e820b46.zip
SL
Sowmiya Loganathan
Syncfusion Team
August 20, 2020 03:40 PM UTC
Hi Madhu,
The sample which we provide on previous update works fine in our end in iOS device. We suspect NuGet cache causes this issue. Please refer the below KB to clear NuGet cache from machine,
Kindly try the above solution in your end and let us know the result. Or else we can set up a web meeting to look into the problem directly on your machine to provide the solution. Please let us know your availability for a web meeting, we will make every effort to have this scheduled for a time of your convenience.
Note: We work in IST hours.
Regards,
Sowmiya Loganathan
MG
Madhu Ganesh
August 22, 2020 01:38 AM UTC
Hi,
I did as you advised and cleared Nuget cache. Now, I am able to see the image if I open the pdf in Preview on Mac but if I open the same pdf in SfPdfViewer on the Xamarin app or on Acrobat Reader on the Mac, I am unable to see the image. I am only able to see a box with the label of the box in it.
I would like to set up a web meeting to get this solved. 8am IST to 1pm IST works for me.
Thank you,
Madhu
SL
Sowmiya Loganathan
Syncfusion Team
August 24, 2020 10:13 AM UTC
Hi Madhu,
We have created a new incident under your Direct trac account . We suggest you to follow up with the incident for further updates. Please log in using the below link.
https://www.syncfusion.com/account/login
Regards,
Sowmiya Loganathan
SIGN IN To post a reply.
- 13 Replies
- 3 Participants
-
MG Madhu Ganesh
- Jul 30, 2020 11:45 AM UTC
- Aug 24, 2020 10:13 AM UTC