Blazor PDFViewer Conrtol Import/ Export Annotation Format

Hi Team,

I have a requirement to import and export xfdf and fdf file with a PDF file using Blazor PDF Viewer. As I am only able to do the same things with Json format. Please suggest how could i use import/export feature with fdf/xfdf Blazor.

Thanks,
Sachin Kumar

30 Replies 1 reply marked as answer

AA Akshaya Arivoli Syncfusion Team July 7, 2020 07:32 AM UTC

Hi Sachin, 

Thank you for contacting Syncfusion support 

Currently we do not have support to “Import and export annotations in XFDF format release for Blazor”. However, we have planned to implement the feature in Volume 2 SP 1 PDF Viewer and it will be expected at the end of JULY 2020. 


Regards, 
Akshaya 




SK sachin kumar July 7, 2020 10:28 AM UTC

Thanks Akshaya,

Could you please confirm me about the release date of SP1 with feature of import/export in xfdf/fdf?  I have one more query about the xfdf/fdf file exported by Xamarin PDF Viewer (Syncfusion) and Blazor version of xfdf/fdf (in coming release ), Will these both (Blazor and Xamarin) generate the same xfdf/fdf file if we do the same annotation.


Thank You,
Sachin Kumar


AA Akshaya Arivoli Syncfusion Team July 8, 2020 01:39 PM UTC

Hi Sachin, 

Thank you for your update. 

The implementation for “Import and export annotations in XFDF format release for Blazor” will be included in our 2020 Volume 2 SP1 release which is expected to be rolled out in the mid of August. We will let you know once the feature is implemented. Also, xfdf file exported by Xamarin PDF Viewer (Syncfusion) and Blazor version of xfdf will be the same. 

If you still have concerns. These details will be helpful for us to investigate further and assist you better. 

 Regards,  
Akshaya   



AB Arthur Butler September 18, 2020 06:19 AM UTC

Hi.  Do you have an update as to when 2020 Volume 2 SP1 will be available with this feature?

Thank you.

Arthur


AA Akshaya Arivoli Syncfusion Team September 21, 2020 12:54 PM UTC

Hi Arthur , 

Sorry for the inconvenience caused. The implementation was not included in our 2020 VOLUME 2 SP release. However, we will implement the feature “Import and export annotations in XFDF format” and it will be included in our 2020 Volume 3 SP release, which is expected to be rolled out in the end of October, 2020 

Regards, 
Akshaya  



VG Vivek Gupta October 13, 2020 04:02 AM UTC

HI Team,

Can you please confirm the release date of October, after which we can have this feature ??

Thanks,
Vivek


MS Mohan Selvaraj Syncfusion Team October 14, 2020 12:33 PM UTC

Hi Vivek, 
  
Sorry for the inconvenience caused 
  
we will implement the feature and it will be included in our 2020 Volume 3 SP release, which is expected to be rolled out in the first week of November 2020     
   
  
Regards, 
Mohan S


AA Akshaya Arivoli Syncfusion Team November 6, 2020 07:31 AM UTC

Hi Arthur,  

We have implemented the feature and the implementation was included in our 2020 Volume 3 SP release version 18.3.0.47.  


Code snippet:  
SfPdfViewerServer pdfviewer;  
public async void export()
{
await pdfviewer.ExportAnnotations();
}
public async void exportxfdf()
{
await pdfviewer.ExportAnnotations(AnnotationDataFormat.XFdf);
}
public async void import()
{
await pdfviewer.ImportAnnotations("blazor-succinctly.xfdf", AnnotationDataFormat.XFdf);
}  
 


Packages link:     
      
Client side package     
    
Blazor Client   
Blazor Sever  
Service side package     
ASP.NET Core :     
      
ASP.NET MVC:     
    
    
Regards,    
Akshaya    



AB Arthur Butler November 9, 2020 01:56 AM UTC

  1. Are there changes to the PDFViewerController to support this new functionality?  
  2. Where is the output of 
     ExportAnnotations()?  Do they get downloaded in the browser?
Regards,
Arthur


AA Akshaya Arivoli Syncfusion Team November 9, 2020 01:00 PM UTC

Hi Arthur, 

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

Regards, 
Akshaya  



AB Arthur Butler November 10, 2020 01:33 AM UTC

3. My requirement is to programaticaly save and restore the annotations behind the scenes.  I don't see how these APIs can satisfy that need.  Is there a way to do what I want - perhaps in the PDFViewerController?  FYI, I have a client side Blazor webassembly app.


AA Akshaya Arivoli Syncfusion Team November 10, 2020 05:00 PM UTC

Hi Arthur, 
 
Please find the details of your query from the below, 
 
Query 
Details 
Are there changes to the PDFViewerController to support this new functionality?   
 
 
We have created the Wen service project with the latest features in  Asp.Net Core and shared the same in the below link, 
 
 
 
