QPdfWriter QPrinter QPainter 自定义生成PDF文件 基本控件(十六)
程序员文章站
2022-05-28 11:38:35
...
一、效果图
二、代码
QFile file(QCoreApplication::applicationDirPath() + "/demo.pdf");
file.open(QIODevice::WriteOnly);
QPdfWriter* writer = new QPdfWriter(&file);
QPainter* p = new QPainter(writer);
writer->setPageSize(QPagedPaintDevice::A4);
p->drawText(QRect(100, 100, 4200, 2200), QString("我国经济长期向好的基本面没有改变(人民论坛)"));
writer->newPage();
delete p;
delete writer;
file.close();
QPrinter printerPixmap(QPrinter::HighResolution);
printerPixmap.setPageSize(QPrinter::A4);
printerPixmap.setOutputFormat(QPrinter::PdfFormat);
printerPixmap.setOutputFileName(QCoreApplication::applicationDirPath() + "/demo1.pdf");
QPixmap pixmap;
pixmap.load(QCoreApplication::applicationDirPath() + "/1.jpg");
QPainter painterPixmap;
painterPixmap.begin(&printerPixmap);
QRect rect = painterPixmap.viewport();
int multiple = rect.width() / pixmap.width();
painterPixmap.scale(multiple, multiple);
painterPixmap.drawPixmap(0, 0, pixmap);
painterPixmap.end();
上一篇: mybatis之(Oracle,MySql)批量更新
下一篇: C# 删除指定文件或文件夹