DottedLine implements ILineDrawer { @Override public void draw(PdfCanvas canvas, Rectangle drawArea) { canvas.saveState() .setLineWidth(lineWidth) .setStrokeColor(color) .setLineDash(0, gap, gap / 2) .setLineCapStyle(PdfCanvasConstants.LineCapStyle.ROUND) .moveTo(drawArea.getX(), drawArea.getY() + lineWidth / 2) .lineTo(drawArea.getX() + drawArea.getWidth(), drawArea.getY() + lineWidth / 2) .stroke() .restoreState(); } DottedLine();  DottedLine(float lineWidth, float gap);  DottedLine(float lineWidth); @Override void draw(PdfCanvas canvas, Rectangle drawArea); float getGap(); void setGap(float gap); float getLineWidth(); void setLineWidth(float lineWidth); @Override Color getColor(); @Override void setColor(Color color);  }
@Test public void dottedLineDrawTest01() { String expectedContent = "q\n" + "15 w\n" + "0 0 0 RG\n" + "[0 5] 2.5 d\n" + "1 J\n" + "100 107.5 m\n" + "200 107.5 l\n" + "S\n" + "Q\n"; PdfDocument tempDoc = new PdfDocument(new PdfWriter(new ByteArrayOutputStream())); PdfCanvas canvas = new PdfCanvas(tempDoc.addNewPage()); DottedLine dottedLine = new DottedLine(15, 5); dottedLine.draw(canvas, new Rectangle(100, 100, 100, 100)); byte[] writtenContentBytes = canvas.getContentStream().getBytes(); Assert.assertArrayEquals(expectedContent.getBytes(), writtenContentBytes); }