iOS Guides | Samples

MonoTouch.UIKit.UIGraphicsPdfRenderer Class

A UIGraphicsRenderer that creates PDFs.

See Also: UIGraphicsPdfRenderer

Syntax

[MonoTouch.Foundation.Register("UIGraphicsPDFRenderer", true)]
[MonoTouch.ObjCRuntime.Introduced(MonoTouch.ObjCRuntime.PlatformName.iOS, 10, 0, MonoTouch.ObjCRuntime.PlatformArchitecture.None, null)]
[MonoTouch.ObjCRuntime.Introduced(MonoTouch.ObjCRuntime.PlatformName.TvOS, 10, 0, MonoTouch.ObjCRuntime.PlatformArchitecture.None, null)]
public class UIGraphicsPdfRenderer : UIGraphicsRenderer

Remarks

Introduced in iOS 10, the UIGraphicsPdfRenderer allows custom drawing code that utilitizes wide color and outputs its results in PDF format.

The common way to use UIGraphicsPdfRenderer is to call UIGraphicsPdfRender.CreatePdf, which takes an Action as an argument, allowing the developer to either pass in drawing code or use a lambda expression:

C# Example

var r = new UIGraphicsImageRenderer(new CGSize(100, 100));

var img = r.CreateImage((UIGraphicsImageRendererContext ctxt) => 
    {
        var superRed = UIColor.FromDisplayP3(1.358f, -0.074f, -0.012f, 1.0f);
        superRed.SetFill();

        UIColor.Black.SetStroke();

        var path = new UIBezierPath();
        path.MoveTo(new CGPoint(10,10));
        path.AddLineTo(new CGPoint(90, 10));
        path.AddLineTo(new CGPoint(45, 90));
        path.ClosePath();
        path.Stroke();
        path.Fill();
    });

The new drawing method is still based on manipulating the state of a "current context" but instead of a CGContext it is now a subclass of UIGraphicsRendererContext (either UIGraphicsImageRendererContext or UIGraphicsPDFRendererContext). If necessary, developers can retrieve the current context as a CGContext using UIGraphicsRenderer.GetContext.

Related content

Requirements

Namespace: MonoTouch.UIKit
Assembly: monotouch (in monotouch.dll)
Assembly Versions: 0.0.0.0

The members of MonoTouch.UIKit.UIGraphicsPdfRenderer are listed below.

See Also: UIGraphicsRenderer

Public Constructors

Default constructor, initializes a new instance of this class.
A constructor that initializes the object from the data stored in the unarchiver object.
Constructor to call on derived classes to skip initialization and merely allocate the object.
A constructor used when creating managed representations of unmanaged objects; Called by the runtime.

Public Properties

[read-only]
override
ClassHandleIntPtr. The handle for this class.

Public Methods

CreatePdf(Action<UIGraphicsPdfRendererContext>) : NSData
Returns the PDF as described in
WritePdf(NSUrl, Action<UIGraphicsPdfRendererContext>, out NSError) : Boolean
Renders the PDF described in to .