简体   繁体   English

如何在 iPhone SDK 中检测 PDF 文档的方向

[英]How to detect the orientation of a PDF document in iPhone SDK

I am currently working for a simple PDF reader using CGPDFDocumnentRef.我目前正在使用 CGPDFDocumnentRef 为一个简单的 PDF 阅读器工作。 It is all fine when I try to render a Portrait PDF document.当我尝试渲染肖像 PDF 文档时,一切都很好。 But when I try to render one in Landscape, it shows a rotated PDF document.但是当我尝试在 Landscape 中渲染一个时,它会显示一个旋转的 PDF 文档。 Of course when I view that landscape PDF file in the web browser of a pdf reader, it is a landscape one.当然,当我在 pdf 阅读器的 web 浏览器中查看横向 PDF 文件时,它是横向的。

Is there any method in iPhone SDK that can detect the Orientation of a pdf document? iPhone SDK 中是否有任何方法可以检测 pdf 文档的方向?

Any help would be appreciated.任何帮助,将不胜感激。

Regards, Xeron0719问候, Xeron0719

You may try to get the page size of your pdf and then check if width is > than heigh and eventually rotate it...您可以尝试获取 pdf 的页面大小,然后检查宽度是否大于高度并最终旋转它...

-(CGSize)getPdfSize{
    CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("aPdfFile.pdf"), NULL, NULL);
    pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
    CGPDFPageRef page = CGPDFDocumentGetPage(pdf, 1);
    CGRect appR = CGPDFPageGetBoxRect (page, 1);
//  NSLog(@"          .....     pdf width: %f", appR.size.width); 
    return appR.size;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM