We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Unable to fill forms for PDF

Hi,

I'm using the PDFViewer control to display a fillable PDF document to the user in an Asp.Net MVC web page. The display works fine and I can show the PDF to the user in the browser. However, the next step is to update the PDF with the data that the user fills in and save it back to the server.

Towards this, I'm leveraging the Download event of the PDF Viewer, since the filled in form data is passed in to this method as JSON. However, I'm unable to fill the form fields and save down the PDF. Below is my controller code for the Download method:

        public object Download(pdfViewerJsonResult jsonResultObj)
        {
            PdfViewerHelper helper = new PdfViewerHelper();

            // First, get the empty, unfilled version of the document
            PdfLoadedDocument loadedDocument = new PdfLoadedDocument(helper.DocumentStream);

            foreach (PdfLoadedField field in loadedDocument.Form.Fields)
            {
                if (field is PdfLoadedTextBoxField)
                {
                    ((PdfLoadedTextBoxField)field).Text = "1";
                }
            }
            
            loadedDocument.Save(@"C:\Test\FormDocument.pdf");
            loadedDocument.Close(true);
}


In the above code snippet, I'm trying to simply set the value for all fillable form fields to "1", but even that is not working. On top of that, when I open the saved document, it already switches to ReadOnly, meaning, when I re-open the saved document in Adobe PDF, the fillable fields are no longer part of the document.

Attached is the PDF i'm using to test this,

10 Replies

RT Ramya Thirugnanam Syncfusion Team April 10, 2019 11:10 AM UTC

Hi Saurabh, 
 
We have tried to reproduce the reported issue with the latest Essential Studio Version 17.1.0.38 using the below code, but we are unable to reproduce the reported issue. 
 
public object Download(Dictionary<string, string> jsonResult) 
        { 
           PdfViewerHelper helper = new PdfViewerHelper();      
            object pdfData = (object)helper.GetDocumentData(jsonResult); 
            var propertyInfo = pdfData.GetType().GetProperty("documentStream"); 
            string value = propertyInfo.GetValue(pdfData, null).ToString(); 
            byte[] byteContents = Convert.FromBase64String(value); 
            // First, get the empty, unfilled version of the document 
            PdfLoadedDocument loadedDocument = new PdfLoadedDocument(byteContents); 
            foreach (PdfLoadedField field in loadedDocument.Form.Fields) 
            { 
                if (field is PdfLoadedTextBoxField) 
                { 
                    ((PdfLoadedTextBoxField)field).Text = "1"; 
                } 
            } 
 
            loadedDocument.Save(HttpContext.Current.Server.MapPath("~/Data/FormDocument.pdf")); 
            loadedDocument.Close(true); 
            return helper.GetDocumentData(jsonResult); 
        } 
 
We have created the sample for the same and shared in the following location, 
 
We can fill the form fields in the UI of the PDF Viewer and it can be retrieved with the form filled values in the Download() Action method of the WebAPI controller, which can be saved in the server using the below code, 
public object Download(Dictionary<string, string> jsonResult) 
        { 
            PdfViewerHelper helper = new PdfViewerHelper(); 
            object pdfData = (object)helper.GetDocumentData(jsonResult); 
            var propertyInfo = pdfData.GetType().GetProperty("documentStream"); 
            string value = propertyInfo.GetValue(pdfData, null).ToString(); 
            byte[] byteContents = Convert.FromBase64String(value); 
            File.WriteAllBytes(HttpContext.Current.Server.MapPath("~/Data/FormFillingDocument.pdf"), byteContents); 
             return null;          
        } 
 
Could you please try this and revert us with more details like Essential Studio Version, PDF document, modified sample and the use case scenario about your requirement, if the provided details do not meet your requirement. These details will be helpful for us to investigate more on your requirement and assist you better. 
 
Regards, 
Ramya T 



SD Saurabh D April 11, 2019 02:27 AM UTC

Hi,

Thanks for the sample - I upgraded to the latest version and it seems to be working. However, I'm now running into another issue - I'm able to edit the PDF file in the PDF Viewer, and save the modified file to disk. However, the saved file loses the editable fields and is now read-only. This only happens with the attached document - it works okay with the test document from your sample. Can you please help?

