From c3f89f2f2b6acf578a2f9a281b39df6788c17957 Mon Sep 17 00:00:00 2001 From: Emmeran Seehuber Date: Sun, 8 Oct 2017 13:48:54 +0200 Subject: [PATCH] Fix #135: Don't write a MiterLimit of 0 into the PDF, as Acrobat Reader does not like that and stops rendering everything ... --- README.md | 1 + .../testcases/TestcaseRunner.java | 28 ++++++++++++------ .../testcases/adobe-borderstyle-bugs.html | 29 +++++++++++++++++++ .../pdfboxout/PdfContentStreamAdapter.java | 11 ++++--- 4 files changed, 56 insertions(+), 13 deletions(-) create mode 100644 openhtmltopdf-examples/src/main/resources/testcases/adobe-borderstyle-bugs.html diff --git a/README.md b/README.md index 811092a6f..16961864a 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ head - 0.0.1-RC12-SNAPSHOT + [Font mapping in custom object drawer rather than using vector shapes](https://github.com/danfickle/openhtmltopdf/pull/121) Thanks @rototor + [Upgraded PDFBOX to 2.0.7, ICU4J to 59.1 and PDFBOX-GRAPHICS2D to 0.7](https://github.com/danfickle/openhtmltopdf/pull/121) Thanks @rototor + [Implemented CSS3 flowing text columns](https://github.com/danfickle/openhtmltopdf/issues/60#issuecomment-310959602) Thanks @miminno ++ [FIX: Don't write miter values of zero into the PDF, fixes dotted/dashed lines in Acrobat Reader](https://github.com/danfickle/openhtmltopdf/issues/135) 0.0.1-RC11 ======== diff --git a/openhtmltopdf-examples/src/main/java/com/openhtmltopdf/testcases/TestcaseRunner.java b/openhtmltopdf-examples/src/main/java/com/openhtmltopdf/testcases/TestcaseRunner.java index 0cec0baa0..cacae41a5 100644 --- a/openhtmltopdf-examples/src/main/java/com/openhtmltopdf/testcases/TestcaseRunner.java +++ b/openhtmltopdf-examples/src/main/java/com/openhtmltopdf/testcases/TestcaseRunner.java @@ -36,9 +36,9 @@ public class TestcaseRunner { * Runs our set of manual test cases. You can specify an output directory with * -DOUT_DIRECTORY=./output for example. Otherwise, the current working * directory is used. Test cases must be placed in src/main/resources/testcases/ - * - * @param args - * @throws Exception + * + * If you only want to run one spefic test, you can specify + * -DONLY_TEST=<testname>. I.e. -DONLY_TEST=adobe-borderstyle-bugs */ public static void main(String[] args) throws Exception { @@ -83,6 +83,11 @@ public static void main(String[] args) throws Exception { */ runTestCase("multi-column-layout"); + /* + * Adobe Borderyle Problem + */ + runTestCase("adobe-borderstyle-bugs"); + /* Add additional test cases here. */ } @@ -199,7 +204,10 @@ public OutputStream supply(int zeroBasedPageNumber) throws IOException { }, BufferedImage.TYPE_INT_ARGB, "PNG")).runPaged(); } - public static void runTestCase(String testCaseFile) throws Exception { + private static void runTestCase(String testCaseFile) throws Exception { + String onlyTest = System.getProperty("ONLY_TEST", ""); + if (!onlyTest.isEmpty() && !onlyTest.equals(testCaseFile)) + return; byte[] htmlBytes = IOUtils .toByteArray(TestcaseRunner.class.getResourceAsStream("/testcases/" + testCaseFile + ".html")); String html = new String(htmlBytes, Charsets.UTF_8); @@ -248,7 +256,8 @@ public void render(Graphics2D graphics2D) { -90, depth); /* - * Now draw some text using different fonts to exercise all different font mappings + * Now draw some text using different fonts to exercise all different font + * mappings */ Font font = Font.decode("Times New Roman").deriveFont(10f); if (depth == 10) @@ -259,13 +268,14 @@ public void render(Graphics2D graphics2D) { font = Font.decode("Dialog"); // Gets mapped to Helvetica graphics2D.setFont(font); String txt = "FanOut " + fanout + " Angle " + angle + " Depth " + depth; - Rectangle2D textBounds = font.getStringBounds(txt, - graphics2D.getFontRenderContext()); + Rectangle2D textBounds = font.getStringBounds(txt, graphics2D.getFontRenderContext()); graphics2D.setPaint(new Color(16, 133, 30)); - GradientPaint gp = new GradientPaint(10.0f, 25.0f, Color.blue, (float) textBounds.getWidth(), (float) textBounds.getHeight(), Color.red); + GradientPaint gp = new GradientPaint(10.0f, 25.0f, Color.blue, + (float) textBounds.getWidth(), (float) textBounds.getHeight(), Color.red); if (angle == 35) graphics2D.setPaint(gp); - graphics2D.drawString(txt, (int)((realWidth - textBounds.getWidth()) / 2), (int)(realHeight - titleBottomHeight)); + graphics2D.drawString(txt, (int) ((realWidth - textBounds.getWidth()) / 2), + (int) (realHeight - titleBottomHeight)); } }); } diff --git a/openhtmltopdf-examples/src/main/resources/testcases/adobe-borderstyle-bugs.html b/openhtmltopdf-examples/src/main/resources/testcases/adobe-borderstyle-bugs.html new file mode 100644 index 000000000..8569a2c33 --- /dev/null +++ b/openhtmltopdf-examples/src/main/resources/testcases/adobe-borderstyle-bugs.html @@ -0,0 +1,29 @@ + + + + + Some Title + + + +The following does not appear in Adobe Reader DC: + + + + +
Hello World
+And this is also missing : + + + + +
Hello World
+ + \ No newline at end of file diff --git a/openhtmltopdf-pdfbox/src/main/java/com/openhtmltopdf/pdfboxout/PdfContentStreamAdapter.java b/openhtmltopdf-pdfbox/src/main/java/com/openhtmltopdf/pdfboxout/PdfContentStreamAdapter.java index 8225aa390..777205f72 100644 --- a/openhtmltopdf-pdfbox/src/main/java/com/openhtmltopdf/pdfboxout/PdfContentStreamAdapter.java +++ b/openhtmltopdf-pdfbox/src/main/java/com/openhtmltopdf/pdfboxout/PdfContentStreamAdapter.java @@ -283,12 +283,15 @@ public void drawImage(PDImageXObject xobject, float x, float y, float w, } public void setMiterLimit(float miterLimit) { - // TODO Not currently supported by PDF-BOX. - // TODO: Use official API when the next version is released. See PDFBOX-3669 try { - cs.appendRawCommands(miterLimit + " M "); + /* + * Only set the miter limit if it is > 0, as 0 is a invalid + * value which causes Acrobat Reader to stop drawing anything. + */ + if( miterLimit > 0.0) + cs.setMiterLimit(miterLimit); } catch (IOException e) { - logAndThrow("drawImage", e); + logAndThrow("setMiterLimit", e); } }