In my app i am using UIWebView for displaying the pdf from an External url. Its get loaded perfectly. While scrolling page number is displayed inside a box. Is there any way to get the page number in code?
You can use the next code:
- (int)getActualPage
{
float scrollViewHeight = self.webView.frame.size.height;
float pageOffset = self.webView.scrollView.contentOffset.y;
return ((int)pageOffset / (int)scrollViewHeight)+1;
}
This code gives you the page number of the document when you see the full page on the UIScrollView. If you want to get the same page number that the UIWebView gives you, just change the final operation. I think that using the module you can get what you want. I know it's not the perfect solution but it's the best I got.
Related
Links from Facebook to my Mediawiki-powered website show an ugly default image for links. (The squarish image which shows a truncated "Powered by Mediawiki") pointed to by the gray arrow.)
How do I override this? I'm looking for a single image which would be the same for all pages rather than a custom image for each page. I want to avoid adding extensions if possible!
Added: #wgLogo is set and the logo file thus set does appear on the individual pages, but not on the FB link.
It seems that the secret is to set <meta property='og:image'… on every page (https://developers.facebook.com/docs/sharing/webmasters/images/).
To do so without installing extensions, add to your LocalSettings.php:
$wgHooks ['BeforePageDisplay'] [] = function (OutputPage &$out, Skin &$skin): bool {
$out->addMeta ('og:image', '(path to your image)');
return true;
};
Further reading:
https://www.mediawiki.org/wiki/Manual:Hooks/BeforePageDisplay
https://doc.wikimedia.org/mediawiki-core/master/php/classOutputPage.html#a1d667167a39be62f9988e94256508489
The PageImages extension adds the most prominent image used on the page as the OpenGraph image. The WikiSEO extension lets you set it manually (per-page or sitewide).
let me explain step by step:
Step 1 - in my app Fist of all listing screen.
Step 2 - press on any no of list, it will come detail screen and
call web service and fetch data.
Step 3 - fetch data like many types of HTML data so in my detail
screen i am using 4 UiWebView for Dynamic UiWebview in scroll.
step-4 in my app Passcode Functionality is there (And it's On).
If i am press on listing screen and it will call detail screen for particular list data load, and i am waiting till all UiWebview Load, the Passcode functionality is work properly.
What is problem let me explain in detail.
if we are just coming Detail screen and web service call and immediately press home button, now i am again launch the app and passcode screen present, After Enter my pass code succesfully i am coming in Detail screen, BUT what i see all UiWebview is not Loaded, even i have all data store in my model class.
I am doing silly mistake over here in HTML String :) .
NSString *html5 =[NSString stringWithFormat:#"<html><head></head><body style=\"background:#ffffff;\"><div style = \"font:16px;margin-top:0px;\" ><object width=\"245\" height=\"0\">%#</object></div></body></html>",objDetail.str_DealName];
Simply i am remove ViewPort and set font size in style.
In my app I am displaying a URL on my UIWebView .This webView page also consist textfields and I want to disable the autocorrect function = off for these textfields. I have tried all the methods but all in vain.
Here is my code
[webView stringByEvaluatingJavaScriptFromString: #"var field = document.getElementsByTagName('input');"
"for(var i = 0 ;i < field.length;i++){ "
"if(field[i].type == 'text'){"
"field[i].autocorrect = 'off';"
"field[i].spellcheck='off';"
"field[i].autocomplete='off';"
"field[i].value = 'hello';"
"}"
"}"];
As you can see i tried all these function (autocorrect, autocomplete and spellcheck as off) both individually and as a combination. But nothing works.
What I discover that if you are fetching an HTML page (and that you don't have access to its HTML source code) and you are trying to access it as above method then all will work fine like "textfield.value", "textfield.type" etc. but the "textfield.autocorrect = 'on' " (or off) does not work.
Because on clicking textfield of HTML page the keyboard of iPhone comes and you cant take object of HTML textfield to Objective C textfield. Hence the two options to solve this are:
Either make autocorrection as off from iPhone "Setting" menu .
Or ask who have access to this HTML page source code to put autocorrect="off" in between textfield HTML code (i.e. .html file)
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.
What im tyring to create is an application the utilizes book features like when the user drags a touch or just touches the right screen the page turns, the book im trying to create has atleats 300 pages. What i need is a starting point on how to access the text data and display it on a view. When the user changes the page the next set of text is accesed and displayed. How would i be able to model a book with so many pages?
any help is appreciated
PS: ive tried looking for simple tutorials but no luck
If you have your text data in a .txt file then you can extract it from there first of all. This post gives info on how you can do that.
Then every time you flick the page just load in an appropriate substring from the entire text. This would be best in an uneditable UITextView. It could look something like this:
int maxCharPerPage = 200;
int lastCharPreviousPage = 1000;
NSRange thisPageRange = NSMakeRange(lastCharPreviousPage+1, lastCharPreviousPage+1+maxCharPerPage);
NSString *thisPageText = [entireBookText substringWithRange:thisPageRange];
textView.text = thisPageText;
Or you could use a UILabel on top of a view but this approach isn't really what UILabel is designed for.