PdfFormatProvider modified the text in field to where it is rotated vertically.

1 Answer 103 Views
PdfProcessing
John
Top achievements
Rank 1
Iron
Iron
John asked on 24 Feb 2022, 12:50 PM
I am able to modify the field correctly and get them to have the correct value. When I export/save the file the form textboxes are all rotated vertically and the only fix I have been able to do is to modify the rotation of the field text in another editor. This kind of ruins the idea of code filling the pdf forms and automating the process. PDFFormatProvider / Telerik Document Processing library is 2022.1.106. I tried rotating the field after value edit to 0,90,etc...and they have all resulted in the similar issue.

1 Answer, 1 is accepted

Sort by
1
John
Top achievements
Rank 1
Iron
Iron
answered on 24 Feb 2022, 01:12 PM
After digging for hours and modifying the code. After asking this question...it seems that the document has to be flagged to recalculate the form field per viewer flag to be set to true. Hope this helps other people. "document.AcroForm.ViewersShouldRecalculateWidgetAppearances = true;"
Tanya
Telerik team
commented on 01 Mar 2022, 10:53 AM

Hi John,

Indeed, the ViewersShouldRecalculateWidgetAppearances property forces the viewer to recalculate the content of each widget according to the properties applied to it. This property is usually needed when changing the widget properties.

Thank you for sharing the solution you have found. 

Nora
Top achievements
Rank 1
commented on 19 Jan 2024, 01:28 PM

Hey 

I have the same issue but using your solution didnt make a difference for me .. any other ideas?

 

Yoan
Telerik team
commented on 22 Jan 2024, 10:12 AM

Hi Nora,

I am willing to help you with resolving the issue you are experiencing but with no resources at my disposal, my assistance is very limited.

In order for me to get a better context and understanding of this case, would you be able to share with us an example project that reproduces this behavior? That way I can try to achieve the same scenario you are describing, examine the results, and get back to you with details and specifics.

Note: Please keep in mind that this is a public forum thread and all attached resources are available for everyone, so make sure you omit any sensitive data that you don't want to be made public.

Thank you in advance for your cooperation.

Regards,

Yoan

Nora
Top achievements
Rank 1
commented on 22 Jan 2024, 01:15 PM

Thanks for reaching out yoan.

Look in the following screenshot, you can see the document is rotated to landscape, and the filled in fields are horizontal. but once i click on one of them the value shows vertically. this of course is not good enough because if i try to print the document the values show up horizontal.

In the following code you can see how i populate the fields. and also how i render the RadFixedDocument to bytes.


This is how i create the document

public RadFixedDocument CreatePdfDocument(string formTemplatePath)
        {  
            var document = new RadFixedDocument();
            document.AcroForm.ViewersShouldRecalculateWidgetAppearances = true;
            document = _provider.Import(File.ReadAllBytes(HttpContext.Current.Server.MapPath($"~\\Modules\\template1)));

            document.AcroForm.ViewersShouldRecalculateWidgetAppearances = true;
            return document;
        }

"PdfFormField" is my own class used to store some data

private static void PopulateFieldValue(PdfFormField formField, FormField widgetField)
        {
            switch (widgetField.FieldType)
            {
                case FormFieldType.TextBox:
                    var textBoxField = widgetField as TextBoxField;
                    if (textBoxField != null && formField.FieldValue != null)
                    {
                        textBoxField.Value = formField.FieldValue.ToString();
                    }
                    break;
                case FormFieldType.CheckBox:
                    var checkBoxField = widgetField as CheckBoxField;
                    if (checkBoxField != null)
                    {
                        checkBoxField.IsChecked = Convert.ToBoolean(formField.FieldValue);
                    }
                    break;
                case FormFieldType.RadioButton:
                    var radioButtonField = widgetField as RadioButtonField;
                    if (radioButtonField != null)
                    {
                        var radOpt = new RadioOption(formField.FieldValue.ToString()); 
                        radioButtonField.Value = radOpt;
                    }
                    break;
            }
        }

and how i export to bytes

internal byte[] RenderPdfForm(PdfForm pdfForm)
        {
            pdfForm.pdfDocument.AcroForm.ViewersShouldRecalculateWidgetAppearances = true;
            return _provider.Export(pdfForm.pdfDocument);
        }

 

you can see i tried setting "ViewersShouldRecalculateWidgetAppearances" in few places but none of them made a difference.

any ideas?

Nora
Top achievements
Rank 1
commented on 23 Jan 2024, 02:38 PM | edited

Yoan
Telerik team
commented on 23 Jan 2024, 04:03 PM

Hello Nora,

For the sake of privacy while sharing resources I have converted the above-linked thread to a Support type. If you don't mind we can continue our communications and investigation in the newly converted Support ticket.

Regards,

Yoan 

Tags
PdfProcessing
Asked by
John
Top achievements
Rank 1
Iron
Iron
Answers by
John
Top achievements
Rank 1
Iron
Iron
Share this question
or