gpt4 book ai didi

iphone - 在 iphone 中创建 pdf 缩略图

转载 作者:太空狗 更新时间:2023-10-30 03:34:14 25 4
gpt4 key购买 nike

我是 Objective-c iPhone 编程的新手。我有一个应用程序可以在我的 UIWebView 中成功显示 PDF,但现在我想创建我的 PDF 的缩略图。我的 PDF 存储在我的资源文件夹中。

因此,请提供有关如何显示 PDF 缩略图的代码。我的代码用于显示按钮功能中获取的 PDF:

-(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];
}

最佳答案

试试下面的方法:

- (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;
}

关于iphone - 在 iphone 中创建 pdf 缩略图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5658993/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com