我使用 itextsharp,我需要从页面的左到右绘制一条虚线(100% 宽度),但不知道如何绘制。文档总是有左右边距。请帮忙
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(""));
....
}
最佳答案
请看例子FullDottedLine .
您正在创建一个 DottedLineSeparator
,其宽度百分比默认为 100%。这 100% 是整个可用宽度页面边距。如果您希望线条超过可用宽度,则需要一个高于 100% 的百分比。
在示例中,使用了默认页面大小 (A4) 和默认页边距 (36)。这意味着页面的宽度为 595 个用户单位,可用宽度等于 595 - (2 x 36) 个用户单位。跨越整个页面宽度所需的百分比等于 100 x (595/523)。
查看生成的 PDF 文件 full_dotted_line.pdf您会看到该线现在穿过页边距。
关于c# - itextsharp 如何添加一个完整的换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20233630/