Is there any way to get the content of a UIWebView
and convert it to a PDF or PNG file? I'd like to get similar output to that available on the Mac by selecting the PDF button when printing from Safari, for example. I'm assuming this isn't possible/built in yet, but hopefully I'll be surprised and find a way to get the content from a webview to a file.
Thanks!
You can use the following category on UIView to create a PDF file:
Bad news: UIWebView does not create nice shapes and text in the PDF, but renders itself as an image into the PDF.
The code below will convert the (full) content of a UIWebView to an UIImage.
After rendering the UIImage I write it to disk as PNG to see the result.
Of course you could do with the UIImage whatever you like.
Note: make sure the UIWebView is fully loaded (UIWebViewDelegate or loading property).
@mjdth, try
fileURLWithPath:isDirectory:
instead.URLWithString
wasn't working for me either.Creating a image from a web view is simple:
Once you have the image you can save it as a PNG.
Creating PDFs is also possible in a very similar way, but only on a yet unreleased iPhone OS version.