diff options
author | Gerald Palfinger <gerald.palfinger@iaik.tugraz.at> | 2022-01-11 10:51:08 +0100 |
---|---|---|
committer | Gerald Palfinger <gerald.palfinger@iaik.tugraz.at> | 2022-01-12 14:08:10 +0100 |
commit | 08a09e29f16a6419e10ab3af2efbeda69cb84694 (patch) | |
tree | 55c7cb404f6f5c704fa884707e2600f200625731 | |
parent | a898c819e2b496d63c5335faa6f232e7f16423cb (diff) | |
download | pdf-as-4-08a09e29f16a6419e10ab3af2efbeda69cb84694.tar.gz pdf-as-4-08a09e29f16a6419e10ab3af2efbeda69cb84694.tar.bz2 pdf-as-4-08a09e29f16a6419e10ab3af2efbeda69cb84694.zip |
Change placeholder image output from PNG to JPG
Microsoft Word's "print to pdf" function lowers the quality of png images used in a word document.
This leads to a failure on pdf-as placeholder detection using the resulting pdf document.
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/PlaceholderGeneratorServlet.java | 29 |
2 files changed, 13 insertions, 20 deletions
@@ -10,7 +10,7 @@ To add contribution on Joinup page, both release folder and maven repository are Create release folder by running: -`./gradle jar sourcesJar war distZip distTar releases` +`./gradlew jar sourcesJar war distZip distTar releases` With this command, a release folder is created. @@ -20,7 +20,7 @@ Release folder needs to be uploaded to https://apps.egiz.gv.at/releases/pdf-as/r Create mvn repo folder by running: -`./gradle uploadArchives` +`./gradlew uploadArchives` The generated mvn repo needs to be uploaded to https://apps.egiz.gv.at/maven/at/gv/egiz/pdfas/ diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/PlaceholderGeneratorServlet.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/PlaceholderGeneratorServlet.java index a35269d2..1036ef0b 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/PlaceholderGeneratorServlet.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/PlaceholderGeneratorServlet.java @@ -15,7 +15,6 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.commons.io.IOUtils; import org.apache.http.HttpStatus; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,9 +28,6 @@ import at.gv.egiz.pdfas.web.helper.QRCodeGenerator; public class PlaceholderGeneratorServlet extends HttpServlet implements PlaceholderExtractorConstants { - /** - * - */ private static final long serialVersionUID = -5854130802422496977L; public static final String PARAM_ID = "id"; @@ -55,10 +51,9 @@ public class PlaceholderGeneratorServlet extends HttpServlet implements Placehol this.doProcess(req, resp); } - protected void doProcess(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - + protected void doProcess(HttpServletRequest req, HttpServletResponse resp) throws IOException { if(!WebConfiguration.isQRPlaceholderGenerator()) { - logger.info("QR Placeholder is disabled by configuration (see {})" + WebConfiguration.PLACEHOLDER_GENERATOR_ENABLED); + logger.info("QR Placeholder is disabled by configuration (see {})", WebConfiguration.PLACEHOLDER_GENERATOR_ENABLED); resp.sendError(HttpStatus.SC_NOT_FOUND); return; } @@ -74,7 +69,7 @@ public class PlaceholderGeneratorServlet extends HttpServlet implements Placehol if(id != null && !id.isEmpty()) { id = id.replaceAll("[^0-9]", ""); - if(id != null && !id.isEmpty()) { + if(!id.isEmpty()) { try{ if(id.length()> 5) id = id.substring(0,5); @@ -99,9 +94,9 @@ public class PlaceholderGeneratorServlet extends HttpServlet implements Placehol } } - filename = filename + ".png"; + filename = filename + ".jpg"; - logger.info("generating qr placeholder for '{}' as {}", buildString, filename); + logger.info("Generating QR placeholder for '{}' as {}", buildString, filename); //if(id != null || profile != null) { // We need to generate the image @@ -152,7 +147,7 @@ public class PlaceholderGeneratorServlet extends HttpServlet implements Placehol try { QRCodeGenerator.generateQRCode(buildString, baos, qrSize); } catch (WriterException e) { - logger.warn("Failed to generate QR Code for placeholder generationg", e); + logger.warn("Failed to generate QR Code for placeholder generation", e); resp.sendError(HttpStatus.SC_INTERNAL_SERVER_ERROR); return; } @@ -160,9 +155,8 @@ public class PlaceholderGeneratorServlet extends HttpServlet implements Placehol baos.close(); BufferedImage qr = ImageIO.read(new ByteArrayInputStream(baos.toByteArray())); - BufferedImage off_Image = - new BufferedImage(width, height, - BufferedImage.TYPE_INT_ARGB); + BufferedImage off_Image = new BufferedImage(width, height, + BufferedImage.TYPE_INT_RGB); //use TYPE_INT_ARGB for png, TYPE_INT_RGB for jpg Graphics g = off_Image.getGraphics(); g.setColor(new Color(255,255,255,1)); @@ -188,7 +182,6 @@ public class PlaceholderGeneratorServlet extends HttpServlet implements Placehol int start = (height - textHeight) / 2; if(profile != null && profile.endsWith("_EN")) { - g.drawString("placeholder for the", qrSize + ( 3 * border), start + lineSpace); g.drawString("electronic signature", qrSize + ( 3 * border), start + (2 * lineSpace)); } else { @@ -196,7 +189,6 @@ public class PlaceholderGeneratorServlet extends HttpServlet implements Placehol g.drawString("elektronische Signatur", qrSize + ( 3 * border), start + (2 * lineSpace)); } if(id != null && !id.isEmpty()) { - Font nrFont = new Font(Font.SANS_SERIF, Font.BOLD | Font.ITALIC, 10); g.setFont(nrFont); @@ -204,12 +196,13 @@ public class PlaceholderGeneratorServlet extends HttpServlet implements Placehol } logger.info("serving qr placeholder for '{}'", buildString); - resp.setContentType("image/png"); + resp.setContentType("image/jpeg"); resp.setHeader("Cache-Control", "private, no-store, no-cache, must-revalidate"); resp.setHeader("Pragma", "no-cache"); resp.setHeader ("Content-Disposition", "attachment; filename=\""+filename+"\""); - ImageIO.write(off_Image, "PNG", resp.getOutputStream()); + // Use JPG (instead of PNG) as output format to avoid placeholder being not recognised after printing to PDF in Microsoft Word + ImageIO.write(off_Image, "JPG", resp.getOutputStream()); return; /*} else { // just use the template |