QT 打印 pdf

需求 qt 需要打印 pdf 解决 简单的打印 pdf,可以使用 QPrinter. void Printer::Print(QPrinter *printer) { qDebug() << "Printer::Print"; QPainter *pPainter = new QPainter(printer); int page_border = 30 * line_ratio_; int nPdfWidth = pPainter->viewport().width(); int nPdfHeight = pPainter->viewport().height(); qDebug() << "pdf width: " << nPdfWidth << ", height: " << nPdfHeight; //绘制标题 int y = 10 * line_ratio_; int nLineHeight = 60 * line_ratio_; y = PrintInfo(pPainter, nPdfWidth, page_border, y, nLineHeight); qDebug() << "after PrintInfo y: " << y; y += 10 * line_ratio_; pPainter->drawLine(QLineF(page_border, y + 15 * line_ratio_, nPdfWidth - page_border, y + 15 * line_ratio_)); y += 30 * line_ratio_; y = PrintImage(pPainter, nPdfWidth, page_border, y, nPdfHeight * image_ratio_); qDebug() << "after PrintImage y: " << y; y = PrintTable(pPainter, nPdfWidth, page_border, y, nLineHeight); qDebug() << "after PrintTable y: " << y; delete pPainter; } int Printer::PrintInfo(QPainter *pPainter, int nPdfWidth, int page_border, int y, int nLineHeight) { pPainter->setFont(QFont("宋体", 18, QFont::Bold)); pPainter->drawText(QRect(0, y, nPdfWidth, 100), Qt::AlignCenter, tr(organization_name_....

2023-11-13 · 2 min · 312 words · RamLife