How to fit PDF height in UIWebView in iPhone/iPad - iphone

I have a project that uses a UIWebView to display a single page PDF file. I would like this content to fit by height (vertically). The default is only to fit width (horizontally). Is there any way to overcome this?

I ran against the same problem and couldn't find a way to do it with UIWebView. If you only want to display a single PDF-page, you can pretty much take the code from Apple's ZoomingPDFViewer Example.
I took the two classes PDFScrollView and TiledPDFView and with a little adjustment for my project, I was easily able to use it to display a single PDF page.

Related

Shrinking webpages that are shown in your UIWebviews

In my app I load some webpages in a 480*320(landscape) UIWebView. But the text is too large, well really the whole content of the page is too big.
Is there some trick that you can do to scale down the whole page in the web view so that it does not seem completely out of proportion to the rest of the app?
I'm guessing there is not and that the only way is to get the HTML of the whole page and look for Font tags and change them all to something smaller and then loading it into a UIWebView.
Thanks for any suggestions or ideas you can offer,
-Code
The UIWebView property scalesPagesToFit should work:
myYebView.scalesPagesToFit = YES;
From the UIWebView documentation:
You can also use the scalesPageToFit property to programmatically set the scale of web content the first time it is displayed in a web view. Thereafter, the user can change the scale using gestures.

Is there a clever way to figure out what size a UIWebview needs to be to hold all text

I get a page full of info from the server VIA JSON. There is a lot of info and different parts to the info, images, text, graphs etc. So i display it inside a UIScrollView so the whole page can scroll. I get some HTMl which i want to display inside a UIWebView. I have the HTML before i create the UIWebView so i can change the height of the UIWebView to contain all the text without the UIWebView itself needing to scroll. But it can vary in length each time i get a new load of data back from the server so i cant hardcore the height it needs to be.
So my question is. Given you have an NSString holding the HTML. Is there a way to calculate how high the UIWebViews frame needs to be, to contain all the HTML without having to scroll.
Hope you understand my question it is kinda long :)
Thanks,
-Code
If it's ok to resize the webview (and the parent scroll view's contentSize property) after the HTML finishes loading, you can use JavaScript to query the rendered height of the HTML and use that. See iPad - find the true height of a UIWebView
Well that would depand on the size of the text in the UIWebView. One way I can think of is to try finding out how many characters (letters) you need to fill one line in your UIWebView. Then use that number to devide your total number of characters in the NSString containing the HTML and base on that number lets call it lanes you could increase the hight of your UIWebView

how to load the pdf through programming with animation in iphone

how load a pdf into iphone and my pdf is of 200 pages then it should allow to turn the pages as we do with while reading book manually means use animation to turn a page one by one ..
Thanking you ..
Loading a large PDF and having page flipping animation isn't very simple. You can use a UIWebView like #Jim says to load the entire thing by just pointing the UIWebView's URL to the PDF but you won't get page animation. However to get full control requires that you render the PDF page by page manually to a view, and create the view's turning animation your self. Its nontrivial, and given your question you don't sound like you know enough to realistically achieve this right off.
Use UIWebView Control to load pdf files.

UIWebView With PDF

I'm displaying a PDF file using UIWebView, and I want to do 2 things:
I want to make the page fit the phone screen without the user has to double tap to do that
I want to remove the margin with gray shadow around the displayed PDF
Thanks for helping
I don't think this will help much, but I think your best option is to render the PDF to an image (of decent DPI) and show the image instead. I do this for an app, but we do that server side using ImageMagick - don't know how you might do that in obj-c. Also note that a mostly-text PDF will be much larger (filesize) when rasterized.
However, you might also try to embed the PDF in HTML page and load that HTML in the WebView - that may at least avoid the gray border/artboard.
webView.transform = CGAffineTransformScale( webView.transform, 1.25, 1.25 );
2 - Checking the Scale Pages to Fit box in IB sorted this for me
I would also like to know the answer to 1.
I guess you want to know how to display the PDF in the same way as when opening as attachment in mail, where the navigation bar only appears on a tap and the status bar also disappears?
You can also use Quartz to do it, as explained here : http://developer.apple.com/iphone/library/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_pdf/dq_pdf.html
Where has CGAFFineTransformScale been all my life?
Seriously, that is a big help. However, it worked better applying it to webView.scrollView.
Finally, is there a similar command to change the offset of the content as well as the scale?

Is there a HTML wrapper in Cocoa other then UIWebView?

I have a bunch of texts and images (taken from the content tag of a RSS feed item) that I want to display in my app. I've managed to extract them from the entire content tag with some regular expressions. But the thing is, in order for the texts to appear before all the images are loaded, I need to preload all the images, and even more, I need to reposition all the texts/images when an image is loaded, because I don't know their size at first, to position the element under them correctly.
I realized this is too much hard-work for such a simple task.
I searched for some simple HTML wrapper but I found nothing. And than I realized: hey, I can insert HTML directly into an UIWebView. But then again, I see UIWebView more like an iFrame in HTML, and by that I mean not a very flexible/fluid element. The content will be bigger than the iPhone screen height, can the UIWebView adjust to fit it's contents? I don't want the browser zoom features and all, but rather to blend in the page.
So bottom line: In order to display a bunch of texts combined with images, should I continue with my initial pain-in-the-ass method, should I use a UIWebView, or is there another simple element like the one in my dreams? :)
Thanks.
Definitely use the web view; it has hundreds of person-years of work behind it, and is realistically impossible for you to reproduce by yourself. To keep it from zooming, you can add a viewport meta tag to your HTML fragment.
...[S]hould I continue with my initial pain-in-the-ass method, should I use a UIWebView, or is there another simple element like the one in my dreams...
I'm not entirely sure what you have against UIWebView, it's a decent and fairly complex element that can support many behaviors. One of the extremely attractive properties of IB and Cocoa development is that prototyping is very quick. I think you should spend half an hour and play around with the component. Writing your own code is definitely an option, but layout engines (ie WebKit in UIWebView/Safari, or Gecko in Firefox) is a complicated task. Why reinvent the wheel?
HTH.