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

浪子不回头ぞ 提交于 2019-12-10 20:13:50

问题


I am currently working for a simple PDF reader using CGPDFDocumnentRef. It is all fine when I try to render a Portrait PDF document. But when I try to render one in Landscape, it shows a rotated PDF document. Of course when I view that landscape PDF file in the web browser of a pdf reader, it is a landscape one.

Is there any method in iPhone SDK that can detect the Orientation of a pdf document?

Any help would be appreciated.

Regards, Xeron0719


回答1:


You may try to get the page size of your pdf and then check if width is > than heigh and eventually rotate it...

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


来源:https://stackoverflow.com/questions/6321772/how-to-detect-the-orientation-of-a-pdf-document-in-iphone-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!