setsimplecolumn 不会使用 C# 中的 itextsharp 5 将文本定位到 PDF 中的给定坐标

setsimplecolumn doesn't position the text to the given coordinates in PDF using itextsharp 5 in C#

我是 iTextShap 的新手,我正在尝试使用 SetSimpleColumn 添加两个文本列,但不知何故第二列没有定位到给定的 x 坐标。我已经浏览了互联网上的很多内容,我正在使用的版本 (5.5.13.2) 的 iTextSharp 文档并不多。

下面是我写的代码,有什么我遗漏的吗?任何帮助将不胜感激,谢谢!

Font f = new Font(baseFont, 8);

ColumnText ct2 = new ColumnText(writer.DirectContent);
ct2.SetSimpleColumn(29f, 587f, 220f, 100f, 11f, 0);
ct2.AddText(new Paragraph("PATIENT'S NAME:", f));
ct2.AddText(Chunk.NEWLINE);
ct2.AddText(new Paragraph("Street Address:", f));
ct2.AddText(Chunk.NEWLINE);
ct2.AddText(new Paragraph("Address 2:", f));
ct2.AddText(Chunk.NEWLINE);
ct2.AddText(new Paragraph("City, State:", f));
ct2.AddText(Chunk.NEWLINE);
ct2.AddText(new Paragraph("Zip Code:", f));
ct2.AddText(Chunk.NEWLINE);
ct2.AddText(new Paragraph("Telephone:", f));
ct2.Go();

ColumnText ct3 = new ColumnText(writer.DirectContent);
ct3.SetSimpleColumn(455.5f, 587f, 220f, 100f, 11f, 2);
ct3.AddText(new Paragraph("PRACTICE:", f) { Alignment = 0});
ct3.AddText(Chunk.NEWLINE);
ct3.AddText(new Paragraph("Street Address:", f));
ct3.AddText(Chunk.NEWLINE);
ct3.AddText(new Paragraph("Address 2:", f));
ct3.AddText(Chunk.NEWLINE);
ct3.AddText(new Paragraph("City, State:", f));
ct3.AddText(Chunk.NEWLINE);
ct3.AddText(new Paragraph("Zip Code:", f));
ct3.AddText(Chunk.NEWLINE);
ct3.AddText(new Paragraph("Telephone:", f));
ct3.AddText(Chunk.NEWLINE);
ct3.AddText(new Paragraph("Fax:", f));
ct3.Go();

显然对 SetSimpleColumn 方法的参数存在误解,您似乎假设前四个参数是 x, y, width, height。但实际上,它们是 x₁, y₁, x₂, y₂。因此,当你

ct3.SetSimpleColumn(455.5f, 587f, 220f, 100f, 11f, 2);

您使该列从 x=220 开始并在 x=455.5 结束。

你想要的,更有可能是

ct3.SetSimpleColumn(455.5f, 587f, 455.5f + 220f, 587f + 100f, 11f, 2);