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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Generate PDF document from layout eg (Stacklayout, relativelayout, grid layout)

Thread ID:

Created:

Updated:

Platform:

Replies:

141279 Dec 4,2018 07:09 AM UTC Mar 1,2019 06:41 AM UTC Xamarin.Forms 5
loading
Tags: PDF
Ofentse
Asked On December 4, 2018 07:09 AM UTC

I am working on a xamarin forms project, and one of my requirements is to generate a pdf document from my layout, for example stacklayout. I want to print the controls inside my stacklayout into pdf document. If it is also possible to print my content page, that will also be helpful.

I attached my screenshot for more clarity on what i want to achieve.


Thank you

Attachment: screenshot_5854686e.zip

Dilli Babu Nandha Gopal [Syncfusion]
Replied On December 6, 2018 12:57 PM UTC

Hi Ofentse 
 
Essential PDF doesn’t have a direct support for converting XAML element into PDF document. So, we have created a workaround sample for converting the XAML page to PDF in Xamarin platform. In this workaround sample, we will capture the XAML page screen by using dependency services and draw the captured screen image to the PDF document by using PdfBitmap object. The resultant PDF document will be preserved as a raster image and not searchable (not Vector quantity). Please refer the attached sample for more details.  
 
Regards, 
Dilli babu 


Ofentse
Replied On December 7, 2018 08:25 PM UTC

Thank you for your response. but just one more question, how to i compute Pagination. Say i draw three images sequentially on the pdf page,
If the last image for example wont fit in the remaining space on a page, how do i move it to the next page, 

Karthik Krishnaraj [Syncfusion]
Replied On December 10, 2018 09:07 AM UTC

Hi Ofentse,  
  
Thank you for your update.  
  
We can paginate to the next page, if the image is not fit the remaining space of the page. It can be performed by setting the PdfLayoutBreakType as FitElement and PdfLayoutType as Paginate in PdfLayoutFormat.  
 
Please find the code snippet below,  
  
Code snippet:  
  
//Create PdfImage object from image stream  
PdfImage image = PdfImage.FromStream(imageStream);  
  
//Create PdfLayoutFormat object  
PdfLayoutFormat format = new PdfLayoutFormat();  
format.Layout = PdfLayoutType.Paginate;  
format.Break = PdfLayoutBreakType.FitElement;  
  
PdfLayoutResult result = null;  
  
//Draw the image using PdfLayoutFromat  
result= image.Draw(page, new PointF(10, 10), format);  
  
for (int i = 0; i < 10; i++)  
{  
//continuously draw the Image.  
result= image.Draw(result.Page, new PointF(result.Bounds.X,result.Bounds.Bottom+10), format);  
}  
  
 
  
  
Using the above code snippet, we can achieve your requirement. Please let us know if you need further assistance in this.  
 
Regards, 
Karthik. 


ibrahim
Replied On February 27, 2019 01:03 PM UTC


Surya Kumar [Syncfusion]
Replied On March 1, 2019 06:41 AM UTC

Hi Ibrahim, 

We suspect that you are facing the runtime permission issue in Android. 

From Android version 6.0(Marshamallow) and above, we need to grant runtime permission to save the PDF in the device. More details about this can be found in this link.  

We have modified the sample to generate runtime permission and attached the same below. So could you please try the same and let us know if it works. 

If you are facing any other issue. Please specify the exact issue with exception details, so that we can help you with that. 

Regards, 
Surya Kumar  


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;