Interesting PDF bugs – where are my missing lines

I have been looking at a customer PDF where we did not display the filled lines on the page. Firing up my debug tools showed that the lines were being converted to shapes and the clip and the color was correct. So where are the lines?

It turned out that because the lines had a width or height of 1 and a stroke width of less than 1, they were not being drawn. Or rather they were being drawn but with no width and no pixels. The fix is to use fillRect as this code snippet shows


//thin lines do not appear unless we use fillRect
if(currentShape.getBounds().getHeight()

g2.fillRect(currentShape.getBounds().x, currentShape.getBounds().y, currentShape.getBounds().width, currentShape.getBounds().height);

}else{
g2.fill(currentShape);
}

And the lines now appear! More of a Java bug, but still interesting… Have you seen any similar bugs with thin lines in Java?

Related Posts:

The following two tabs change content below.

Mark Stephens

System Architect and Lead Developer at IDRSolutions
Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX. He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.
Markee174

About Mark Stephens

Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX.

He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>