How to convert xaml to pdf for a Scrollview

I was going through the following link:

https://www.syncfusion.com/kb/10697/how-to-convert-xaml-to-pdf-in-xamarin-using-c

This code works fine as long as what I need from the xaml fits in the screen without scrolling. But what if all my elements are in a ScrollView and I would like all the xaml elements to be saved in my pdf. 

I have around 50 entry fields on one of my Pages and this View is scrollable so I can go up and down to go through these fields. How can I get all these 50 fields onto a pdf that scrolls? Or save the fields in two pdf pages instead of one, etc.

Thank you,
Madhu

11 Replies 1 reply marked as answer

SL Sowmiya Loganathan Syncfusion Team June 12, 2020 02:01 PM UTC

Hi Madhu,  

Thank you for contacting Syncfusion support.  

Currently we are trying to create sample to achieve your requirement. We will update the further details on June 16, 2020.  

Regards, 
Sowmiya Loganathan 



SL Sowmiya Loganathan Syncfusion Team June 16, 2020 11:56 AM UTC

Hi Madhu,   
  
Thank you for your patience.   
  
Please find the below forum link to convert all the contents in the scroll view to PDF in Xamarin Forms (Android and iOS),  
  
Regards,  
Sowmiya Loganathan  
 


Marked as answer

MG Madhu Ganesh June 17, 2020 07:08 AM UTC

I tried out the code in the Xamarin forums link and was able to get it to work but the fields are all squashed up together and am unable to read any text in the fields in the resulting pdf. It is trying to fit all 50 fields on an A4 size pdf page and that makes the text unreadable. Is there any way to fix that by either having pdf page length variable, i.e., same length as the scrollable view? Or can the fields be split into separate pdf pages?

Thanks

Attachment: AssailantInfo_bae33813.zip


SL Sowmiya Loganathan Syncfusion Team June 18, 2020 12:17 PM UTC

Hi Madhu,   
  
We glad to know that the provided solution works fine.   
  
We can able to increase the page size (as like the image size) by setting the document size using PageSettings property of PDF document. Please refer the below code snippet,   
  
//Creates a new PDF document  
PdfDocument document = new PdfDocument();  
  
//Set the page size   
document.PageSettings.Size = new SizeF(image.Width, image.Height);  
  
You can use the above code snippet or set the custom page size when you add the page to PDF document.   
 
Please try the above solution in your end and let us know the result.   
 
Regards,  
Sowmiya Loganathan  
 



LS Lovedeep Singh December 6, 2020 04:13 PM UTC

How did you able to do that in iOS. Can you give me an idea for the same. Stuck since longtime.
I am doing like this.
var view = UIApplication.SharedApplication.KeyWindow.RootViewController.View.Subviews.FirstOrDefault().Subviews.FirstOrDefault();
                UIScrollView scroll = null;

                foreach (object subView in view.Subviews)
                {
                    if (subView is UIScrollView)
                    {
                        scroll = (UIScrollView)subView;
                    }
                }

                UIGraphics.BeginImageContext(scroll.ContentSize);

                CGPoint savedContentOffset = scroll.ContentOffset;
                CGRect savedFrame = scroll.Frame;
                scroll.ContentOffset = CGPoint.Empty;
                scroll.Frame = new CGRect(0, 0, scroll.ContentSize.Width, scroll.ContentSize.Height);
                scroll.Layer.RenderInContext(UIGraphics.GetCurrentContext());

                var image = UIGraphics.GetImageFromCurrentImageContext();

                scroll.ContentOffset = savedContentOffset;
                scroll.Frame = savedFrame;
                UIGraphics.EndImageContext();

                using (var imageData = image.AsJPEG(100))
                {
                    var bytes = new byte[imageData.Length];
                    System.Runtime.InteropServices.Marshal.Copy(imageData.Bytes, bytes, 0, Convert.ToInt32(imageData.Length));
                    return bytes;
                }

It gives null scroll. Please help


SL Sowmiya Loganathan Syncfusion Team December 7, 2020 12:49 PM UTC

Hi Lovedeep,   
  
We have analyzed the reported issue “Scroll is null while convert XAML to PDF for a ScrollView” and currently we are checking it in iOS. We will update the further details on December 09, 2020.   
  
Regards,  
Sowmiya Loganathan 



GK Gowthamraj Kumar Syncfusion Team December 9, 2020 03:47 PM UTC

Hi Lovedeep,    
 
Thank you for your patience. 
   
We are still checking on this reported issue “Scroll is null while convert XAML to PDF for a ScrollView” in iOS. We will update the further details on December 11th, 2020.    
   
Regards,   
Gowthamraj K 



LS Lovedeep Singh December 10, 2020 07:25 AM UTC

Hi, Thanks for the update. Waiting for the same


GK Gowthamraj Kumar Syncfusion Team December 11, 2020 03:24 PM UTC

Hi Lovedeep, 
 
We are facing an problem while running this code in IOS machine and currently, we are checking and resolving the issue and we will update the further details on December 15th 2020 without any delay.  
 
Regards, 
Gowthamraj K 



GK Gowthamraj Kumar Syncfusion Team December 15, 2020 05:34 PM UTC

Hi Lovedeep, 
 
Thank you for your update. 
 
We have checked the sample code in our mac machine, it working properly. We have attached the sample for your reference. Kindly please try the below sample in your end and let us know the result. 
 
If still your facing an same issue, kindly please share the Mac machine configuration details, modified sample to check the issue in our end. So, that it will be helpful for us to analyze and assist you further on this. 

Regards, 
Gowthamraj K 



PK Prakash Kandel August 3, 2021 12:00 PM UTC

@Madhu Ganesh can you please send your github project how you done in android project


Loader.
Up arrow icon