How to convert pdf file into png (image) file in QT

家住魔仙堡 提交于 2019-12-13 03:54:42

问题


I have following code

QString filePath("x.pdf");
QPrinter printer(QPrinter::HighResolution);
printer.setCreator(PRODUCT_NAME);
printer.setOutputFileName(filePath;
printer.setOutputFormat(QPrinter::PdfFormat);
QPainter painter(&printer);
render(&painter);

how can I save this above PDF file x.pdf into a png file using QT code?


回答1:


Qt has no built-in methods that allow to convert PDF files to images. You should use some other libraries or call from your program some external converter. Maybe try with Poppler:

QImage image = pdfPage->renderToImage(xres, yres, x, y, width, height);
image.save("convertedDocument.png");


来源:https://stackoverflow.com/questions/45736885/how-to-convert-pdf-file-into-png-image-file-in-qt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!