Also we will update the documentation with latest changes 
Where is the output of  
 ExportAnnotations()?  Do they get downloaded in the browser? 
 
Yes, the exported annotations will be downloaded in xfdf format in the browser  
 My requirement is to programaticaly save and restore the annotations behind the scenes.  I don't see how these APIs can satisfy that need.  Is there a way to do what I want - perhaps in the PDFViewerController?  FYI, I have a client side Blazor webassembly app. 
We can import/export the annotations in XFDF format using the below code, 
 
public async void exportxfdf() 
    { 
        await Viewer.ExportAnnotations(Syncfusion.Blazor.PdfViewer.AnnotationDataFormat.Xfdf); 
    } 
    public async void import() 
    { 
        await Viewer.ImportAnnotations("PDF Succinctly (1).xfdf", Syncfusion.Blazor.PdfViewer.AnnotationDataFormat.Xfdf); 
    } 
 
 
 
Kindly try it and revert us with more details if any concerns on it. 
 
 
 
Regards, 
Akshaya  



AB Arthur Butler November 15, 2020 08:38 AM UTC

I have modified ExportAnnotations to save the data in a database instead of exporting it to a file.  The data looks like this:

77u/PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjx4ZmRmIHhtbDpzcGFjZT0icHJlc2VydmUiIHhtbG5zPSJodHRwOi8vbnMuYWRvYmUuY29tL3hmZGYvIj4NCiAgPGFubm90cz4NCiAgICA8c3RhbXAgcGFnZT0iMSIgcmVjdD0iNjYsNjgyLjUsOTAsNzA2LjUiIG5hbWU9ImUy...

This appears to be consistent with the data from the Xamarin.Forms PdfViewer.

I have modified ImportAnnotations to restore the annotations from the database.  I call ImportAnnotations in the DocumentLoaded event of the Blazor PdfViewer.  In turn, ImportAnnotations on the server was modified as 

jsonObject["importedData"] = annotations;  // same data that was saved to the database above
JsonResult = pdfviewer.ImportAnnotationFromXFdf(jsonObject);
return Content(JsonConvert.SerializeObject(JsonResult));

No error is returned, but the annotations are never displayed in the PdfViewer.

Any idea what the issue could be?

Regards,
Arthur


AA Akshaya Arivoli Syncfusion Team November 16, 2020 12:37 PM UTC

Hi Arthur , 

Thank you for your update. 

We are currently checking on the reported query with the provided details and we will update you with more details on November 17, 2020 

Regards, 
Akshaya  



AA Akshaya Arivoli Syncfusion Team November 17, 2020 12:23 PM UTC

Hi Arthur, 
 
We were unable to reproduce the reported issue with the provided details. We have shared the sample in which we have tried in the below link, 
 
public async void import() 
    { 
        await Viewer.ImportAnnotations("PDF Succinctly.xfdf", Syncfusion.Blazor.PdfViewer.AnnotationDataFormat.Xfdf); 
    } 
 
 
