【发布时间】:2012-01-26 15:12:29
【问题描述】:
在我正在创建的应用程序中,我将一长页 HTML 加载到 webView 中,然后使用以下命令将其打印到 PDF:
-(void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
{
if ([frame isEqual:[[self doc] mainFrame]])
{
NSMutableData *newData = [[NSMutableData alloc] init];
NSPrintInfo *newInfo = [NSPrintInfo sharedPrintInfo];
NSView *docView = [[[[self doc] mainFrame] frameView] documentView];
NSPrintOperation *newPrintOp = [NSPrintOperation PDFOperationWithView:docView insideRect:docView.bounds toData:newData printInfo:newInfo];
BOOL runPrint = [newPrintOp runOperation];
if (!runPrint)
{
NSLog(@"Print Failed");
}
PDFDocument *newDoc = [[PDFDocument alloc] initWithData:newData];
[newData release];
[self setPdf:newDoc];
//Other code here
}
}
问题是当我查看newDoc 时,它是一个巨大的单页PDF。我更喜欢的打印行为与“另存为 PDF...”对话框中的打印行为相同 - 即将 PDF 拆分为多个大小合理的页面。
有谁知道如何做到这一点?
我尝试在NSPrintInfo *newInfo = [NSPrintInfo sharedPrintInfo]; 之后插入以下内容
[newInfo setVerticalPagination:NSAutoPagination];
[newInfo setHorizontalPagination:NSAutoPagination];
NSAutoPagination 在文档中描述如下:
NSAutoPagination 图像被分成大小相等的矩形并放置在一列页面中。 在 Mac OS X v10.0 及更高版本中可用。 在 NSPrintInfo.h 中声明。
这对打印的 PDF 没有影响。
【问题讨论】:
标签: objective-c cocoa pdf