In iphone development, is it possible to evaluate a javascript string using a webView in which a PDF is loaded? - iphone

I have loaded a PDF into UIWebView. Now i want to search for strings in that pdf. So I used a string which contains JS steps(used to highlight that specific string) and evaluated it with the webView object like this. But no result was obtained .It was as if nothing had been done.
Dont the JS evaluation work on a pdf loaded into a webView? Is there anyother way to search for a string in a PDF loaded into webView?

Even if you could evaluate JS against a webview that is currently displaying a pdf, the pdf render has no exposed or documented APIs. If you have code that works on HTML then it is not working because the PDF is not exposing an HTML like dom. If you have code that works in the acrobat plugin on a desktop then it won't work because the phone uses a derivative of Apple's Webkit PDF plugin which does not export the same API as Acrobat (as far as I know it exports no API, and if it does it is undocumented). In any event, regardless of why you think your code should work, it won't.
If you want to find a string in a pdf you are going to need to write code to parse the PDF and find that string, and even then you will not be able to highlight the specific string in the webview based renderer.
If you want this sort of functionality you should should use Quartz to directly render your PDFs onto views. Apple provides documentation for how to do that.

Related

Template-based PDF renderer for flutter web

I am writing a Flutter web application that needs to have a customizable template for printing reports: inside the template there will be some placeholders that must be replaced with data at the moment of printing. The "printing" itself will be done by having the user download and open a PDF file, then print it through the browser, the OS or anything else, but that's beyond the scope, at the moment.
The default template would be something like this, where <BUYER_DATA> and <TRANSACTION_DATA> will be replaced with the data of the transaction the user is printing, along with some other "technical" tags (i.e., the page number and the pages count):
Header with site name
727 Chester Rd New Trafford, Stretford
Manchester
<BUYER_DATA>
01-12-2022 14:40
<TRANSACTION_DATA>
AppName - TM 2022
Page <PAGE_NO> of <PAGES_COUNT>
The user is allowed to edit this template in any aspect (boldness, size, colors, etc), provided that the tags related to the data are not removed from it.
So, to achieve this, I added a WYSIWYG html editor inside a page in order to save the template as an HTML-formatted string. And this works fine: only then I realized that the well-known flutter printing library doesn't support conversion from HTML directly to PDF on web, and all my plans began to crumble.
I then tried to discover if there's some other way to achieve the same by replacing the HTML template with something else, like markdown, but it seems that there's nothing that could help me.
The question is: anybody knows of a package capable of converting from HTML, markdown or such, directly into PDF?
I just need to know so I can stop googling around and decide to write my own parser for the HTML and convert it into a series of Widgets of the before-mentioned printing package.

is it possible to view a question with a browser before importing it to Moodle?

I have created a XML file using R-exams out of just a single exercise to be imported to Moodle. I would like to view it before uploading it in the Moodle question bank. I tried to open it with Firefox and I can see some code but not the output and a message appear saying that the XML file does not seem to have a style sheet associated to it. Is there a way to find this style sheet and to see how the question comes out just using a browser like Firefox or Chrome?
To emulate how the R/exams exercises are converted to HTML by exams2moodle() and how Moodle displays mathematical content, it's best to use
exams2html(..., converter = "pandoc-mathjax")
In recent versions of R/exams the resulting HTML file then automatically loads the MathJax Javascript that enables correct rendering of mathematical content in all modern browsers (including Google Chrome). See also http://www.R-exams.org/tutorials/math/ for some general advice about math in HTML.
To the best of my knowledge there is no tool that would quickly display Moodle XML files in such a way that you can easily assess them.

swift open urls from pdf file

I'm working with pdf files that have urls inside it, and it's presented like images, I want the pdf to be presented like html file, so when the user clicks on a url inside the document it opens the url using safari
I'm using this library to read pdf files
https://github.com/Alua-Kinzhebayeva/iOS-PDF-Reader
and I have no problem to migrate to another library if it supports what I need
From a quick look at that library, it appears it is rendering each page as an image and then displaying it. It would probably be pretty tough to use that library to allow clickable links.
I don't have any experience with 3rd party solutions but theres a couple ways to do it provided by Apple.
You could show the pdf in a WKWebView or a QLPreviewController. Both have delegate methods that are called when a link is clicked.

Getting images by parsing constantly changing HTML

I'm in the process of developing an iOS app that retrieves images from a URL (http://m.9gag.com). It so happens that the HTML for the URL is in constant change and whenever I have a working code, the site's style changes.
Is there any way I could pull those images from the HTML without having to worry about webpage changes? There is no public API at the moment so that's sadly not an option.
I look forward to hearing some options.
Also, if the page is set so that when the user scrolls to the bottom, it loads more content, how can I get more html to load based on how far down in the HTML parsing I've got? I'm not using a webview, I just need to update the HTML I initially retrieved.
It seems that the simplest way in your case - use regular expression (for example http://[A-Za-z0-9_/\.]*\.jpg) to extract URLs and keep track of already pulled images.

What is the most elegant way to view a multipage PDF in iOS application?

I am stuck in a predicament whereby I hope someone can help me.
I am consuming a web service that returns a multi page PDF document as a Base64 payload. I want to be able to view the PDF on a page by page basis. For example I get the following string back in a long Base 64 encoded form within image tags :
<image>JVBERi0xLjMNCiXi48/TDQoxIDAgb2JqDQo8PA0KL01vZER........</image>
I am not wanting to use a UIWebView to view the fax but a simple very basic PDF viewer with pagination. I know there are some libraries like Fast PDF Kit but that would not work because they show the logo and the license is a little pricey.
I am a PDF newbie so if someone can show by a small example I would truly appreciate that.
I'm not sure why you don't want to use UIWebView since it probably does everything you need. PDF parsing guide from Apple will show you how to implement this by hand:
http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_pdf_scan/dq_pdf_scan.html