Saturday, April 20, 2013

UIImage to PDF.

Found this on a StackOverflow post, tweaked for sanity's sake (mine):

Link:   UIImage to PDF

Lots of work to do this weekend.  Took a minute to throw this out here.

public static byte[] CreatePDF (UIImage image)
        NSMutableData data = new NSMutableData();
        UIGraphics.BeginPDFContext(data, new RectangleF(new PointF(0,0), image.Size), null);
        UIGraphics.BeginPDFPage(new RectangleF(new PointF(0,0), image.Size), null);
        image.Draw(new RectangleF(0, 0, image.Size.Width, image.Size.Height));

        using (NSData imageData  = data)
            Byte[] myByteArray = new Byte[imageData.Length];
            System.Runtime.InteropServices.Marshal.Copy (imageData.Bytes, myByteArray, 0, Convert.ToInt32(imageData.Length));
            fs = new MemoryStream(myByteArray);
        return fs.ToArray();


No comments:

Post a Comment