[AcceptVerbs("Post")] 
        [HttpPost("ImportAnnotations")] 
        [Microsoft.AspNetCore.Cors.EnableCors("MyPolicy")] 
        [Route("[controller]/ImportAnnotations")] 
        //Post action to import annotations 
         public IActionResult ImportAnnotations([FromBody] Dictionary<string, string> jsonObject) 
        { 
            PdfRenderer pdfviewer = new PdfRenderer(_cache); 
            string jsonResult = string.Empty; 
            object JsonResult; 
            if (jsonObject != null && jsonObject.ContainsKey("fileName")) 
            { 
                string documentPath = GetDocumentPath(jsonObject["fileName"]); 
                if (!string.IsNullOrEmpty(documentPath)) 
                { 
                    jsonResult = System.IO.File.ReadAllText(documentPath); 
                } 
                else 
                { 
                    return this.Content(jsonObject["document"] + " is not found"); 
                } 
            } 
            else 
            { 
                string extension = Path.GetExtension(jsonObject["importedData"]); 
                if (extension != ".xfdf") 
                { 
                    JsonResult = pdfviewer.ImportAnnotationFromXFdf(jsonObject); 
                    return Content(JsonConvert.SerializeObject(JsonResult)); 
                } 
                else 
                { 
                    string documentPath = GetDocumentPath(jsonObject["importedData"]); 
                    if (!string.IsNullOrEmpty(documentPath)) 
                    { 
                        byte[] bytes = System.IO.File.ReadAllBytes(documentPath); 
 
                        //jsonObject["importedData"] = Convert.ToBase64String(bytes); 
                        jsonObject["importedData"] = "77u/PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjx4ZmRmIHhtbDpzcGFjZT0icHJlc2VydmUiIHhtbG5zPSJodHRwOi8vbnMuYWRvYmUuY29tL3hmZGYvIj4NCiAgPGFubm90cz4NCiAgICA8ZnJlZXRleHQgcGFnZT0iMCIgcmVjdD0iMTcxLjc1LDY1OC41LDI4NSw3MDEuMjUiIHRpdGxlPSJHdWVzdCIgZGF0ZT0iRDoyMDIwMTExNzE3MDI1OSswNSczMCciIG5hbWU9ImI4Nzc5YjY4LTM0NGItNDVlYy1hYjhjLWY4YjcyZjdhOGVhMiIgc3ViamVjdD0iVGV4dCBCb3giIHJvdGF0aW9uPSIwIiBib3JkZXI9IjAsMCwxIiBmbGFncz0icHJpbnQiIGZyaW5nZT0iMCwwLDAsMCIgcT0iMCIgSVQ9IkZyZWVUZXh0VHlwZVdyaXRlciIgaGVhZD0iT3BlbkFycm93Ij4NCiAgICAgIDxkZWZhdWx0YXBwZWFyYW5jZT4xIDEgMSByZyA8L2RlZmF1bHRhcHBlYXJhbmNlPg0KICAgICAgPGRlZmF1bHRzdHlsZT5mb250OkhlbHZldGljYSAxMnB0O3N0eWxlOlJlZ3VsYXI7IGNvbG9yOiMwMDAwMDA8L2RlZmF1bHRzdHlsZT4NCiAgICAgIDxjb250ZW50cz5lcmZnM2Y8L2NvbnRlbnRzPg0KICAgIDwvZnJlZXRleHQ+DQogIDwvYW5ub3RzPg0KICA8ZiBocmVmPSJBbm5vdGF0aW9ucy54ZmRmIiAvPg0KPC94ZmRmPg=="; 
                        JsonResult = pdfviewer.ImportAnnotationFromXFdf(jsonObject); 
                        return Content(JsonConvert.SerializeObject(JsonResult)); 
                    } 
                    else 
                    { 
                        return this.Content(jsonObject["document"] + " is not found"); 
                    } 
                } 
            } 
  
            return Content(jsonResult); 
        } 
 
 
Also, we are facing issue on export/import Shape annotations as xfdf. We will analyze further on it and update you with more details on November 19, 2020 

Kindy try it and revert us with the complete base64 string, annotation details, PDF document and the modified sample if you are still facing the issue. These details will be helpful for us to investigate further and assist you better. 

Regards, 
Akshaya  



AA Akshaya Arivoli Syncfusion Team November 19, 2020 05:39 PM UTC

  
Hi Arthur, 

We have Confirmed that “ Import and export annotation not working properly in XFDF format” is a defect and logged the defect report for the same. The fix for the issue will be included in our upcoming  weekly nuget release on 9th  December 2020. You can track the status using the below link  
  

Regards, 
Akshaya 



AA Akshaya Arivoli Syncfusion Team December 9, 2020 04:55 PM UTC

Hi Arthur, 

The fix for the reported issue was not included in our latest weekly release. However, we will fix the same and it will be included in our 2020 Volume 4 release which is expected to be rolled out at the end of December 2020 

Regards, 
Akshaya  



AA Akshaya Arivoli Syncfusion Team December 17, 2020 12:09 PM UTC

Hi Arthur,  

Sorry for the inconvenience caused. 

The fix for the issue was not included in our Volume 4 2020 release.  However we will fix the same with high priority and it will be included in our upcoming weekly NuGet release on December 30, 2020 

Regards, 
Akshaya 



AA Akshaya Arivoli Syncfusion Team December 30, 2020 05:11 PM UTC

Hi Arthur,  

We have fixed the reported issue and the fix was included in our latest weekly release v18.4.0.32. Kindly upgrade to that version to get the issue resolved. 


From Volume 4  release  (v18.4.0.30), the Syncfusion Blazor UI components are separately available in individual NuGet packages. The NuGet packages are segregated based on the component usage and its namespace. Kindly refer the below documentation link. 




Regards, 
Akshaya  




VG Vivek Gupta December 31, 2020 06:21 AM UTC

Thank you for the information.

We have a requiremeent to export the xfdf annotation to database. So please suggest how can we get the xfdf file as object(string) to save it in db and while importing we can use that saved file into the pdf viewer. It would be very helpful if you can share a sample code for the said requirement.


Regards


AA Akshaya Arivoli Syncfusion Team January 4, 2021 11:27 AM UTC

Hi Vivek, 

Thank you for your update. 

Currently, we do not have support to export the annotations as object in XFDF format. We will analyze further on this and provide the details on January 6, 2021. 

Regards, 
Akshaya   



AA Akshaya Arivoli Syncfusion Team January 11, 2021 12:24 PM UTC

Hi Vivek,  

