【发布时间】:2018-12-10 14:30:49
【问题描述】:
我的代码使用“飞碟用户代理”库从 html 模板生成 PDF/PPT 文件。
现在的问题是 Itext 使用缓存系统通过缓存而不是调用外部 URL 来访问图像和其他资源。我想知道如何清除这个缓存,或者刷新需要多少时间。我不知道我在这里感到绝望和无能为力,因为由于缺乏良好的文档,我什至无法理解这个工具。
1- 请您解释一下ReplacedElementFactory 的作用。
2- 在研究图书馆时,我找到了方法:
public ImageResource getImageResource(String uri) {
ImageResource resource = null;
uri = this.resolveURI(uri);
resource = (ImageResource)this._imageCache.get(uri);
if (resource == null) {
InputStream is = this.resolveAndOpenStream(uri);
if (is != null) {
try {
URL url = new URL(uri);
if (url.getPath() != null && url.getPath().toLowerCase().endsWith(".pdf")) {
PdfReader reader = this._outputDevice.getReader(url);
PDFAsImage image = new PDFAsImage(url);
Rectangle rect = reader.getPageSizeWithRotation(1);
image.setInitialWidth(rect.getWidth() * this._outputDevice.getDotsPerPoint());
image.setInitialHeight(rect.getHeight() * this._outputDevice.getDotsPerPoint());
resource = new ImageResource(uri, image);
} else {
Image image = Image.getInstance(this.readStream(is));
this.scaleToOutputResolution(image);
resource = new ImageResource(uri, new ITextFSImage(image));
}
this._imageCache.put(uri, resource);
} catch (Exception var16) {
XRLog.exception("Can't read image file; unexpected problem for URI '" + uri + "'", var16);
} finally {
try {
is.close();
} catch (IOException var15) {
;
}
}
}
}
包含这行代码resource = (ImageResource)this._imageCache.get(uri);
我认为这是它从缓存中获取图像的地方,而不是寻找更新版本的图片。
3- Itext 多久刷新一次它的缓存,首先它的大小是多少,我如何为其指定路径,它如何存储它?
感谢您的帮助。
【问题讨论】:
标签: java itext flying-saucer