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.

31st May 2016


Horizontal line 100% width

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 this link if you want to see how to answer this question in iText 5.


Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now