如何使用pdfbox减少pdf大小

时间:2017-04-28 03:03:49

标签: pdfbox

我想压缩输出PDF。输出下面的代码比原始文件大得多。我可以使用压缩选项吗?

PDDocument doc = new PDDocument();

InputStream in = new FileInputStream(f);
BufferedImage bimg = ImageIO.read(in);
PDPage page = new PDPage(PDRectangle.A4);
doc.addPage(page);
PDImageXObject pdImageXObject = JPEGFactory.createFromImage(doc, bimg, 0.03f);
PDPageContentStream contentStream = new PDPageContentStream(doc, page, AppendMode.APPEND, true);
contentStream.close(); 
doc.save(outfile);
doc.close();

0 个答案:

没有答案
相关问题