Skip to main content
Skip table of contents

How to add a full line break?

I use itextsharp and I need to draw a dotted line break from the left to the right of the page (100% width) but I don't know how to do this. The document always has a margin to the left and the right.

Chunk linebreak = new Chunk(new DottedLineSeparator());

Posted on StackOverflow on Nov 27, 2013 by nam vo

Please take a look at the example FullDottedLine. You're creating a DottedLineSeparator of which the width percentage is 100% by default. This 100% is the full available width within the margins of the page. If you want the line to exceed the available width, you need a percentage that is higher than 100%.

In iText 7 DottedLineSeparator class does not exist anymore, but we have DottedLine class that draws a dotted line. You require a custom width of the line depending on the page size. The easiest way to set it, is by extending the DottedLine class and introducing an extra parameter:

class CustomDottedLine extends DottedLine {
    protected Rectangle pageSize;

    public CustomDottedLine(Rectangle pageSize) {
        this.pageSize = pageSize;

    public void draw(PdfCanvas canvas, Rectangle drawArea) {
        super.draw(canvas, new Rectangle(pageSize.getLeft(), drawArea.getBottom(), pageSize.getWidth(), drawArea.getHeight()));

Take a look at the resulting pdf and you'll see that the line now runs through the margins.

Click How to add a full line break? if you want to see how to answer this question in iText 5.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.