打印离屏PDFViews [英] Printing Off-screen PDFViews

查看:152
本文介绍了打印离屏PDFViews的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种情况,我想打印多页PDF。虽然我可以使用PDFKit实用程序类和/或quartz函数来获取信息来手动写入NSView子类的绘图/分页代码,但我认为更快的替代方法是创建一个离屏PDFView并指示它自己打印。当我尝试这个解决方案时,打印对话框没有消失,打印对话框右侧的所有打印设置控件消失,应用程序冻结。

I have a situation where I want to print a multi-page PDF. While I could use the PDFKit utility classes and/or quartz functions to get the information to manually write drawing/pagination code for a NSView subclass, I had thought that quicker alternative would be to create an off-screen PDFView and tell it to print itself. When I tried this solution, the print dialog didn't go away, all of the print settings controls on the right half of the print dialog disappeared, and the application froze.

然后我写了一个小测试应用程序用下面的方法说明了问题。当在没有定义USE_PDF_VIEW预处理器宏的情况下编译测试程序时,空白视图显示正常。如果定义USE_PDF_VIEW,则文档不打印,大多数打印对话框控件消失,应用程序冻结。虽然我有其他方法来实现我的目标,我很好奇为什么这个捷径不工作。有什么Cocoa绘图我还是不明白吗?我在电子邮件中碰到Apple Voodoo Magic(tm),使得PDFView的行为与其他NSView的完全不同。

I then wrote a tiny test application with the following method that illustrates the problem. When the test program is compiled without the USE_PDF_VIEW preprocessor macro defined, the blank view displays fine. If USE_PDF_VIEW is defined, the document doesn't print, most of the print dialog controls disappear, and the app freezes. While I have other ways of accomplishing my goal, I'm curious as to why this shortcut doesn't work. Is there something about Cocoa drawing I still don't understand? Am I banging into Apple Voodoo Magic(tm) behind the scenes that makes PDFView behave in a completely different way than other NSViews?

- (void)printMyStuff:(id)sender {

NSPrintInfo *currInfo = [NSPrintInfo sharedPrintInfo];

#ifdef USE_PDF_VIEW


    PDFView *pdfView = [[PDFView alloc] init];
    PDFDocument *pdfDoc = [[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:@"/Users/wls/Documents/my_document.pdf"]];
    [pdfView setDocument: pdfDoc];
    [pdfView printWithInfo:currInfo autoRotate:YES];


#else

    NSView *myView = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 500, 500)];
    NSPrintOperation *myop = [NSPrintOperation printOperationWithView:myView printInfo:currInfo];
    [myop runOperation];


#endif

}


推荐答案

有完全相同的问题。
需要将 PDFView 添加到 NSWindow ,以便 printWithInfo:

Had the exact same problem. The PDFView needs to be added to a NSWindow in order for printWithInfo:autoRotate: to work (atleast in my case), otherwise the printing controls go blank or won't work.

这里是完整的代码:

    PDFView *vDoc = [[PDFView alloc] init];
    [vDoc setDocument:pdfDoc];
    [vDoc setAutoScales: YES];
    [vDoc setDisplaysPageBreaks: NO];
    NSWindow *wnd = [[NSWindow alloc] init];
    [wnd setContentSize:vDoc.frame.size];
    [wnd setContentView:vDoc];
    [vDoc printWithInfo:printInfo autoRotate:YES];
    [wnd release];
    [vDoc release];`

这篇关于打印离屏PDFViews的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