2013-10-02 40 views
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文件呢?

任何想法?

+0

退房[這](http://stackoverflow.com/a/32790178/1223728)的答案。 – Borzh

回答

0

看來,如果我改用秤正確:

[PDFDocumentView printWithInfo:printInfo autoRotate:NO]; 
相關問題