This is a migrated thread and some comments may be shown as answers.

Update AcroForms Field from code

2 Answers 9 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
Ali
Top achievements
Rank 1
Ali asked on 14 Nov 2018, 12:22 PM

Is there any way to let the PdfViewer update its content after changing a field value by code?

 

In the documentation it is said:

"The UI of RadPdfViewer responds to interactive changes in field values (through mouse interaction with the UI) and it is not recommended to change the field collection in code. If you change the field values from your code, this may lead to unpredictable UI behavior and the applied changes will not be saved when using the SaveAs command."

 

A PdfViewer .UpdateAcroFormsFields() or Field.UpdateUI() method on the PdfViewer would be highly useful!

2 Answers, 1 is accepted

Sort by
0
Accepted
Georgi
Telerik team
answered on 19 Nov 2018, 11:54 AM
Hello Ali,

Thank you for your feedback.

RadPdfViewer is used only for visualization purposes and not for editing. The reason behind this is that RadPdfViewer and PdfProcessing share the same public API but differ internally. We understand this is inconvenient and we are currently working to merge both models into one. As a possible workaround, you can import and edit the document using the PdfFormatProvider of the PdfProcessing library. After exporting it, you can import it using the PdfFormatProvider of RadPdfViewer as can be seen in the following forum thread. For example, to apply the value of a TextBoxField with a specified name, the following code can be used:
PdfFormatProvider pdfProcessingFormatProvider = new PdfFormatProvider();
RadFixedDocument document = pdfProcessingFormatProvider.Import(File.ReadAllBytes(fileName));
 
TextBoxField textField = document.AcroForm.FormFields[formFieldName] as TextBoxField;
if (textField != null)
{
    textField.Value = "New value";
}
 
byte[] documentData = pdfProcessingFormatProvider.Export(document);
PdfFormatProvider pdfViewerFormatProvider = new PdfFormatProvider(new MemoryStream(documentData));
RadFixedDocument editedDocument = pdfViewerFormatProvider.Import();
this.pdfViewer.Document = editedDocument;

I hope this helps.

Regards,
Georgi
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Ali
Top achievements
Rank 1
answered on 19 Nov 2018, 06:39 PM

Thank you very much Georgi!

The workaround works perfectly!

Tags
PDFViewer
Asked by
Ali
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Ali
Top achievements
Rank 1
Share this question
or