Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating pdf Thumbnail in iphone

I am new to Objective-c iPhone programming. I have an application in which I display a PDF in my UIWebView successfully, but now I want to create a thumbnail of my PDF. My PDF is stored in my resource folder.

So please give me code for how I can show a thumbnail of my PDF. My code is for displaying PDF is which is taken in button function:

-(void)show:(id)sender {

    pdfView.autoresizesSubviews = NO;
    pdfView.scalesPageToFit=YES;
    pdfView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
    [pdfView setDelegate:self];

    NSString *path = [[NSBundle mainBundle] pathForResource:@"com" ofType:@"pdf"];
    NSLog(@"Path of res is%@",path);
    NSURL *url = [NSURL fileURLWithPath:path];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [pdfView loadRequest:request];
}
like image 523
Yogesh Avatar asked Apr 14 '11 05:04

Yogesh


People also ask

How do I save a PDF as an image on iPhone?

Inside the On My iPhone folder, tap Downloads. When you touch the zip file, iOS will automatically create a folder with your PDF pages saved as images. Tap the share button (a square with an arrow pointing up out of it) and hit Save Image to save each one to your camera roll.

How do I create a PDF on my iPhone?

On your iPhone:Download PDF Expert for free. Open the app and tap the blue plus sign. Select Create PDF from File. Pick the file you wish to convert and tap Create.

How do I save a PDF to my iPhone home screen?

Using “Get File Action” in the Shortcuts App In this method, you will move the PDF to the Shortcuts folder on iCloud Drive first, then create a shortcut. Open the Files app on your iPhone. Locate the PDF, touch and hold it to open the context menu, then select “Move.”


1 Answers

try the following method:

- (UIImage *)imageFromPDFWithDocumentRef:(CGPDFDocumentRef)documentRef {
    CGPDFPageRef pageRef = CGPDFDocumentGetPage(documentRef, 1);
    CGRect pageRect = CGPDFPageGetBoxRect(pageRef, kCGPDFCropBox);

    UIGraphicsBeginImageContext(pageRect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextTranslateCTM(context, CGRectGetMinX(pageRect),CGRectGetMaxY(pageRect));
    CGContextScaleCTM(context, 1, -1);  
    CGContextTranslateCTM(context, -(pageRect.origin.x), -(pageRect.origin.y));
    CGContextDrawPDFPage(context, pageRef);

    UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return finalImage;
} 
like image 108
reflog Avatar answered Sep 22 '22 02:09

reflog