UIWebView - scaling multipage PDF ToFit - iphone

I have a multipage pdf (~14 pages) that I want to load into a UIWebView.
Trouble is that when I activate scalesPageToFit
- The first page is zoomed to ~50%
- The page is centered
- I cannot manually move/scroll the page closer to the page-boundaries
Am using Interface builder.
Any ideas how I can solve this mystery?
Thanks

Try Apple's QuickLook for better PDF display.
Check out this example code: https://github.com/steipete/PSPDFKit-Demo/blob/master/Examples/PSPDFKitExample/PSPDFQuickLookViewController.m
(It's part of http://PSPDFKit.com)

Related

UIWebView best way to load an XML

I want to display Xml file on UIWebView, what i am doing is this:
[m_WebView loadData:[NSData dataWithContentsOfURL:theURL] MIMEType:nil textEncodingName:nil baseURL:nil];
But this is not displaying it properly and i have no control over the color components of it, any suggestions!
You need to use your own style sheet to enable control on component, else web view loads xml as its default format.
Check out following tutorial on css with UIWebView - http://mentormate.com/blog/iphone-uiwebview-class-local-css-javascript-resources/, http://iphoneincubator.com/blog/windows-views/uiwebview-revisited

Using HTML pages in UIWebView, strange issues with relative page images but links work

So I'm creating an app which basically is a UIWebView that loads an HTML page, which should have images on it. The HTML page is loading fine (confirmed with a little text on the page), but then I have this code in it:
<img src="images/image_1.png">
test
Check this out:
The tag has a broken image link
But, when I tap on the link, the
image loads!
How is this happening? What kind of solution is there?
I have the images in a subfolder of resources, which I added by "Create Folder References."
Help? A note: This is on iPad, using 4.2. But that shouldn't matter, right Apple? (Also, changing it to xml <img /> type tag doesn't do anything)
The image was way too big - over 2500px wide. Resizing to 1024px fixed it. Thanks Jose Vega.
Also, Automator is a gift from the Gods when it comes to batch operations.

Programmatically Generate PDF from HTML on iPhone

I am looking for a way to programmatically (in obj-c) generate a PDF file from a local html file. I am dynamically generating the html from user inputs, I need to create the PDF and send it to the user (via email). I am having difficulty with the PDF generation portion.
I have the code to create a PDF using CGPDFContextCreateWithURL but I am struggling with drawing the page using quartz.
I have searched extensively on SO as well as the internet to no avail.
Any help is much appreciated!
To generate a pdf from an HTML, you need to render the html into a web view, and take snapshots of the web view, and render them into an image context.
The tutorial might be helpful:
http://www.ioslearner.com/convert-html-uiwebview-pdf-iphone-ipad/
I've written a little piece of code that takes an NSAttributedString from DTCoreText, and renders it into a paged PDF file. You can find it on my GitHub Repository. It won't render images or complex html, but it should serve for most uses. Plus, if you're familiar with CoreText, you can extend my PDF frame setter to generate these items.
So what it does now: Give it an HTML string, and it will use DTCoreText to generate an NSAttributedString, then render that into a PDF. It hands back the location that it saved the PDF file in the app's Documents folder.
Why not use a WebService, send the HTML page to this and retrieve the PDF-file ?
That way you can use iTextSharp and C#, and you're done in about 2 minutes.
Plus (if you're evil) you can store and see all the data on your server.
I haven't tried this myself so i have nothing to offer concrete but I'd have to imagine there has to be an easy way to do this on iPhone due to the imaging model. I'd look deeper into the documentation.
As to pushing back with the client that is up to you but there are probably multiple reasons for wanting to keep everything local. Frankly I would not be pleased at all to here from somebody I hired that he couldn't manage this particular task. So think long and hard about this push back. Oh even if you do push back a webserver is a poor choice. I'd go back a step further and investgate why you need something in HTML in the first place.
I've never tried this so I have no idea if it'll work, but how about loading the HTML into a UIWebView, and then make the view draw itself into a PDF context? E.g.
UIWebView *webview = [[UIWebView alloc] initWithFrame:CGRectMake(...)];
[webview loadHTMLString:html baseURL:...];
Then:
- (void)webViewDidFinishLoad:(UIWebView *)webview {
CGPDFContextRef pdfContext = CGPDFContextCreateWithURL(...);
[webview.layer drawInContext:pdfContext];
...
}
I made it by following this SO: https://stackoverflow.com/a/13342906/448717
In order to maintain the same content's proportions I had to multiply the size of the WKWebView 1.25 times the printableRect's size set for the UIPrinterRenderer, as the screen points differs from the PostScript's... I guess.

Updating UIWebView off screen?

I'm trying to get a UIImage of a UIWebView, I can do this fine using renderInContext:. However before I generate the image I would like to update the UIWebView with some HTML code, the trick is the UIWebView is hidden. Right now, I can not get the updated version of the web view to render in the UIImage, just the old one.
Are you waiting until the UIWebView re-renders before querying it again? Loading HTML into a UIWebView does not immediately update the view. You need to wait for webViewDidFinishLoad:. This is true even if the HTML is a simple string with no external references.

Displaying html in a table view cell

I am working a rss reader app for iphone . What are my options for displaying entry summary in rss feed ( which could be html) in a tableviewcell without compromising scroll performance .
I dont control the feed so html in summary section is out of my control .
I am thinking of uiwebview would be my last option ( so rss feeds have images and stuff in there, unfortunately ) . I was thinking if there was a way to extract summary text from html.
You can use a WebKit view, UIWebView to present the feed and add it a subview to the UITableViewCell.
You need to worry about the cell height and making the UIWebView non-scrollable.
I recently saw a presentation on Three20 (http://groups.google.com/group/three20/) that included a few things that might help you.
This is the specific thing I'm referring to: http://mattvague.com/three20-custom-cells-iphone-tutorial
If anyone is interested I just made a new up-to-date version of my custom cells tutorial, check it out at http://mattvague.com/three20-tttableitem-tutorial
Cheers!