如前所述,CGPDFPageGetBoxRect(page, kCGPDFMediaBox) 始终为 PDF 返回相同的大小,无论 PDF 的方向如何。
但是页面的旋转是正确返回的。
所以我使用以下代码进行轮换:
rotate = CGPDFPageGetRotationAngle(page);
然后使用我在这里找到的以下代码:http://ipdfdev.com/2011/03/23/display-a-pdf-page-on-the-iphone-and-ipad/
switch (rotate) {
case 0:
// Translate the origin of the coordinate system at the
// bottom left corner of the page rectangle.
CGContextTranslateCTM(context, 0, cropBox.size.height);
// Reverse the Y axis to grow from bottom to top.
CGContextScaleCTM(context, 1, -1);
break;
case 90:
// Reverse the Y axis to grow from bottom to top.
CGContextScaleCTM(context, 1, -1);
// Rotate the coordinate system.
CGContextRotateCTM(context, -M_PI / 2);
break;
case 180:
case -180:
// Reverse the Y axis to grow from bottom to top.
CGContextScaleCTM(context, 1, -1);
// Translate the origin of the coordinate system at the
// top right corner of the page rectangle.
CGContextTranslateCTM(context, cropBox.size.width, 0);
// Rotate the coordinate system with 180 degrees.
CGContextRotateCTM(context, M_PI);
break;
case 270:
case -90:
// Translate the origin of the coordinate system at the
// bottom right corner of the page rectangle.
CGContextTranslateCTM(context, cropBox.size.height, cropBox.size.width);
// Rotate the coordinate system.
CGContextRotateCTM(context, M_PI / 2);
// Reverse the X axis.
CGContextScaleCTM(context, -1, 1);
break;
}
等等 - PDF 以正确的方向显示