HOWTO: add and remove a page to a PDF-Document and display it with SfPdfViewer using MVVM concept

Hi,

I use the SyncFusion SfPdfViewer-Control in my Xamarin.Forms Projects (targeting Android, iOS and UWP platforms).
All I want to do is add and remove Images to a PDF-Document and display it with the PDFViewer-Control.

I use MVVM concept so I only placed the control in a Xamarin.Forms Page with a databinding to my ViewModel-Property PdfDocumentStream.
<syncfusion:SfPdfViewer Grid.Row="0" 
  x:Name="pdfViewerControl" 
  InputFileStream="{Binding PdfDocumentStream}" 
  PageNumber="{Binding Path=PageNumber}"
  MinimumHeightRequest="200" 
  PageViewMode="PageByPage" 
  WidthRequest="100" 
  BookmarkNavigationEnabled="False" 
  BookmarkPaneVisible="False" 
  EnableFormFilling="False" 
  EnableDocumentLinkAnnotation="False" 
  EnableScrollHead="False" 
  IsTextSearchEnabled="False" 
  IsTextSelectionEnabled="False"
  ShowPageNumber="False"
  />
  
So nothing magic.

In the ViewModel I have 2 methods to add and remove an image to the PdfDocumentStream using SyncFusions PdfLoadedDocument and PdfDocument classes.
These methods create a new MemoryStream and assign this one to the PdfDocumentStream property in my ViewModel.

My main problem is that if I there is only 1 page left in the document and I want to remove this page, this is not shown from the SfPdfViewer-Control.
I tried setting my PdfDocumentStream-property to null, but this did not work.

Can you provide a working MVVM sample for adding and removing pages from a PDF?

Kind Regards






  


3 Replies

JP Jhansi Priya Ramesh Syncfusion Team February 20, 2020 06:33 PM UTC

Hi Horst, 

Thank you for contacting Syncfusion support. 

We have created a simple sample to add/remove pages from PDF document in MVVM. Please find the sample from the below link, 



When only single page is left in the document, we suggest unloading the Pdfviewer instead of removing the pages from PDF document. Kindly try the above solution and please let us know if any further assistance required. 

Regards, 
Jhansi Priya Ramesh 



HH Horst Hagmüller February 21, 2020 09:15 AM UTC

Hi, 

Thanks for the sample, but this sample crashes when the Add button is pressed several times in quick succession!

See my incident I already reported: https://www.syncfusion.com/support/directtrac/incidents/266643

Also when all pages from the original PDF-Document are removed and then you add a new page the document has 2 pages instead of 1!
Can you provide a full working sample, please?


Kind Regards



AV Ashokkumar Viswanathan Syncfusion Team February 24, 2020 12:07 PM UTC

Hi Horst,   
  
Application crashes by adding and removing pages in SfPdfViewer  
We have updated the details in the incident 266643.  Please have a follow up with the incident 266643 for further updates.     
  
2 pages added instead of 1  
We have modified the sample as per your request. Please find the sample link below,   
 
  
Please let us know if you need any further assistance with this. 
 
Regards, 
Ashok Kumar Viswanathan. 


Loader.
Up arrow icon