How to get rid from question mark in a blue square in UIWebView? - iphone

In my iPhone application I'm parsing RSS feed to get html and keep it. Afterwards I display this html in UIWebView. The problem is that html contains urls of images, if there is network connection everything is ok, UIWebView loads and displays these images, but if there is no connection it shows text but in place of images shows frame with blue square inside
How can I get rid of it?
Thank you

Check programmatically to make sure that you have an internet connection.
See this question and its accepted answer on how to do that.
If you don't have an internet connection, then you have a couple of options. You can either:
Parse through your html, replace the <img> tags with blanks (this will completely get rid of the images and their associated blue question mark boxes.
Parse through your html, replace the src part of <img src="somewebsite"> with a reference to an image placeholder in the project bundle.
XPath is your friend when it comes to parsing html. Although if you wanted to, you could do all of this with NSSTring.

Related

How to resize an image with clickable link in README.md file?

I have been trying to add a link to one of the YouTube videos in the README.md file. So, first I took a screenshot of the video at a specific timestamp, put it in the local directory, and then used the following syntax:
[![ALT TEXT] (image/screenshot path)] (https://youtu.be/video_id "video text")
But as the size of the screenshot is a little big (as big as my laptop screen), using the above syntax takes a lot of space in the output! I don't want that. I want to control the size of the screenshot/image. How can I do that?
I found different answers on adding an image with a clickable link; resize an image in readme; but I couldn't find any answer addressesing both the issues. (Sorry if such answer already exists)
Thanks a lot in advance :)
You can include raw HTML in your Markdown document, so just use standard HTML <a> and <img> tag with width and height atttributes:
<img src="path/to/img.png" width="xxx" height="yyy">
This will render correctly on github and elsewhere.

Rendering Images inside PDF, images not being rendered in PDF Viewer 0.1.8

Please check updates as they have additional informations... Apparently located the problem in a specific pdf client but cannot close the issue with an open bounty...
I am generating a pdf using grails rendering plugin. The PDF has a couple of images inside and "some" of them are not being outputted!
I am rendering the images inline via data uris as required by the plugin. That means that all my images are something like:
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQECWAJYAAD...">
If I render them in a normal html view, I can see the images just fine!
If I render the template to a JPG/PNG with the same plugin, again the images render all fine.
If I render to PDF the images which are being retrieved by an octed-stream are broken!
Something like:
Looks like the image started to render and then something happened...
It is happening on the big-sized images, but also on the thumbnail version of same image.
Any one has some hints as why this might occur?
UPDATE
The file which does not show up is a file with mime application/octet-stream
So apparently I can retrieve the bytes from the file, but when they transmitted for PDF Rendering, the image does not appear...
Yet another update
The issue seems to be related with the PDF Viewer. Was using a Linux based PDF Viewer (PDF Viewer 0.1.8) and specific images are broken. In all other PDF Viewers I could test everything works fine.
Cannot close the issue as there is a bounty open :( Sorry that the bounty and question seems meaningless now, but you never know, someone might have an idea how to solve this even for PDF Viewer 0.1.8.
<img src="data:image/jpg;base64,/9j/4AAQSkZJRgABAQECWAJYAAD...">
works fine for me. Note the missing "e".
You can use rendering tag:
<rendering:inlineJpeg bytes="${your-image}" />
Make sure you decodeBase64() your image.

Using HTML pages in UIWebView, strange issues with relative page images but links work

So I'm creating an app which basically is a UIWebView that loads an HTML page, which should have images on it. The HTML page is loading fine (confirmed with a little text on the page), but then I have this code in it:
<img src="images/image_1.png">
test
Check this out:
The tag has a broken image link
But, when I tap on the link, the
image loads!
How is this happening? What kind of solution is there?
I have the images in a subfolder of resources, which I added by "Create Folder References."
Help? A note: This is on iPad, using 4.2. But that shouldn't matter, right Apple? (Also, changing it to xml <img /> type tag doesn't do anything)
The image was way too big - over 2500px wide. Resizing to 1024px fixed it. Thanks Jose Vega.
Also, Automator is a gift from the Gods when it comes to batch operations.

Extract image URL from HTML text

In Objective-C what is the best method to extract an image url from HTML text?
I've got a chunk of HTML text which may contain one or more images. I want to be able to get the src URL of each image.
If you don't mind limiting yourself to iOS 4, you can use the new text checking APIs. The one you want is NSTextCheckingTypeLink and the NSRegularExpression class.
This seems to be answered over here: parsing HTML on the iPhone
The second answer down has a detailed explanation, however you will just have to change the xpath expression to match your image tags.

Programmatically Generate PDF from HTML on iPhone

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.