一:Qt导出PDF
这里我是将3个图片(QPixmap:截图而得)画在了导出的pdf里面,其中第1.2张图片在第一页,第3张图片在第2页
代码:
QPrinter printer_pixmap(QPrinter::HighResolution);
printer_pixmap.setPageSize(QPrinter::A4); //设置纸张大小为A4
printer_pixmap.setPrintRange(QPrinter::AllPages);
printer_pixmap.setOutputFormat(QPrinter::PdfFormat); //设置输出格式为pdf
printer_pixmap.setOutputFileName(outfilepath); //设置输出路径
QPainter painter_pixmap;
painter_pixmap.begin(&printer_pixmap);
QRect rect = painter_pixmap.viewport();
int multiple = rect.width()/pixmap1.width();
painter_pixmap.scale(multiple*0.675, multiple*0.675); //将图像(所有要画的东西)在pdf上放大multiple-1倍
painter_pixmap.drawPixmap(120, 0, pixmap1); //画图1
painter_pixmap.drawPixmap(120, 580, pixmap2);//画图2
printer_pixmap.newPage(); //换页
painter_pixmap.drawPixmap(120, 0, pixmap3);//画图3
painter_pixmap.end();