Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw dotted line in pdfBox

Tags:

java

pdf

pdfbox

I'm using Pdfbox to draw some line on my document. Code:

contentStream.drawLine(startX, startY, startX, endY);

The result is an straight line. I wonder Does the PdfBox can draw dotted line?

like image 626
Ranga Ron Avatar asked Jun 02 '15 08:06

Ranga Ron


1 Answers

Use the setLineDashPattern() call before doing your drawLine call:

public void setLineDashPattern(float[] pattern, float phase)

example:

setLineDashPattern (new float[]{3}, 0);

will configure a line pattern with 3 on, 3 off, 3 on, 3 off, etc

setLineDashPattern (new float[]{3,1}, 0);

will configure a line pattern with 3 on, 1 off, 3 on, etc

for more details on dash patterns, see the PDF specification.

like image 139
Tilman Hausherr Avatar answered Oct 25 '22 19:10

Tilman Hausherr