Is there a way to programmatically scroll to a PDF page within a UIWebView?

前端 未结 5 739
野的像风
野的像风 2020-12-08 23:49

It is possible to use JavaScript to set the pixel y-offset of a UIWebView, e.g.:

[webView stringByEvaluatingJavaScriptFromString:[NSString strin         


        
相关标签:
5条回答
  • 2020-12-09 00:24

    I think that you'll have to load and display the PDF yourself using the PDF APIs rather than UIWebView. Here is an possible idea of how to simulate snapping scrolling to rectangular grid boundaries which may help you make the experience more like a UIWebView for your users.

    iPhone sdk Cocoa Touch - Pass touches down from parent UIView to child UIScrollview

    0 讨论(0)
  • 2020-12-09 00:35

    So this post has been open for quite a while now but since it's the first entry on a Google search for "scroll pdf uiwebview" I thought I'd provide my take at this for future readers.

    You can indeed scroll to a particular page in a PDF document using nothing but pure Java Script. I've posted sample code on our blog (http://apptech.next-munich.com/2011/02/pdf-in-uiwebview.html) but here's a short summary of what you need to do:

    1. Use the window.outerHeight DOM property to find the total height of the rendered PDF document.
    2. Use the window.innerHeight DOM property to find the height of the browser window in browser coordinates.
    3. Jump to the page using the window.scrollTo(x, y) function.

    There is one catch, though, that you cannot just device the outerHeight by the number of pages and jump to what you get. Instead, you will have to multiply by the innerHeight/webView.bounds.size.height ratio.

    0 讨论(0)
  • 2020-12-09 00:38

    The uiwebview commonly used to load pdf's has it's own scrollview object that you can make calls to. try something like this:

        [webview.scrollView setContentOffset:CGPointMake(0, webview.scrollView.contentOffset.y + 100) animated:YES];    
    

    This will scroll the view for the pdf down 100 pixels. As for getting the pagenumber of the pdf, I can only imagine that javascript is what you need to take a look at. Or, If you simply know the number of pixels on each page of the pdf, then increment or decrement as necessary. :)

    0 讨论(0)
  • 2020-12-09 00:40

    I have seen your edit in question. Has anyone built a non-UIWebView-based PDF viewer (with source code)?

    See my question.

    Reading PDF files as string through iPhone application

    It has functionality to display each pdf page in an image view. user can easily change pages. But the missing points are as follows.

    • user can not make any selection - as it is not text but an image
    • user can't find any text.
    • user can not zoom ( oh yes - you can put image view in scroll view for zooming functionality )
    0 讨论(0)
  • 2020-12-09 00:42

    I have faced a similar problem, in which I had to scroll to particular page in PDF (which is displayed using UIWebView) on selection of a cell corresponding to that page in tableView (thumbnail tableview).

    So I wrote a piece of code which allows you to scroll to particular page in PDF.

    I am not using any javascript code. I am just keeping track of the zoom scale applied to the original PDF page each time and calculating the updated offset required to scroll to each page. So, this works even if the PDF is in zoomed state.

    You can find the code here.

    0 讨论(0)
提交回复
热议问题