gpt4 book ai didi

iphone - 如何使用 iPhone SDK 从 PDF 文档生成缩略图?

转载 作者:行者123 更新时间:2023-12-03 18:26:16 25 4
gpt4 key购买 nike

我已阅读the Apple PDF documentation with Quartz .

但我不知道如何从 PDF 文档生成缩略图...

有什么想法/示例代码吗?

最佳答案

这是我的示例代码。

NSURL* pdfFileUrl = [NSURL fileURLWithPath:finalPath];
CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfFileUrl);
CGPDFPageRef page;

CGRect aRect = CGRectMake(0, 0, 70, 100); // thumbnail size
UIGraphicsBeginImageContext(aRect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
UIImage* thumbnailImage;


NSUInteger totalNum = CGPDFDocumentGetNumberOfPages(pdf);

for(int i = 0; i < totalNum; i++ ) {


CGContextSaveGState(context);
CGContextTranslateCTM(context, 0.0, aRect.size.height);
CGContextScaleCTM(context, 1.0, -1.0);

CGContextSetGrayFillColor(context, 1.0, 1.0);
CGContextFillRect(context, aRect);


// Grab the first PDF page
page = CGPDFDocumentGetPage(pdf, i + 1);
CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFMediaBox, aRect, 0, true);
// And apply the transform.
CGContextConcatCTM(context, pdfTransform);

CGContextDrawPDFPage(context, page);

// Create the new UIImage from the context
thumbnailImage = UIGraphicsGetImageFromCurrentImageContext();

//Use thumbnailImage (e.g. drawing, saving it to a file, etc)

CGContextRestoreGState(context);

}


UIGraphicsEndImageContext();
CGPDFDocumentRelease(pdf);

关于iphone - 如何使用 iPhone SDK 从 PDF 文档生成缩略图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4504834/

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