We have confirmed that “Support to export the annotations as object in xfdf format” is a feature and logged the feature request for the same. The implementation for the feature will be included in our upcoming weekly NuGet release on February 3, 2021. You can track the status using the below link   


Regards,  
Akshaya 


VS Vasugi Sivajothi Syncfusion Team February 3, 2021 03:45 PM UTC

Hi Vivek, 
 
We have  provided the  “support to import and export the annotation using stream” and the implementation was included in our latest weekly nuget release v18.4.0.41. Kindly upgrade to that version to get the implementations.  We can store the exported annotation stream data in database and import the same.  Please find the code snippet below.  
 
Blazor Sever 
Service side package    
ASP.NET Core :    
     
ASP.NET MVC:    
   
CDN links:   
   
 
Code Snippet 
 
 
<button @onclick="ExportXFDF">ExportXFDF</button> 
<button @onclick="ImportXFDF">ImportXFDF</button> 
 
<SfPdfViewerServer @ref="@PDFViewer" /> 
 
@code{ 
    public SfPdfViewerServer PDFViewer { get; set; } 
    Stream annotationData; 
 
    public async void ExportXFDF() 
    { 
        annotationData = await PDFViewer.ExportAnnotationAsStream(AnnotationDataFormat.Xfdf); 
    } 
 
    public async void ImportXFDF() 
    { 
        await PDFViewer.ImportAnnotation(annotationData, AnnotationDataFormat.Xfdf); 
    } 
} 
 
 
 
Regards, 
Vasugi 
 


Marked as answer

AB Arthur Butler February 16, 2021 09:22 AM UTC

ImportAnnotations is still failing for me in the latest version 18.4.0.43.  See attached example - perhaps I am doing something wrong.

1. Put a file named PDF_Succinctly.pdf in c:\temp

2. Run the PDFViewer server component in the project VNet.TestBank.Api.sln.

3. Run the Blazor WebAssembly app in Hosted Sample/SyncfusionBlazorApp89.sln.  Select the PDF Viewer control.

4. Add a simple annotation such as a text highlight.  ExportAnnotations() in the server app gets called and the data gets stored in the global _annotations variable.

5. Select "Syncfusion Blazor Samples" from the left menu and then "PDF Viewer" to reload the document.  This will call ImportAnnotations() in the server app and it should restore the annotations saved in step 4.  However, nothing is restored.

Attachment: SfPdfViewer.Blazor_7000620f.zip


VS Vasugi Sivajothi Syncfusion Team February 17, 2021 11:44 AM UTC

Hi Arthur, 
 
Thanks for the update. 
 
We were able to reproduce the reported issue with the provided sample not with our simple sample. So, we will analyze further on this and update you with more details on February 19, 2021. 
 
 
Regards, 
Vasugi 



VS Vasugi Sivajothi Syncfusion Team February 19, 2021 05:42 PM UTC

Hi Arthur, 
 
We have checked the issue with your sample, please modify the below changes in importAnnotation method in your sample to resolve the reported issue. And please refer to the below modified sample, 
 
byte[] bytes = System.IO.File.ReadAllBytes(documentPath); 
jsonObject["importedData"] = Convert.ToBase64String(bytes); 
JsonResult = pdfviewer.ExportAnnotation(jsonObject); 
return Content(JsonConvert.SerializeObject(JsonResult)); 
 
 
Please let us know if you have any concerns about this, 
 
Regards, 
Vasugi 



AB Arthur Butler February 23, 2021 10:12 PM UTC

Thank you!


TN thuan nguyen March 4, 2021 03:24 AM UTC

I add a stamp with a flag image _pdf_viewer.AddStamp(new FlagStamp(), _pdf_viewer.PageNumber, tappedPoint);
 and export  annotation:  Stream fdfStreamToSave = _pdf_viewer.ExportAnnotations(AnnotationDataFormat.XFdf);
I see that when add the flag in page number >2 then export annotation not include the flag. Please help.


TN thuan nguyen March 4, 2021 03:25 AM UTC

This happen in syncfusion xamarin. ios and android


MK Muralitharan Karikalan Syncfusion Team March 5, 2021 02:06 PM UTC

 
Hi  Thuan,  
  
Greetings from Syncfusion support,  
  
We were unable to reproduce the issue, “Stamp annotation is not exported properly” and it is working as expected. Could you please try the below-provided sample and let us know whether we have missed out anything while replicating the issue.  
   
Please find the sample in the below link, which we have used to reproduce the issue in our end  
 
  
Kindly share the following details to analyze more on this issue and assist you with the better solution    
1.Simple sample/ modify the above sample to reproduce the issue.   
2.Replication video/procedure to reproduce the issue.  
3.PDF document   
4.Details about how you are exporting and importing the stamp annotation  
  
Regards,  
Muralitharan K  
 


Loader.
Up arrow icon