IOS creates pdf from UIWebview content

In my iOS app, I need to create a pdf from my webview content. I watched these posts: Creating a PDF file from UIWebView and https://coderchrismills.wordpress.com/2011/06/25/making-a-pdf-from-a-uiwebview/ p>

I wonder if there is an easier way to do this. For example, for my Mac project, I use this:

NSData *pdf = [[[[webView mainFrame] frameView] documentView] dataWithPDFInsideRect:[[[webView mainFrame] frameView] documentView].frame]; PDFDocument *doc = [[PDFDocument alloc] initWithData:pdf]; 

Is there an easy way to do this in iOS?

What is the best option to get high quality pdf from web content?

+7
ios pdf uiwebview
source share
2 answers

There is no method that allows this directly through the SDK, like on a Mac, but you can take a look at BNHtmlPdfKit , which allows you to save the contents of URLs, web representations, and html strings as PDF files.

For example, as follows:

 self.htmlPdfKit = [BNHtmlPdfKit saveUrlAsPdf:[NSURL URLWithString:@"http://itsbrent.net"] toFile:@"...itsbrent.pdf" pageSize:BNPageSizeA6 success:^(NSString *pdfFileName) { NSLog(@"Done"); } failure:^(NSError *err) { NSLog(@"Failure"); }]; 

It uses a custom UIPrintPageRenderer that overrides paperRect and printableRect , causing the UIPrintFormatter return pageCount, as well as render the document.

+4
source share

I found AnderCover's good answer to " Create a PDF file from UIWebView " also it does not use third-party api. To create a pdf file from webview.

I hope he helps you.

+1
source share

All Articles