PDF-Scrollview - 以横向格式显示 PDF - 文档

发布于 2024-12-03 01:01:09 字数 326 浏览 1 评论 0原文

我正在使用 Apple 的示例“PDFScrollView”在 iPad 上显示 PDF。只要 PDF 文档处于纵向模式,此功能就可以正常工作。 但是,当文档处于横向模式时,文档始终显示为旋转 90 度。 我发现这个如何检测方向iPhone SDK 中的 PDF 文档 - 但是当我尝试获取 PDF 的尺寸时,高度总是大于宽度,无论 PDF 有什么方向......

有什么想法吗?

I'm using Apple's example «PDFScrollView» to display PDFs on an iPad. This works fine, as long as the PDF-document is in Portrait-Mode.
When the document is in Landscape-mode, though, the document is always shown rotated by 90 degrees.
I found this How to detect the orientation of a PDF document in iPhone SDK - but when I try to get the dimensions of the PDF, the height is always bigger than the width, no matter what orientation the PDF has...

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

つ低調成傷 2024-12-10 01:01:09

如前所述,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 以正确的方向显示

As mentionend in, the CGPDFPageGetBoxRect(page, kCGPDFMediaBox) always returns the same size for a PDF, no matter what orientation the PDF has.

But the rotation of the page is returned correctly.

So I get the rotation using this code:

rotate =  CGPDFPageGetRotationAngle(page);

And then use the code below which I found here: 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;
    }

Et voilà - the PDF is displayed in the right orientation

心的位置 2024-12-10 01:01:09

我写这篇文章的假设是您的问题是关于当用户旋转设备时旋转文档......
为此,您必须在视图中重新绘制文档。要实现这一点,请执行以下操作...

  1. 更改绘制文档的视图的框架,并在以下方法中在该视图中使用 CALayer(或 CATiledLayer)。
    - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 持续时间:(NSTimeInterval)duration

  2. 更改帧后调用 CATiledLayer 的 setNeedsDisplay 方法。

  3. 然后返回YES
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

上述步骤将相应地在您的视图的新框架中重新绘制文档,以便其正确显示。

->如果您的视图是全屏,则只需第 2 步和第 3 步就足够了。

如果需要任何进一步的帮助,请在此发帖......

I am writing this with assumption that your problem is about rotating document when user rotates device....
For that you have to redraw document in view. TO achieve that do following....

  1. change frame of the view in which document is drawn, and CALayer(OR CATiledLayer) being used in that view in following method.
    - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

  2. Call setNeedsDisplay method of CATiledLayer after changing frame.

  3. Then return YES in
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation.

Above steps will redraw the document in new frame of you View accordingly so it will appear properly.

->IF your view is in full screen or then only step 2 ans 3 will be enough.

Post here if any further assistance is required....

愿得七秒忆 2024-12-10 01:01:09

您自己绘制 PDF 有什么特殊原因吗?您可以在 iOS 4.0 或更高版本上使用 QLPreviewController,并在以前的版本中使用 UIDocumentInteractionController

Is there a particular reason you are drawing PDFs yourself? You could use QLPreviewController on iOS 4.0 or later, and UIDocumentInteractionController for previous versions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文