Updating ImageViewer's display after Programatically updating form fields

Questions, comments and suggestions concerning VintaSoft PDF .NET Plug-in.

Moderator: Alex

Post Reply
IntegraMike
Posts: 56
Joined: Mon Dec 02, 2019 11:19 pm

Updating ImageViewer's display after Programatically updating form fields

Post by IntegraMike »

Hello,

When setting the value of form fields programatically, the image viewer is not updating even though they are backed by the same stream. Is there a good way to solve this problem? Currently the best I have found is to called PdfDocument.SaveChanges then clear the images in the ImageViewer, then reload the images in the ImageViewer from the stream.

Calling ImageViewer.Refresh/ReloadImage/Image.Reload/etc. have not seemed to solve the issue. Any help you can provide would be appreciated.

Thanks!
Mike
Alex
Site Admin
Posts: 2319
Joined: Thu Jul 10, 2008 2:21 pm

Re: Updating ImageViewer's display after Programatically updating form fields

Post by Alex »

Hello Mike,

The PdfInteractiveFormField object stores information about form field data. Each form field has PDF Widget annotation, which is associated with PDF form field and defines appearance of form field. You can get PDF Widget annotation using PdfInteractiveFormField.Annotation property. You need to update PDF Widget annotation for updating the form field appearance.

Here is code snippet that demonstrates how to change data and update appearance for the first text field in PDF document:

Code: Select all

// get PDF page associated with the first image in image viewer
Vintasoft.Imaging.Pdf.Tree.PdfPage pdfPage = Vintasoft.Imaging.Pdf.PdfDocumentController.GetPageAssociatedWithImage(imageViewer1.Images[0]);

// get interactive form of PDF document
Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm interactiveForm = pdfPage.Document.InteractiveForm;
// get the first text field of PDF document
Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextField firstTextField = interactiveForm.Fields[0] as Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextField;
// change value of text field
firstTextField.TextValue = "New text value";
// update appearance of text field
firstTextField.Annotation.UpdateAppearance();

// reload image in image viewer
imageViewer1.Images[0].Reload(true);
Best regards, Alexander
Post Reply