5

I use itextsharp and i need to draw a dotted linebreak from left to right of the page(100% width) but don't know how. The doc always has a margin left right. Please help enter image description here

var pageSize = PageSize.A4;

        if (_pdfSettings.LetterPageSizeEnabled)
        {
            pageSize = PageSize.LETTER;
        }


        var doc = new Document(pageSize);
        PdfWriter.GetInstance(doc, stream);
        doc.Open();

        //fonts

        var titleFont = GetFont();
        titleFont.SetStyle(Font.BOLD);
        titleFont.Color = BaseColor.BLACK;
        titleFont.Size = 16;

        var largeFont = GetFont();
        largeFont.SetStyle(Font.BOLD);
        largeFont.Color = BaseColor.BLACK;
        largeFont.Size = 18;

        int ordCount = orders.Count;
        int ordNum = 0;

        foreach (var order in orders)
        {

            var addressTable = new PdfPTable(3);
            addressTable.WidthPercentage = 100f;
            addressTable.SetWidths(new[] { 25, 37, 37 });


            // sender address

            cell = new PdfPCell();
            //cell.Border = Rectangle.NO_BORDER;
            cell.AddElement(new Paragraph("Người Gửi", titleFont));
            cell.AddElement(new Paragraph(_localizationService.GetResource("admin.orders.pdfinvoice.sender", lang.Id), smallFont));
            cell.AddElement(new Paragraph(_localizationService.GetResource("admin.orders.pdfinvoice.senderaddress", lang.Id), smallFont));
            cell.AddElement(new Paragraph(_localizationService.GetResource("PDFInvoice.Hotline", lang.Id), smallFont));
            cell.AddElement(new Paragraph("TAKARA.VN", largeFont));

            addressTable.AddCell(cell);

            ......
           Chunk linebreak = new Chunk(new DottedLineSeparator());
                doc.Add(linebreak);   

                doc.Add(new Paragraph(""));
           ....
}
nam vo
  • 3,271
  • 12
  • 49
  • 76

1 Answers1

0

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 withing 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 the example, the default page size (A4) and the default margins (36) are used. This means that the width of the page is 595 user units and the available width equals 595 - (2 x 36) user units. The percentage needed to span the complete width of the page equals 100 x (595 / 523).

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

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165