Skip to content

Commit

Permalink
Fix #135: Don't write a MiterLimit of 0 into the PDF, as Acrobat Read…
Browse files Browse the repository at this point in the history
…er does

not like that and stops rendering everything ...
  • Loading branch information
rototor committed Oct 8, 2017
1 parent 8767967 commit c3f89f2
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -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
========
Expand Down
Expand Up @@ -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 {

Expand Down Expand Up @@ -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. */
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand All @@ -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));
}
});
}
Expand Down
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>Some Title</title>
<style>
.dotted {
border: 2px dotted #dddddd;
}
.dashed {
border: 2px dashed #dddddd;
}
</style>
</head>
<body>
The following does not appear in Adobe Reader DC:
<table>
<tr>
<td class="dashed">Hello World</td>
</tr>
</table>
And this is also missing :
<table>
<tr>
<td class="dotted">Hello World</td>
</tr>
</table>
</body>
</html>
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit c3f89f2

Please sign in to comment.