Attachment: i485_82366cc0.zip


RT Ramya Thirugnanam Syncfusion Team April 11, 2019 04:18 PM UTC

Hi Saurabh,  
 
We can reproduce the reported issue with the provided PDF document. On analyzing, we found that the provided document has extended rights. As per the specification, the extended feature document is a process that requires digital signature using private key from Adobe. If we change/add the content of extended PDF, it will be breaking the signature and will cause an error message. So that while adding watermark text in the PDF it causes the error message when open it to Adobe Reader. 
 
Hence kindly include the Valid license key in your project to get this issue resolved. Please find the below UG link for including valid license key in your project. 
 
Regards, 
Ramya T 



SD Saurabh D April 12, 2019 03:13 AM UTC

Hi Ramya,

Thanks for your prompt response, I think I'm very close - please refer to the attached project, where I let the user fill the PDF, and would like to save the document down locally on the server. I don't need to modify the file - simply take the filled PDF that the user fills and save it down to disk.

I've verified that my product key is in global.asax.cs. However, it saves the file with no fields populated. The fiels are all editable in the saved version, but they're all blank, even though I explicityly fill them in the UI.. Please refer to my attached project.

Attachment: PdfViewer_MVCsample_30b40be3.zip


RT Ramya Thirugnanam Syncfusion Team April 12, 2019 12:43 PM UTC

Hi Saurabh,   
 
The provided PDF document contains XFA forms fields, The support for saving the XFA forms is only provided in our latest release by PDF.BASE ,So we need to apply the same in our PDF Viewer control and will update the patch on 16th  April 2019.In the meanwhile, please use the workaround for saving the fields in the PDF document. 
 
            PdfViewerHelper helper = new PdfViewerHelper(); 
            object pdfData = (object)helper.GetDocumentData(jsonResult); 
            var propertyInfo = pdfData.GetType().GetProperty("documentStream"); 
            string value = propertyInfo.GetValue(pdfData, null).ToString(); 
            byte[] byteContents = Convert.FromBase64String(value); 
            PdfLoadedDocument loadedDocument = new PdfLoadedDocument(byteContents); 
 
            //Fill the XFA form. 
            loadedDocument.Form.EnableXfaFormFill = true; 
 
            foreach (PdfLoadedField field in loadedDocument.Form.Fields) 
            { 
                if (field is PdfLoadedTextBoxField) 
                { 
                    ((PdfLoadedTextBoxField)field).Text = "syncfusion"; 
                } 
            } 
            loadedDocument.Save(@"Downloaded.pdf"); 
 
Regards, 
Ramya T 



RT Ramya Thirugnanam Syncfusion Team April 16, 2019 09:09 AM UTC

Hi Saurabh,   
 
The patch for reported issue can be downloaded from the below link. 
   
Recommended approach - exe will perform automatic configuration
Please find the patch setup from below location: 
  
 
Advanced approach – use only if you have specific needs and can directly replace existing assemblies for your build environment
Please find the patch assemblies alone from below location: 
  
 
NuGet for this issue: 
 

Assembly Version: 17.1.0.38
Installation Directions : 
This patch should replace the files “Syncfusion.Pdf.Base” and Syncfusion.EJ.PdfViewer under the following folder.
$system drive:\ Files\Syncfusion\Essential Studio\$Version # \precompiledassemblies\$Version#\4.6
Eg : $system drive:\Program Files\Syncfusion\Essential Studio\9.3.0.61\precompiledassemblies\9.3.0.61\4.0

To automatically run the Assembly Manager, please check the Run assembly manager checkbox option while installing the patch. If this option is unchecked, the patch will replace the assemblies in precompiled assemblies’ folder only. Then, you will have to manually copy and paste them to the preferred location or you will have to run the Syncfusion Assembly Manager application (available from the Syncfusion Dashboard, installed as a shortcut in the Application menu) to re-install assemblies.

