Search code examples
iospdfuiwebviewkeynote

how are keynote file(.key, .key.zip) and pdf file loaded on UIWebView


After I loaded ppt on UIWebView, in

func webViewDidFinishLoad(webView: UIWebView) {
    let html = webView.stringByEvaluatingJavaScriptFromString("document.documentElement.outerHTML")
}

I got the whole HTML for the ppt file.

But after I loaded .key or .pdf, the HTML is empty! So how are them loaded on UIWebView. Anyway I could get or set the content after I loaded them like ppt?


Solution

  • When you load a PDF document using UIWebView, you see in essence an image of the pages laid out in a scroll view. There is no HTML involved.

    You ask about the "content" of the documents, but that does not really have a meaning in PDF. Think of a PDF documents as a set of instructions for drawing shapes, images and glyphs onto the screen.

    As far as PDF is concerned, there is no such thing as a word, a paragraph, a heading and so on. And therefore, there isn't really such a thing as "content" in the same way as there is in an HTML page.

    There are some libraries that try to recover structure from PDF, and the UIWebView uses one under the hood, at least to discover lines, words, paragraphs and columns, buy it is not accessible from the API, and therefore you cannot use it.