Code for saving UIView as PDF in Xamarin.iOS

ranju_ranju_ Member ✭✭

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?

Tagged:

Best Answer

Answers

Sign In or Register to comment.