【问题标题】:print pdf file via printer device in qt在qt中通过打印机设备打印pdf文件
【发布时间】:2014-12-21 02:50:00
【问题描述】:

我是新的 C++ QT 程序员,我想通过我的打印机设备(或网络打印机)打印多个 pdf 文件,我搜索并找到了这个教程: Qt Handling PDF file 但我无法编译 MuPDF 和 Poppler 并在我的应用程序中使用这些第三方库。我的 pdf 文件也加密了,必须从内存中打印文件。 是通过我的打印机设备打印 pdf 文件的方法吗?

【问题讨论】:

  • 是否禁止使用任何第三方程序?您可以调用能够理解 PDF 并支持多种输出语言的 ghostscript。
  • 是的,我的老板禁止我使用第三库,我可以直接通过打印机设备打印ghostscript文件吗?我可以轻松地将我的pdf文件转换为ghostscript文件吗?
  • windows平台(windows xp,7)
  • 使用 ghostscript,您仍然需要确定要服务的打印机类型。我认为最简单的方法是调用 acrobat 阅读器,请参阅 here 特别是 /t 选项。
  • 实际上我的 pdf 是加密的,不能保存在磁盘上的 pdf 文件中,因此我不能使用命令行 acrobat 阅读器。

标签: c++ qt pdf printing network-printers


【解决方案1】:

你好,你可以使用这样的东西。

QPrinter printer(QPrinter::HighResolution);
printer.setOrientation(QPrinter::Portrait);
QPrintDialog dlg(&printer, this);
dlg.setWindowTitle("Print");

if (dlg.exec() == QDialog::Accepted)
{
    QWidget* widget = new QWidget(his); // this widget is your pdf widget
    QPixmap printPixmap(widget->width(),widget->height());
    widget->render(&printPixmap,QPoint(),QRegion(0,0,widget->width(),widget->height()));
    QPainter painterPixmap(&printer);
    painterPixmap.scale(4,4);
    painterPixmap.drawPixmap(printer.pageRect().topLeft(), printPixmap, printPixmap.rect());
}

【讨论】:

  • 我想将 pdf 文件发送到打印机设备(例如网络打印机),我不想打印我的小部件,
  • 好的,如果你可以在小部件上渲染文件,那么你可以像这样打印。
  • 我不能使用 mupdf 和 poppler 来渲染 pdf(真的我不能为 qt5 编译这个库),任何渲染库或方式存在吗??
猜你喜欢
  • 2014-08-25
  • 1970-01-01
  • 2014-07-22
  • 1970-01-01
  • 1970-01-01
  • 2017-10-02
  • 2019-12-06
  • 2012-01-07
  • 1970-01-01
相关资源
最近更新 更多