Disclaimer : 
Please note that we have created this patch for version 17.1.0.38 specifically to resolve the following issue(s) reported in this forum 143902.

If you have received other patches for the same version for other products, please apply all patches in the order received.
The bug fix will be included in our SP1 of Volume 1 which will be available in May 2019.
 
  
Regards,  
Ramya T  



SD Saurabh D April 20, 2019 03:13 AM UTC

Hi,

Thank you for your continued help with resolving issues with the product. I wanted to report a potential bug that I'm seeing - it appears that when certain form fields have predetermined character length defined, the pdf viewer control behaves in a weird way where it repeats characters.

As an example, please try to load the attached PDF in the PDF Viewer, go to Page # 2, Line Item 8 (Country of Birth), and try to enter "United States Of America". The behavior I'm seeing is that the control does not allow me to type in the entire name.

Thanks.


Attachment: i485_8d9ee78e.zip


RT Ramya Thirugnanam Syncfusion Team April 22, 2019 09:07 AM UTC

Hi Saurabh, 
 
Thanks for your update. 
 
When we analyzed the provided document, “Country of Birth” text box field has maximum length set to the PDF dictionary. So the text “United States Of America” cannot be typed entirely in the Adobe PDF viewer. This is the behavior of the text box form field. 
 

 
When the provided document is loaded in the Syncfusion ejPdfViewer control, we are able to notice a repetition of characters when the maximum length is reached in the text box. 
 
 
 
Could you please confirm us that this is the issue that you have faced?  However, we will analyze in this issue and update you with further details on April 24, 2019. 
 
Regards, 
Ramya T 



RT Ramya Thirugnanam Syncfusion Team April 24, 2019 12:27 PM UTC

Hi Saurabh, 

Thank you for your patience. 

We have confirmed that the issue “Text characters are repeated when the maximum length in reached in the text box form field” as a defect and logged a defect report for the same. The patch for the fix is expected to be available on May 8, 2019. 

Regards, 
Ramya T 



RT Ramya Thirugnanam Syncfusion Team May 8, 2019 09:03 AM UTC

Hi Saurabh,

The issue with " Text characters are repeated when the maximum length in reached in the text box form field" has been fixed and the patch for this fix can be downloaded from the following location.

Recommended approach - exe will perform automatic configuration
Please find the patch setup from below location:
http://syncfusion.com/Installs/support/patch/17.1.0.38/1088848/F143902/SyncfusionPatch_17.1.0.38_1088848_5082019032055498_F143902.exe 

Advanced approach – use only if you have specific needs and can directly replace existing assemblies for your build environment
Please find the patch assemblies alone from below location:
http://syncfusion.com/Installs/support/patch/17.1.0.38/1088848/F143902/SyncfusionPatch_17.1.0.38_1088848_5082019032055498_F143902.zip 
 

Assembly Version: 17.1.0.38
Installation Directions :
This patch should replace the files “ej.web.all.min.js ” under the following folder.
$system drive:\ Files\Syncfusion\Essential Studio\$Version # \precompiledassemblies\$Version#\4.5
Eg : $system drive:\Program Files\Syncfusion\Essential Studio\9.3.0.61\precompiledassemblies\9.3.0.61\4.0

To automatically run the Assembly Manager, please check the Run assembly manager checkbox option while installing the patch. If this option is unchecked, the patch will replace the assemblies in precompiled assemblies’ folder only. Then, you will have to manually copy and paste them to the preferred location or you will have to run the Syncfusion Assembly Manager application (available from the Syncfusion Dashboard, installed as a shortcut in the Application menu) to re-install assemblies.

Note :
You can change how you receive bug fixes by navigating to the following link and updating your preferences.

https://www.syncfusion.com/support/directtrac/patches

Disclaimer :
Please note that we have created this patch for version 17.1.0.38 specifically to resolve the following issue(s) reported in this/the incident(s). 232875

If you have received other patches for the same version for other products, please apply all patches in the order received.
This fix will be included in our Volume 2 release which will be available in June 2019.

Regards,
Ramya Thirugnanam
 


Loader.
Up arrow icon