我正在尝试开发一个桌面应用程序(最好),它应该能够在很大程度上压缩PDF文件(可能大约40%-50%)。我选择了JAVA并编写了以下代码,但它可以压缩文件只需10kb,这是不可取的。我应该选择哪种语言,或者我该怎样做才能获得理想的结果。请帮助!
public class Compress {
public static void main(String[] args) throws FileNotFoundException, DocumentException, IOException {
PdfReader reader = new PdfReader("C:\\Users\\Srijita thakur\\Desktop\\test\\CS_S06.pdf");
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("C:\\Users\\Srijita Thakur\\Desktop\\test\\op.pdf"), PdfWriter.VERSION_1_5);
stamper.getWriter().setCompressionLevel(5);
int total = reader.getNumberOfPages() + 1;
for (int i = 1; i < total; i++) {
reader.setPageContent(i, reader.getPageContent(i));
}
stamper.setFullCompression();
stamper.close();
reader.close();
}
}