Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Code for saving UIView as PDF in Xamarin.iOS

$
0
0

I am trying to use below code for saving UI View as PDF as in the link: https://forums.xamarin.com/discussion/129636/create-pdf-from-uiview#latest

partial void BtnTest_TouchUpInside(UIButton sender)
        {
            createPDFFromView(this.View);

        }
        public static NSMutableData createPDFFromView(UIView view)
        {

            NSMutableData pdfData = new NSMutableData();

            try
            {
                // Points the pdf converter to the mutable data object and to the UIView to be converted

                UIGraphics.BeginPDFContext(pdfData, view.Bounds, null);
                UIGraphics.BeginPDFPage(view.Bounds, null);

                var pdfContext = UIGraphics.GetCurrentContext();

                view.Layer.RenderInContext(pdfContext);

                UIGraphics.EndPDFContent();
            }
            catch (Exception ex)
            {

            }
            return pdfData;
        }

Is this the complete code or I need to additional code to consume NSMutabledata returned by createPDFFromView method here?


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>