Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1722701
  • 博文数量: 1493
  • 博客积分: 38
  • 博客等级: 民兵
  • 技术积分: 5834
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-19 17:28
文章分类

全部博文(1493)

文章存档

2016年(11)

2015年(38)

2014年(137)

2013年(253)

2012年(1054)

2011年(1)

分类:

2012-10-12 16:30:59

原文地址:qt 打印文本 作者:kjqin


点击(此处)折叠或打开

  1. // iFormat 为1表示打印成PDF,否则表示输出到打印机
  2. // strHtml是HTML格式的打印内容,strPdfFile是PDF文件路径。

  3. void printDocument(const QString &strHtml,
  4.         const QString &strPdfFile, int iFormat = 1)
  5. {
  6.     QPrinter p;
  7.     QTextDocument doc;
  8.     doc.setHtml(strHtml);

  9.     if (iFormat == 1)
  10.     {
  11.         p.setPageSize(QPrinter::A4);
  12.         p.setOutputFormat(QPrinter::PdfFormat);
  13.         p.setOutputFileName(strPdfFile);
  14.         doc.print(&p);
  15.     }
  16.     else
  17.     {
  18.         doc.setPageSize(QSizeF(p.logicalDpiX()*(80/25.4),
  19.                 p.logicalDpiY()*(297/25.4)));
  20.         p.setOutputFormat(QPrinter::NativeFormat);
  21.         doc.print(&p);
  22.     }
  23. }

阅读(319) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~