1.导入依赖
<!-- https://mvnrepository.com/artifact/com.itextpdf/itextpdf --> <dependency> <groupId>com.itextpdf</groupId> <artifactId>itextpdf</artifactId> <version>5.5.13</version> </dependency> <!-- https://mvnrepository.com/artifact/com.lowagie/itext --> <dependency> <groupId>com.lowagie</groupId> <artifactId>itext</artifactId> <version>4.2.1</version> </dependency> |
2.实现图片转PDF的工具类
package util; import java.io.FileOutputStream; import com.itextpdf.text.Document; public class PicToPdfUtil { |
3.测试
public static void main(String[] args) { String source = "D:/image/车辆颜色.png"; String target = "D:/aaa/1.pdf"; convert(source, target); } |