我想在pdf行中画一条虚线。
虚线很好,但它的绘图在顶部有很多空间。
我试图删除这些空格但无法删除。
我使用下面的代码绘制虚线::
class CustomDashedLineSeparator extends DottedLineSeparator {
protected float dash = 5;
protected float phase = 0.5f;
public float getDash() {
return dash;
}
public float getPhase() {
return phase;
}
public void setDash(float dash) {
this.dash = dash;
}
public void setPhase(float phase) {
this.phase = phase;
}
@Override
public void draw(PdfContentByte canvas, float llx, float lly, float urx, float ury, float y) {
canvas.saveState();
canvas.setLineWidth(lineWidth);
canvas.setLineDash(dash, gap, phase);
drawLine(canvas, llx, urx, y);
canvas.restoreState();
}
}
Chunk lineSeperatorChunk = getLineSeperatorCell();
PdfPCell lineSeperatorCell = new PdfPCell();
lineSeperatorCell.addElement(lineSeperatorChunk);
private static Chunk getLineSeperatorCell() {
CustomDashedLineSeparator separator = new CustomDashedLineSeparator();
separator.setDash(2);
separator.setGap(2);
separator.setLineWidth((float) 0.1);
return new Chunk(separator);
}