You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by an...@apache.org on 2017/05/24 14:55:15 UTC
syncope git commit: [SYNCOPE-1094] fixed through pdfbox best practices
Repository: syncope
Updated Branches:
refs/heads/2_0_X 7bd67e918 -> 7c5daa5f2
[SYNCOPE-1094] fixed through pdfbox best practices
Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/7c5daa5f
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/7c5daa5f
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/7c5daa5f
Branch: refs/heads/2_0_X
Commit: 7c5daa5f23a3766b8d0b2d148afd55a874f97cad
Parents: 7bd67e9
Author: Andrea Patricelli <an...@apache.org>
Authored: Wed May 24 16:54:51 2017 +0200
Committer: Andrea Patricelli <an...@apache.org>
Committed: Wed May 24 16:54:51 2017 +0200
----------------------------------------------------------------------
.../html/form/preview/BinaryPDFPreviewer.java | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/syncope/blob/7c5daa5f/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/preview/BinaryPDFPreviewer.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/preview/BinaryPDFPreviewer.java b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/preview/BinaryPDFPreviewer.java
index 8b478a9..da00856 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/preview/BinaryPDFPreviewer.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/preview/BinaryPDFPreviewer.java
@@ -24,7 +24,11 @@ import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.Serializable;
+import org.apache.pdfbox.cos.COSObject;
+import org.apache.pdfbox.io.MemoryUsageSetting;
+import org.apache.pdfbox.pdmodel.DefaultResourceCache;
import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.graphics.PDXObject;
import org.apache.pdfbox.rendering.ImageType;
import org.apache.pdfbox.rendering.PDFRenderer;
import org.apache.syncope.client.console.annotations.BinaryPreview;
@@ -44,7 +48,7 @@ public class BinaryPDFPreviewer extends AbstractBinaryPreviewer {
private static final int IMG_SIZE = 300;
- private static final float RESOLUTION = 96;
+ private static final float DPI = 100;
private static final ImageType IMAGE_TYPE = ImageType.RGB;
@@ -60,11 +64,18 @@ public class BinaryPDFPreviewer extends AbstractBinaryPreviewer {
PDDocument document = null;
try {
- document = PDDocument.load(new ByteArrayInputStream(uploadedBytes));
+ document = PDDocument.load(new ByteArrayInputStream(uploadedBytes), MemoryUsageSetting.setupTempFileOnly());
+ document.setResourceCache(new DefaultResourceCache() {
+
+ @Override
+ public void put(final COSObject indirect, final PDXObject xobject) throws IOException {
+ }
+
+ });
if (document.isEncrypted()) {
LOG.info("Document is encrypted, no preview is possible");
} else {
- firstPage = new PDFRenderer(document).renderImage(0, RESOLUTION, IMAGE_TYPE);
+ firstPage = new PDFRenderer(document).renderImageWithDPI(0, DPI, IMAGE_TYPE);
}
} catch (IOException e) {
LOG.error("While generating thumbnail from first page", e);