Load PdfViewer with Uploader

Hello Team!

When try to load pdfViewer with uploader https://blazor.syncfusion.com/documentation/pdfviewer/opening-pdf-file/?no-cache=1
<SfUploader ID="UploadFiles" AllowedExtensions=".pdf,.PDF">
    <UploaderEvents FileSelected="onsuccess"></UploaderEvents>
</SfUploader>
<SfPdfViewerServer @ref="@Viewer" Width="1060px" Height="500px" />

    public void onsuccess(SelectedEventArgs action)
    {
        string filePath = action.FilesData[0].RawFile.ToString();
        Viewer.Load(filePath, null);
    }

I have this error


his there another way to achieve what I want?? my use case is to validate the load pdf in order to be sure that it containts some mandatory fields name before save it in my database. I was trying to use this possibility and after i would have export formfields of pdfViewer and check if my json contains my mandatory elements. Is it a proper way to do it or there is another shorter possibility?

Thanks,
Chimène NK.

10 Replies

AA Akshaya Arivoli Syncfusion Team April 2, 2020 12:40 PM UTC

Hi NKOUAMBIA , 

Thank you for using Syncfusion products. 

We are unable to understand your exact requirement with the provided details. Can you please provide more details about your requirement, use case scenario and confirm us whether you want to validate the required form fields(which are preserved in the PDF document structure) before saving it in Database using PDF Viewer. Also please provide your usage of the FileUploader, use case document and the sample. These details will be helpful for us to investigate further and assist you better. 

  
Regards,  
Akshaya  



NC NKOUAMBIA CHIMENE April 2, 2020 08:28 PM UTC

Hello Team!

My use case is to validate the loaded pdf in other to make sure that my templates pdf contains some fields with specific name like e.g.( name_of_town, date_of_birth, postal_zip, ...). because those informations will be loaded by default when initialize the pdf for editing and it come from a query in database that always provide the column with the specified name that have to match with those mandatory pdf formfields.

So when i add a new pdf templates I have to make sure those specific fields are in if not i have to inform the user that those fields are missing he can decide to save it as is or change the specified fields name to match the requirements.
This is the code i wrote (but in other to have a memory steam i was using uploader to allows user to load a file from disk) and it throws error i post on my previous message
protected async Task<Dictionary<String, String>> CheckSignetInGabarit(MemoryStream ms)
{
await _viewer.Load("data:application/pdf;base64," + Convert.ToBase64String(ms.ToArray()), null);
object base64Data = await _viewer.ExportFormFieldsAsObject();
var jsonFieldPdf = JObject.Parse(base64Data.ToString());
var nameSignetNotFound = new Dictionary<String, String>();
foreach (MandatoryItems signet in MandatoryItemsList)
{
if (!jsonFieldPdf.ContainsKey(signet.NomSignet))
nameSignetNotFound.Add(signet.NomSignet, signet.InformationSource);
}

return nameSignetNotFound;
}

Is ther a better way to do it?

Thanks,
Chimène NK.


AA Akshaya Arivoli Syncfusion Team April 3, 2020 01:42 PM UTC

Hi NKOUAMBIA, 

Currently we do not have support to validate the form fields in our PDF Viewer. However we are currently working on providing support to validate the form field by exposing the events. That event will be triggered on performing download/ print with not filled form fields in the loaded document. And all the non filled fields are exposed in the event arguments, using that you can identify the non filled form fields and notify the user based on that in your application level. The implementation will be included in our weekly release on April 8th.  

Regards, 
Akshaya  



NC NKOUAMBIA CHIMENE April 8, 2020 08:13 PM UTC

Hello Akshaya Arivoli!

I Have a Question, 
1- Is there a possiblity to empty formfields without necessary have to write pdfviewer.load(emptydynamicpdf), a little like the empty formfields in the Acrobat Reader Pro.

2-Is there a way to check if the pdf have formfields? before doing the object base64Data = await Viewer.ExportFormFieldsAsObject(); to avoid the bellow error if a user join a non dynamic pdf! 
 

Cordialement,
Chimène NK.



AA Akshaya Arivoli Syncfusion Team April 9, 2020 02:05 PM UTC

Hi NKOUAMBIA , 


We are currently checking on the reported query, we will update you with further details on April 10th, 2020 



Regards, 
Akshaya 
>>>>>>>>>>>>>>>>>>>>>>>>> 



MS Mohan Selvaraj Syncfusion Team April 10, 2020 09:46 AM UTC

Hi NKOUAMBIA , 

Is there a possiblity to empty formfields without necessary have to write pdfviewer.load(emptydynamicpdf), a little like the empty formfields in the Acrobat Reader Pro. 
We can empty the form fields by importing and exporting the form fields.We need to exportformfields with empty values and save them in a location and after that import the data for the same PDF document. So the value gets saved. 

Example: 

Use the below code for exporting the empty formfields data initially. 
viewer.ExportFormFields(); 
 
And then import the exported  data in to the PDF Viewer control for emptying the form fields value.  
viewer.ImportFormFields("wwwroot/Data/ff.json") 
 


If the provided details doesn’t matches your criteria. Kindly provide more details about the query. So that would be helpful for us to analysis more and assist you better. 
Is there a way to check if the pdf have formfields? before doing the object base64Data = await Viewer.ExportFormFieldsAsObject(); to avoid the bellow error if a user join a non dynamic pdf!  

At present we don’t have support to check the PDF has a form fields. We will implement the usability feature and it will be available in volume 1 SP1 release. 


Regards, 
Mohan S 



NC NKOUAMBIA CHIMENE April 15, 2020 12:36 PM UTC

Hello Team!

Consider that i'm comming from database with my document which have been already edited and I want to empty form fields, you see that the given solution doesn't work since i will not be able to first export the empty form fields. And the document can be different so the ideal way is to do it like in Adobe Reader if possible.

Thanks,
Chimène NK. 


AA Akshaya Arivoli Syncfusion Team April 16, 2020 07:35 AM UTC

Hi NKOUAMBIA , 

Thank you for your update, 

As mentioned earlier , currently we do not have support to empty the form fields using the PDF Viewer. However we will analyze further on it and update you with more details on April 20th, 2020 

Regards, 
Akshaya 



NC NKOUAMBIA CHIMENE April 27, 2020 09:39 PM UTC

Hello Team!

Is there a way to get the fieldCollection by name for example 
fieldCollection["NameOfField"].Flatten = true; to avoid looping throw all the fieldcollection to find a specific field
foreach (var field in loadedDocument.Form.Fields)
{
	if (loadedDocument.Form.Fields[i].Name == "NameOfField")
	{
		loadedDocument.Form.Fields[i].Flatten = true; 
	} 
	i++; 
}
 

Thanks,
Chimène Nk.


AA Akshaya Arivoli Syncfusion Team April 28, 2020 07:46 AM UTC

Hi Chimène,   
  
We can able to get the specific field name without looping all the field collection by using TryGetField method. Please refer the below code snippet for more details,  
  
//Load the existing PDF form  
PdfLoadedFormFieldCollection fields = doc.Form.Fields;  
PdfLoadedField field = null;  
  
//Get the specific field by name  
fields.TryGetField("FirstName", out field);  
  
//Set text  
(field as PdfLoadedTextBoxField).Text = "Modified";   
  
Please try the above solution in your end and let us know if you need any further assistance on this.   
   
Regards, 
Akshaya 


Loader.
Up arrow icon