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];
}
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.
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.
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.”
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With