!70 修正PDF转图片,内存无法回收导致的OOM

Merge pull request !70 from SawyerYong/N/A
This commit is contained in:
陈精华 2023-03-08 05:55:45 +00:00 committed by Gitee
commit daa081d46d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 22 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import cn.keking.config.ConfigConstants;
import cn.keking.model.FileAttribute;
import cn.keking.model.FileType;
import cn.keking.service.cache.CacheService;
import cn.keking.service.cache.NotResourceCache;
import cn.keking.utils.KkFileUtils;
import cn.keking.utils.WebUtils;
import com.aspose.cad.CodePages;
@ -198,6 +199,7 @@ public class FileHandlerService {
return null;
}
PDDocument doc = PDDocument.load(pdfFile);
doc.setResourceCache(new NotResourceCache());
int pageCount = doc.getNumberOfPages();
PDFRenderer pdfRenderer = new PDFRenderer(doc);

View File

@ -0,0 +1,20 @@
package cn.keking.service.cache;
import org.apache.pdfbox.cos.COSObject;
import org.apache.pdfbox.pdmodel.DefaultResourceCache;
import org.apache.pdfbox.pdmodel.graphics.PDXObject;
import java.io.IOException;
/**
* @author: Sawyer.Yong
* @since: 2023/02/18 14:45
* 解决图片 SoftReference 导致内存无法被回收导致的OOM, 详见 https://issues.apache.org/jira/browse/PDFBOX-3700
*/
public class NotResourceCache extends DefaultResourceCache {
@Override
public void put(COSObject indirect, PDXObject xobject) throws IOException {
// do nothing
}
}