Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos cocoa osx打印pdf文档_Macos_Cocoa_Pdf_Printing - Fatal编程技术网

Macos cocoa osx打印pdf文档

Macos cocoa osx打印pdf文档,macos,cocoa,pdf,printing,Macos,Cocoa,Pdf,Printing,在我的cocoa应用程序中,我从我的webview获得一个pdf文档。我需要打印那个pdf文件。我了解到有NSPrintOperation printOperationWithView方法,但该方法打印文档的视图。是否有直接从文件url打印的方法?我怎样才能正确地做到这一点 这是我的代码: NSString *fileName = [NSString stringWithFormat:@"%@/mypdf.pdf", documentsDirectory]; NSData *pdfFinal

在我的cocoa应用程序中,我从我的webview获得一个pdf文档。我需要打印那个pdf文件。我了解到有NSPrintOperation printOperationWithView方法,但该方法打印文档的视图。是否有直接从文件url打印的方法?我怎样才能正确地做到这一点

这是我的代码:

NSString *fileName = [NSString stringWithFormat:@"%@/mypdf.pdf", documentsDirectory];

NSData *pdfFinal = [[[[webView mainFrame] frameView] documentView] dataWithPDFInsideRect:[[[webView mainFrame] frameView] documentView].frame];
PDFDocument *doc = [[PDFDocument alloc] initWithData:pdfFinal];
[doc writeToFile:fileName];
我需要帮助。提前感谢。

阅读以下答案:

它解释了如何获取存储在NSData结构中的PDF文件并将其发送到打印机。因此,剩下的唯一挑战(除了清理那些肯定不是生产质量的代码)是将您的PDF文件放入NSData流中。这应该不会很难

事实上,您可以更改部分代码,而不是使用从NSData流获取信息的数据提供程序,而是使用以下方法构建一个直接从文件读取的数据提供程序:

CGDataProviderRef CGDataProviderCreateWithFilename ( const char *filename );
如果你已经在磁盘上的某个地方有了PDF文件,那就更简单了