Well the good news is that I figured it out. The problem was I was using drawInContext, while renderInContext is the one to use....
Code:
// PDF page drawing expects a Lower-Left coordinate system, so we flip the coordinate system
// before we start drawing.
CGContextTranslateCTM(pdfContext, 0.0, pageRect.size.height);
CGContextScaleCTM(pdfContext, 1.0, -1.0);
// webView is my UIWebView component
[webView.layer renderInContext:pdfContext];
The bad news is that this just produces a screen sized bitmap in the pdf, so not that useful.
Quote:
Originally Posted by pmattf
Does anybody know how to take the current contents of a UIWebView and save them into a pdf file?
Using this tutorial as a starting point, I took out everything between CGContextBeginPage and CGContextEndPage.
I first tried
Code:
// webView is my passed in UIWebView *
[webView.layer drawInContext:pdfContext];
The documentation says that UIView's have a layer property of type CALayer *, and CALayer has a drawInContext method. Yet I get a warning that there is no drawInContext method here, and nothing happens when I run it.
Next I tried:
Code:
UIGraphicsPushContext(pdfContext);
[webView setNeedsDisplay];
UIGraphicsPopContext();
Which I think may be closer to the right track, but that still generates an empty pdf file.
Any help would be appreciated.
|