iphone : How to convert webpage(UIWebView) to pdf - iphone

i want to convert my webpage(displayed in UIWebView) contents in pdf file.
which can be stored at perticular directory (document dir/any user defined dir).
So later on it can be viewable to user either internet connection not available.
is there any possibilities to perform this functionality.
how can i do this...
Thanking you in advance...

An image might be your best option. See Take snapshot of view / WebView programmatically
To get the image, you'll want to use:
UIGraphicsBeginImageContext(self.bounds.size);
[theView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Then, to save to the Photos Library:
UIImageWriteToSavedPhotosAlbum(viewImage,nil,NULL,NULL);

Related

How to obtain a copied image from the pasteboard?

I have a photo editing app where I want to provide a way for the user to edit photos from the pasteboard. For example the user might copy a photo from his website in Safari and then head over to my app and choose "Open from pasteboard". Kind of like Photoshop does it.
How can I get notified or check if there is a picture or graphic (probably a UIImage) in the pasteboard? And how could I obtain that image?
I needed one for a UIImage and this snippet helped me out.
You can always extract the image out using:
UIImage *image = [UIPasteboard generalPasteboard].image;

Scaling images and save them

In my app, the user can take an image through the camera or chose one from the photo album.
(I save the photo taken with the camera in the photo album).
In both cases, I would like to save a scaled copy (640x920) of the image in the documents directory.
How can I proceed to scale and then save the resulting image?
The easiest way is with NYXImagesUtilities.
Here's the github page.
A basic example of using it.
// #import <QuartzCore/QuartzCore.h>
// #import "NYXImagesUtilities.h"
//.. path is an NSString of the documents directory + file name you want to save it to.
//.. myImage is the UIImage that you got from the user.
UIImage *scaledImage = [myImage scaleToFitSize:(CGSize){640, 920}];
[scaledImage saveToPath:path type:NYXImageTypePNG];

Load image from a stored png

How does one load or fetch an image that was saved to disk?
I wrote the image to the documents filepath using NSData and a PNG representation. How does one get this image back? UIImage.
UIImage *theImage = [UIImage imageWithContentsOfFile:filePath];
As ever, see the UIImage documentation at Apple. It is your friend.

iPhone MapView save to Photo Album

How do I save a MapView to the PhotoAlbum for later attachment to an email created within my iPhone application?
Try this:
UIGraphicsBeginImageContext(map.layer.bounds.size);
[map.layer renderInContext:UIGraphicxGetCurrentContext()];
UIImage *mapImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
And perhaps you should also double-check Google's licensing terms if they allow making and distributing screenshots of the maps.

UIImageWriteToSavedPhotosAlbum saves to wrong size and quality

I'm trying to take a screen shot of my app's current view and save it to photo album (to then be emailed or MMS'ed).
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, self, #selector(savedPhotoImage:didFinishSavingWithError:contextInfo:), nil);
This works but the resulting image apears to be larger (533x800px) and heavily compressed when I email it from the photo library.
I've tried first writing the UIImage to file and then saving to album but still get the same issue.
If I used the in-built screenshot functionality on the iPhone the view saves correctly to photo album at 320x480 but the above code appears to save a larger image for some reason?
Thanks!
I found a decent workaround, which is to essentially rewrap the UIImage as a PNG, then save the rewrapped version. Code looks something like this:
UIImage* im = [UIImage imageWithCGImage:myCGRef]; // make image from CGRef
NSData* imdata = UIImagePNGRepresentation ( im ); // get PNG representation
UIImage* im2 = [UIImage imageWithData:imdata]; // wrap UIImage around PNG representation
UIImageWriteToSavedPhotosAlbum(im2, nil, nil, nil); // save to photo album
I had that same error, on my part, that was solved when I rounded the decimal points to be the same scale as the iPhone, try it, make sure the scale is 1.0, 2.0, etc and not 3.1, that will throw it off.