Why are my lines disappearing when I switch the deprecated drawLine() method for the version with moveTo / lineTo / stroke in Apache PDFBox 2.x?
<p>I am creating a table by this example: <a href="http://fahdshariff.blogspot.de/2010/10/creating-tables-with-pdfbox.html" rel="nofollow noreferrer">http://fahdshariff.blogspot.de/2010/10/creating-tables-with-pdfbox.html</a></p>

<p>Now I've switched from Apache PDFBox 1.8 to 2.0, so some methods now are deprecated, including the <code>drawLine()</code>-method.</p>

<p>The <a href="https://pdfbox.apache.org/docs/2.0.0/javadocs/deprecated-list.html" rel="nofollow noreferrer">API changelog states</a> that you have to use a combination of 3 other methods now to accomplish the task of drawing a line:</p>

<pre><code>org.apache.pdfbox.pdmodel.PDPageContentStream.drawLine(float, float, float, float):
Use PDPageContentStream.moveTo(float, float) 
followed by PDPageContentStream.lineTo(float, float) 
followed by PDPageContentStream.stroke()
</code></pre>

<p>Therefore I've changed this line</p>

<pre><code>final float tableWidth = page.findMediaBox().getWidth() - (2 * margin);
</code></pre>

<p>to this line:</p>

<pre><code>final float tableWidth = page.getMediaBox().getWidth() - (2 * margin);
</code></pre>

<p>And changing these 2 lines</p>

<pre><code>// draw the rows
contentStream.drawLine(margin, nexty, margin + tableWidth, nexty);
(...)
// draw the columns
contentStream.drawLine(nextx, y, nextx, y - tableHeight);
</code></pre>

<p>to this:</p>

<pre><code>// draw the rows
contentStream.moveTo(margin, nexty);
contentStream.lineTo(margin, nexty);
contentStream.stroke();
(...)
// draw the columns
contentStream.moveTo(nextx, y - tableHeight);
contentStream.lineTo(nextx, y - tableHeight);
contentStream.stroke();
</code></pre>

<p>But if I do this, all the lines are gone and dont appear in the PDF:</p>

<p><a href="https://i.stack.imgur.com/zvJK3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zvJK3.png" alt="emptyLines"></a></p>

<p>Strangely, if I mix the deprecated <code>drawLine()</code>-method with the <code>moveTo / lineTo / stroke</code>-methods, I can get either the rows OR the columns:</p>

<pre><code>// draw the rows
float nexty = y;
for (int i = 0; i &lt;= rows; i++) {
    contentStream.drawLine(margin, nexty, margin + tableWidth, nexty);
    // contentStream.moveTo(margin, nexty);
    // contentStream.lineTo(margin, nexty);
    // contentStream.stroke();
    nexty -= rowHeight;
}

// draw the columns
float nextx = margin;
for (int i = 0; i &lt;= cols; i++) {
    // contentStream.drawLine(nextx, y, nextx, y - tableHeight);
    contentStream.moveTo(nextx, y - tableHeight);
    contentStream.lineTo(nextx, y - tableHeight);
    contentStream.stroke();
    nextx += colWidth;
}
</code></pre>

<p>Has this result:</p>

<p><a href="https://i.stack.imgur.com/YbCg3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YbCg3.png" alt="rowLines"></a></p>

<p>Switching on the deprecated <code>drawLine</code>-method for the columns</p>

<pre><code>// draw the rows
float nexty = y;
for (int i = 0; i &lt;= rows; i++) {
    // contentStream.drawLine(margin, nexty, margin + tableWidth,
    // nexty);
    contentStream.moveTo(margin, nexty);
    contentStream.lineTo(margin, nexty);
    contentStream.stroke();
    nexty -= rowHeight;
}

// draw the columns
float nextx = margin;
for (int i = 0; i &lt;= cols; i++) {
    contentStream.drawLine(nextx, y, nextx, y - tableHeight);
    // contentStream.moveTo(nextx, y - tableHeight);
    // contentStream.lineTo(nextx, y - tableHeight);
    // contentStream.stroke();
    nextx += colWidth;
}
</code></pre>

<p>has this result:</p>

<p><a href="https://i.stack.imgur.com/mndzi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mndzi.png" alt="columnLines"></a></p>

<p>So the maths behind this for drawin the lines seems to be okay. But somehow there is a side-effect I'm not understanding, so the lines disappear?</p>

<p>How can I switch the deprecated <code>drawLine</code>-method to a non-deprecated version?</p>

<p>The example-code is a <a href="https://stackoverflow.com/help/mcve">MVCE</a>, so if you want to test my problem, simply copy the example code from here into the editor of your choice: <a href="http://fahdshariff.blogspot.de/2010/10/creating-tables-with-pdfbox.html" rel="nofollow noreferrer">http://fahdshariff.blogspot.de/2010/10/creating-tables-with-pdfbox.html</a></p>