如何使用java将PNG文件转换为PDF? [英] How can I convert a PNG file to PDF using java?
本文介绍了如何使用java将PNG文件转换为PDF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用任何开源库吗?
Are there any open source libraries that I can use?
推荐答案
itext 可以帮到你。
您没有真正将png转换为pdf,但创建了一个带有png的pdf。
简单示例:
itext may help you. you don't really convert a png to pdf but create a pdf with a png in it. simple example:
Document document = new Document(PageSize.A4, 20, 20, 20, 20);
PdfWriter.getInstance(document, new FileOutputStream("C:/test.pdf"));
document.open();
Image image = Image.getInstance(getClass().getResource("/logo.png"));
document.add(image);
document.close();
这篇关于如何使用java将PNG文件转换为PDF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文