Android:减少Pdf大小

时间:2015-07-05 23:40:51

标签: android pdf compression pdf-generation adobe-reader

如何在Android中实现与Adobe Reader,Quartz Pdf Context等相比的PDF文件压缩级别?

我尝试使用iText,但压缩级别比Adobe Reader低约400%,比Quartz Pdf Context低200%。

我在iText中使用的代码(来源iText文档)是:

public void compressPdf(String src, String dest) throws IOException, DocumentException {
    PdfReader reader = new PdfReader(src);
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest), PdfWriter.VERSION_1_5);
    stamper.getWriter().setCompressionLevel(9);
    int total = reader.getNumberOfPages() + 1;
    for (int i = 1; i < total; i++) {
        reader.setPageContent(i, reader.getPageContent(i));
    }
    stamper.setFullCompression();
    stamper.close();
    reader.close();
}

0 个答案:

没有答案