itextsharp 如何添加完整换行符

问题描述 投票:0回答:1

我使用itextsharp,我需要从页面的左到右绘制一个虚线分隔符(100%宽度),但不知道如何。文档总是左右留有边距。请帮忙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(""));
           ....
}
c# itext
1个回答
0
投票

请看一下示例FullDottedLine

您正在创建一个

DottedLineSeparator
,其宽度百分比默认为 100%。这个 100% 是完整的可用宽度与页面边距。如果您希望线条超出可用宽度,则需要高于 100% 的百分比。

在示例中,使用默认页面尺寸 (A4) 和默认边距 (36)。这意味着页面宽度为 595 个用户单位,可用宽度等于 595 - (2 x 36) 个用户单位。跨越页面整个宽度所需的百分比等于 100 x (595 / 523)。

查看生成的 PDF 文件 full_dotted_line.pdf,您会发现该线现在穿过了页边距。

© www.soinside.com 2019 - 2024. All rights reserved.