【问题标题】:How to auto rotate page when printing NSDocument via NSView?通过 NSView 打印 NSDocument 时如何自动旋转页面?
【发布时间】:2012-12-12 15:43:06
【问题描述】:

我有一个 NSDocument 后代,我想打印到单个页面 - 当页面宽于高时拉伸以适应并自动旋转。 渲染视图根据内容确定其边界。 rectForPage 只返回 [self bounds]; knowPageRange 设置 range.length = 1 和 range.location = 1 并返回 YES。 使用下面的代码完成打印。

一切正常,除了自动旋转。在打印面板中,我看到了正确形状的预览(宽于高,正确的尺寸等),但是当我打印时,页面是合适的,但是在纵向模式下,不必要地缩小图像。 如果我没有设置 printInfo.paperSize,它会自动旋转正常,但不会缩放,而是会剪切图像。有什么想法吗?

附加信息:打印面板中的“查看 PDF”在预览中显示页面确定。 从预览打印,然后在预览的打印面板中显示图像旋转以匹配纸张纵向方向(即:横向图像本身显示为旋转)。这与我在打印面板中显示未旋转的情况不同。然后从预览的打印面板打印会做正确的事情。

- (NSPrintOperation *)printOperationWithSettings:(NSDictionary *)printSettings error:(NSError **)outError {
    MindMapRenderingView *renderingView = [[MindMapRenderingView alloc] initWithMindMap:_mindMap 
                                                                          printJobTitle:[_mindMap singleLineTitle]];
    NSSize pageSize = [renderingView bounds].size;
    NSPrintOperation *printOperation = [NSPrintOperation printOperationWithView:renderingView
                                                                      printInfo:[self printInfo]];
    [renderingView release];

    NSPrintInfo* printInfo = [printOperation printInfo];
    [[printInfo dictionary] addEntriesFromDictionary:printSettings];

    if (isLandscape)
        [printInfo setOrientation:NSLandscapeOrientation];
    else
        [printInfo setOrientation:NSPortraitOrientation];

    [printInfo setPaperSize:pageSize];

    [printInfo setHorizontalPagination:NSFitPagination];
    [printInfo setVerticalPagination:NSFitPagination];

    return printOperation;
}

【问题讨论】:

  • 可能是您的打印机试图比您更聪明吗?当您“打印到 PDF”时会发生什么?它仍然以不正确的方向出现吗?

标签: cocoa printing


【解决方案1】:

还没有找到自动旋转的方法,但经过更多试验后,我想出了模拟预览打印风景 pdf 方式的解决方案:我旋转用于绘制输出的 NSView 的框架。在 drawRect 中:我还使用 NSAffineTransform 绘制旋转的输出。这给出了所需的结果。唯一的缺点是使用打印面板中的“查看 PDF”现在也会显示旋转的 pdf。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多