QPrinter和QPrintDialog的使用举例

#ifndef QT_NO_PRINTER
    QPrinter printer(QPrinter::HighResolution);
    qDebug()<true "PDF-XChange 4.0"
    QPrintDialog dialog(&printer, this);

    if (dialog.exec()) {
        qDebug()<true "PDF-XChange 4.0"
        QPainter painter(&printer);
        QRect rect = painter.viewport();
        QSize size = imageLabel->pixmap()->size();
        size.scale(rect.size(), Qt::KeepAspectRatio);
        painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
        painter.setWindow(imageLabel->pixmap()->rect());

        //生成一个5页的pdf文档
        {
            QList pPixmapList;
            for(int i=0; i<5;i++)
            {
                pPixmapList.append(QPixmap(*imageLabel->pixmap()));
            }
            for(int i=0;i<5;i++)
            {
                painter.drawPixmap(0, 0, pPixmapList.at(i));
                if(i!=4)
                    printer.newPage();
            }
        }
    }
#endif

你可能感兴趣的:(QT)