如何在QT中将pdf文件转换为png(图像)文件 [英] How to convert pdf file into png (image) file in QT

查看:1489
本文介绍了如何在QT中将pdf文件转换为png(图像)文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码

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

如何使用QT代码将以上PDF文件x.pdf保存为png文件?

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

推荐答案

Qt没有允许将PDF文件转换为图像的内置方法.您应该使用其他一些库,或者从程序中调用某些外部转换器.也许尝试使用 Poppler :

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");

这篇关于如何在QT中将pdf文件转换为png(图像)文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