I'm having an issue with getting the quality of my PDF when taken from a
UIWebview. 
My approach is below and the result is a very low res PDF A4 page. The
question is, what approach should I be taking to get a higher resolution out
of this view? Maybe a trick to build the view offline and make it really
large and then downsize it? Attached is a screenshot of the view which is a
combination of html, gifs, and Google Visualization Charts (javascript).
Attached is the webview and the resulting PDF.

Here's what I do
1. Load up the webview
2. Take a screenshot programmatically and the result is a UIImage
Here's the code to take a screenshot:
public static UIImage TakeScreenShot(UIView view)
{
        RectangleF canvasRect = view.Bounds;
        UIGraphics.BeginImageContextWithOptions(canvasRect.Size, false, 0.0f);
                        
        CGContext ctx = UIGraphics.GetCurrentContext();
        ctx.FillRect(canvasRect);
        view.Layer.RenderInContext(ctx);
                        
        UIImage newImage = UIGraphics.GetImageFromCurrentImageContext();
        UIGraphics.EndImageContext();
        NSData imgData = newImage.AsPNG();

        return UIImage.LoadFromData(imgData);
}

3. Create the PDF report through CGContext DrawImage by passing in the above
screenshot
Here is the code to create a PDF from a UIImage
public static NSData CreatePDFFromImage(UIImage image)
{
        RectangleF imageRect = new RectangleF (PointF.Empty, image.Size);
        NSMutableData data = new NSMutableData ();
        UIGraphics.BeginPDFContext(data, new RectangleF(-5f, 15f, 612f, 792f),
null);
        UIGraphics.BeginPDFPage();
        CGContext gctx = UIGraphics.GetCurrentContext();
        gctx.TranslateCTM(0, image.Size.Height);
        gctx.ScaleCTM(1,-1);
        gctx.DrawImage(imageRect, image.CGImage);
                        
        UIGraphics.EndPDFContent();
        return data;
}

http://monotouch.2284126.n4.nabble.com/file/n4398889/Photo_Feb_17%2C_4_25_45_PM.png
 
http://monotouch.2284126.n4.nabble.com/file/n4398889/pdf_report.png 

Thanks,

Dennis

--
View this message in context: 
http://monotouch.2284126.n4.nabble.com/UIWebView-PDF-tp4398889p4398889.html
Sent from the MonoTouch mailing list archive at Nabble.com.
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to