简体   繁体   English

Qt如何通过QPrinter打印QFile?

[英]Qt How to Print QFile via QPrinter?

Can any one suggest me a way to Print QFile using QPrinter ?? 谁能建议我一种使用QPrinter打印QFile的方法?

Actually, I have a pdf file generated by my application which i need to print (via dot matrix Printer) as per user choice.I searched QFile documentation but it shows no way to print the file directly to the printer. 实际上,我有一个由我的应用程序生成的pdf文件,我需要根据用户选择进行打印(通过点阵打印机)。我搜索了QFile文档,但它没有显示直接将文件打印到打印机的方法。

Any Idea how to print QFile ?? 任何想法如何打印QFile ??

The QFile class provides filesystem IO. QFile类提供文件系统IO。 In order to print a PDF file, you would have to parse its contents and render it onto a QPrinter . 为了打印PDF文件,您必须解析其内容并将其呈现到QPrinter

So you would have to embed some kind of library for PDF rendering into your application. 因此,您将必须将某种类型的库用于PDF渲染到您的应用程序中。 A popular open-source choice is the Poppler library , used for example by KDE's own PDF viewer Okular. Poppler库是流行的开源选择,例如由KDE自己的PDF查看器Okular使用。

If that is too much hassle for you, there might be platform-dependent shortcuts. 如果这对您来说太麻烦了,那么可能会有依赖于平台的快捷方式。 For example, on Unix/Linux systems, you can run the command xdg-open /path/to/file.pdf (eg using QProcess ), which will open the standard PDF viewer. 例如,在Unix / Linux系统上,您可以运行命令xdg-open /path/to/file.pdf (例如,使用QProcess ),它将打开标准的PDF查看器。 That could work if you instruct the user to choose the "Print" function in this application, but this requires extra user interaction. 如果您指示用户在此应用程序中选择“打印”功能,则可能会起作用,但这需要额外的用户交互。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM