How to determine the orientation of a PDF in the iPhone SDK

I am currently working for a simple PDF reader using CGPDFDocumnentRef. Everything is fine when I try to make a portrait PDF document. But when I try to make one in Landscape, it shows a rotated PDF document. Of course, when I view this landscape PDF file in the web browser of the PDF reader, it is landscape.

Is there any method in the iPhone SDK that can determine the orientation of a PDF?

Any help would be appreciated.

Regards, Xeron0719

+3
source share
1 answer

You can try to get the page size of your pdf file and then check if there is a width> than heigh and ultimately 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;
}
+5
source

All Articles