【发布时间】:2015-02-07 12:48:29
【问题描述】:
我想使用 itext 库从 java servlet 的 pdf 文件返回一页(以减少文件大小下载)。 使用此代码
try {
PdfReader reader = new PdfReader(input);
Document document = new Document(reader.getPageSizeWithRotation(page_number) );
PdfSmartCopy copy1 = new PdfSmartCopy(document, response.getOutputStream());
copy1.setFullCompression();
document.open();
copy1.addPage(copy1.getImportedPage(reader, page_i) );
copy1.freeReader(reader);
reader.close();
document.close();
} catch (DocumentException e) {
e.printStackTrace();
}
此代码返回页面,但文件大小很大,有时甚至等于原始文件大小,甚至只是一页。
【问题讨论】:
-
也许您的每一页都使用了大字体或大图像。在这种情况下,您是否丢弃 100 页中的 99 页并不重要:该一页仍然需要字体和该图像,并且您的 PDF 文件大小不会减小。如果您想要更有用的答案,您必须向我们提供有关您的 PDF 性质的更多信息。
-
文件副本在邮箱files link,大部分页面是论文图片。
-
我已经下载了腹部.pdf。这是一个只包含图像的 PDF。为什么不提取图像并提供这些图像?如果可以提供单独的图像,为什么还需要单页 PDF?
-
像 (Special Embryology.pdf) 这样的文本附带的文件返回小文件,但我认为返回图像是最好的解决方案,因为大多数文件都是由图像组成的,你想。
标签: java google-app-engine pdf itext