0
我试图打印从文件系统中读取的PDF文件。但不能完全奏效。我知道我必须在视图中有文件,然后打印视图。可可 - 从文件系统中读取PDF文件并打印出来
这是我的打印方法:
NSPrintInfo *printInfo = [NSPrintInfo sharedPrintInfo];
NSPrintOperation *PDFPrint = [NSPrintOperation printOperationWithView:_pdfView printInfo:printInfo];
[PDFPrint setCanSpawnSeparateThread:YES];
[PDFPrint setShowsProgressPanel:YES];
[PDFPrint runOperation];
这是我如何创建视图:
PDFDocument *pdfDocument = [[PDFDocument alloc] initWithURL:fileURL];
PDFPage *firstPage = [pdfDocument pageAtIndex:0];
NSRect bounds = [firstPage boundsForBox:kPDFDisplayBoxMediaBox];
NSSize pixelSize = bounds.size;
NSSize documentSize;
documentSize.width = pixelSize.width;
documentSize.height = pixelSize.height;
PDFView *PDFDocumentView = [[PDFView alloc] initWithFrame:NSMakeRect(0, 0, documentSize.width, documentSize.height)];
[PDFDocumentView setDisplayMode:kPDFDisplaySinglePage];
[PDFDocumentView setDisplayBox:kPDFDisplayBoxMediaBox];
[PDFDocumentView setAutoScales:NO];
[PDFDocumentView setDocument:pdfDocument];
[PDFDocumentView setBackgroundColor:[NSColor redColor]];
return PDFDocumentView;
当我调整了这个来回我已经成功地打印PDF但它没有正确对齐。
关于对齐。我可以看到我创建的红色背景,并且我无法看到PDF右侧的一部分。
那么如何最好地阅读并打印PDF文件呢?
任何想法?
退房[这](http://stackoverflow.com/a/32790178/1223728)的答案。 – Borzh