首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >图片没有显示在pdf预览?

图片没有显示在pdf预览?
EN

Stack Overflow用户
提问于 2015-08-14 05:44:28
回答 1查看 71关注 0票数 0

奇怪的感觉是,如果我想在一个控制器上预览一个pdf,除了一个图像,我唯一能让它工作的方法就是使用一个自定义的自定义的视图控制器,也许我不清楚。如何使图像显示在QuickLook操作的预览中,而不需要切换到视图中,而不仅仅是模态?这合乎逻辑吗?

我开发了一个生成PDF的应用程序,我给用户提供了预览them....but的可能性,当这些image....boom有一个image....boom时,图像就会从preview...unless上消失--我用的是一个索引--那么就没问题了,不过看起来很奇怪。如有任何建议?....thanks提前.

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-15 07:58:34

代码语言:javascript
复制
- (CFRange)renderPage:(NSInteger)pageNum withTextRange:(CFRange)currentRange
   andFramesetter:(CTFramesetterRef)framesetter
{

CGContextRef    currentContext = UIGraphicsGetCurrentContext();

// Put the text matrix into a known state. This ensures
// that no old scaling factors are left in place.
CGContextSetTextMatrix(currentContext, CGAffineTransformIdentity);

// Create a path object to enclose the text. Use 72 point
// margins all around the text.

#pragma-----------here to disclose the height of text on pdf preview

CGRect    frameRect = CGRectMake(40, 72, 468,  350);
CGMutablePathRef framePath = CGPathCreateMutable();
CGPathAddRect(framePath, NULL, frameRect);

[_imageView1 setImage:theImage1];

CGRect frame = CGRectMake(40, 50, 130, 130);
[ProgramPDFViewController drawImage:theImage1 inRect:frame];

CGSize size = theImage1.size;
CGFloat ratio = 0;
if (size.width > size.height) {
    ratio = 44.0 / size.width;
} else {
    ratio = 44.0 / size.height;
}
CGRect rect = CGRectMake(0.0, 0.0, ratio * size.width, ratio * size.height);


UIGraphicsBeginImageContext(rect.size);
[theImage1 drawInRect:rect];
UIGraphicsEndImageContext();
CTFrameRef frameRef = CTFramesetterCreateFrame(framesetter, currentRange, framePath, NULL);
CGPathRelease(framePath);
CGContextTranslateCTM(currentContext, 0, kDefaultPageHeight);
CGContextScaleCTM(currentContext, 1.0, -1.0);
 CTFrameDraw(frameRef, currentContext);
currentRange = CTFrameGetVisibleStringRange(frameRef);
currentRange.location += currentRange.length;
currentRange.length = 0;
CFRelease(frameRef);

return currentRange;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32003035

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档