Update AcroForms Field from code

3 posts, 1 answers
  1. Ali
    Ali avatar
    14 posts
    Member since:
    Nov 2018

    Posted 14 Nov 2018 Link to this post

    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. Answer
    Georgi avatar
    50 posts

    Posted 19 Nov 2018 Link to this post

    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.

    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.
  3. Ali
    Ali avatar
    14 posts
    Member since:
    Nov 2018

    Posted 19 Nov 2018 in reply to Georgi Link to this post

    Thank you very much Georgi!

    The workaround works perfectly!

Back to Top