1

我有一个 NSTextView 包含数据表,我重写了 drawPageBorderWithSize: 方法来绘制页脚(页码),页眉包含一个页面标题,当我使用 NSPrintOperation 显示打印面板时,一切正常。

但我需要在我的窗口中显示预览(不是打印面板中的那个),为此我尝试将我的视图导出为 PDF 数据,如下所示:

    NSMutableData *pdfData = [[NSMutableData alloc]init];
NSPrintOperation *pdfOperation = [NSPrintOperation PDFOperationWithView:printView insideRect:NSMakeRect(0, 0, 600, 900) toData:pdfData printInfo:myPrintInfo];
[pdfOperation runOperation];

PDFDocument *pdfDocument = [[PDFDocument alloc]initWithData:pdfData];
[pdfDocument writeToFile:@"/my directory/Test.pdf"];

但是这个PDF文件只显示了表格,它没有显示我使用drawPageBorderWithSize制作的页眉和页脚,也没有我在myPrintInfo中疯狂的边距,正如我所说的所有这些都出现在打印面板中!

我也收到了这个错误:

断言失败:(s->stack->next != NULL),函数 CGGStackRestore,文件 Context/CGGStack.c,第 77 行。

为什么 NSPrintOperation 到 PDF 不能在我的 NSTextView 中显示所有内容??!!

4

1 回答 1

0

游戏有点晚了,但我刚刚发现了你的问题。

drawPageBorderWithSize:在这种情况下不会调用该方法。把所有东西都画进去drawRect:

于 2014-09-14T14:55:48.487 回答