java中怎么将jpg转换成pdf
2个回答
展开全部
引用pdfbox jar包
PDDocument pdDocument = new PDDocument();
BufferedImage image = ImageIO.read(f);
int width = 612;
int height = 792;
PDPage pdPage = new PDPage(new PDRectangle(width, height));
pdDocument.addPage(pdPage);
PDImageXObject pdImageXObject = LosslessFactory.createFromImage(pdDocument, image);
PDPageContentStream contentStream = new PDPageContentStream(pdDocument, pdPage);
contentStream.drawImage(pdImageXObject, 0, 0, width, height);
contentStream.close();
pdDocument.save(srcPath + candidate + File.separator
+ f.getName().substring(0, f.getName().length() - 4) + ".pdf");
pdDocument.close();
PDDocument pdDocument = new PDDocument();
BufferedImage image = ImageIO.read(f);
int width = 612;
int height = 792;
PDPage pdPage = new PDPage(new PDRectangle(width, height));
pdDocument.addPage(pdPage);
PDImageXObject pdImageXObject = LosslessFactory.createFromImage(pdDocument, image);
PDPageContentStream contentStream = new PDPageContentStream(pdDocument, pdPage);
contentStream.drawImage(pdImageXObject, 0, 0, width, height);
contentStream.close();
pdDocument.save(srcPath + candidate + File.separator
+ f.getName().substring(0, f.getName().length() - 4) + ".pdf");
pdDocument.close();
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询