BoldDesk®Customer service software offering ticketing, live chat, and omnichannel support, starting at $49/mo. for 10 agents. Try it for free.
Currently the latest version does not have this feature,
We want to have the ability to change images in PdfLoadedButtonField without deleting and re-adding affecting the pdf file
For example
PdfLoadedButtonField loadedButtonField = loadedPage.Form.Fields["buttonFieldName"] as PdfLoadedButtonField;
// Create a new image to set as the button's image
Bitmap newImage = new Bitmap("path_to_new_image.jpg");
// Create PdfBitmap object from new image
PdfBitmap pdfImage = new PdfBitmap(newImage);
// Update the button's image
loadedButtonField.Appearance.Normal.Graphics.DrawImage(pdfImage, new RectangleF(0, 0, loadedButtonField.Bounds.Width, loadedButtonField.Bounds.Height));
// Save the edited document
loadedDocument.Save("output.pdf");
if (form.FieldsWidget[i] is PdfButtonWidgetFieldWidget)
{ PdfButtonWidgetFieldWidget field = form.FieldsWidget[i] as PdfButtonWidgetFieldWidget; if (field.Name == "Image") { field.SetButtonImage(PdfImage.FromFile("logo.png")); } }
Please help us, thank you very much, we need this feature
This is the actual behavior. We are not supposed to modify the appearance of the existing button field. As a workaround, we can get the bounds of the button field and delete the existing field and create a new button field over the bounds and modify the appearance of the field.
please refer to the below code:
//Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a new page to PDF document. PdfPage page = document.Pages.Add(); PdfForm pdfForm = document.Form; pdfForm.SetDefaultAppearance(false); //Create a Button. PdfButtonField buttonField = new PdfButtonField(page, "buttonFieldName"); //Set properties to the Button field. buttonField.Bounds = new Syncfusion.Drawing.RectangleF(0, 150, 90, 20); FileStream imgStream = new FileStream("ImageToPDF.png", FileMode.Open, FileAccess.Read); PdfBitmap image = new PdfBitmap(imgStream); RectangleF bounds= new Syncfusion.Drawing.RectangleF(0, 0, buttonField.Bounds.Width,buttonField.Bounds.Height); buttonField.Appearance.Normal.Graphics.DrawImage(image, bounds); //Add the form field to the document. document.Form.Fields.Add(buttonField); MemoryStream savedStream = new MemoryStream(); // Save the edited document document.Save(savedStream); File.WriteAllBytes("Before.pdf", savedStream.ToArray()); PdfLoadedDocument pdfLoadedDocument = new PdfLoadedDocument(savedStream); PdfLoadedPage? loadedPage = pdfLoadedDocument.Pages[0] as PdfLoadedPage; PdfLoadedForm form= pdfLoadedDocument.Form; //Set default appearance to false. form.SetDefaultAppearance(false); PdfLoadedButtonField? loadedButtonField = pdfLoadedDocument.Form.Fields["buttonFieldName"] as PdfLoadedButtonField; form.Fields.Remove(loadedButtonField); // Create a new image to set as the button's image FileStream imageStream = new FileStream("animals.jpg", FileMode.Open, FileAccess.Read); PdfBitmap pdfImage = new PdfBitmap(imageStream); //Create a Button. PdfButtonField newbuttonField = new PdfButtonField(loadedPage, "buttonFieldName"); //Set properties to the Button field. newbuttonField.Bounds = new Syncfusion.Drawing.RectangleF(buttonField.Bounds.X, buttonField.Bounds.Y, buttonField.Bounds.Width, buttonField.Bounds.Height); newbuttonField.Text = "buttonFieldName"; RectangleF imgBounds = new RectangleF(0, 0, newbuttonField.Bounds.Width, newbuttonField.Bounds.Height); newbuttonField.Appearance.Normal.Graphics.DrawImage(pdfImage,imgBounds); //Add the form field to the document. pdfLoadedDocument.Form.Fields.Add(newbuttonField); MemoryStream outputStream = new MemoryStream(); // Save the edited document pdfLoadedDocument.Save(outputStream); string fileName = string.Empty; fileName = "Image.pdf"; File.WriteAllBytes(fileName, outputStream.ToArray()); |
Thank you for your feedback
However, there is a problem with my PDF file: I am not allowed to delete or add new Form Fields,
Because my PDF file has been added with a digital certificate, I am only allowed to change the button field and Appearance image,
I hope the upcoming version will support this feature, ( Change the image on button field )
Similar to some other brands' products that I have found.
Hi Thuy,
Currently, we are analyzing this and will update with further details on June 24, 2024.
Regards,
Jeyalakshmi T
Thank you very much,
Hopefully, the company supports this feature, because other products also have it.
Hi Thuy,
Currently, we do not support to update appearance of the existing button field.We have logged the feature request called “Support to update appearance of the existing button field.” in our end. And we do not have any immediate plan to implement this feature. It will be available any of our upcoming releases.
You can track the status using the following feedback link:
https://www.syncfusion.com/feedback/58951/support-to-update-appearance-of-the-existing-button-field
Regards,
Jeyalakshmi T