【问题标题】:setsimplecolumn doesn't position the text to the given coordinates in PDF using itextsharp 5 in C#setsimplecolumn 不使用 C# 中的 itextsharp 5 将文本定位到 PDF 中的给定坐标
【发布时间】:2021-05-27 18:02:10
【问题描述】:

我是 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();

【问题讨论】:

  • “不知何故,第二列没有定位到给定的 x 坐标” - 你到底是什么意思? ct2 应该从x=29ct3 开始定位到x=220。这不会发生吗?
  • x=455.5 at ct3 没有发生。

标签: c# .net pdf itext


【解决方案1】:

显然对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);

【讨论】:

  • 感谢您的帮助!是的,关于论点有一个误解,我的问题现在已经解决了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-05
  • 1970-01-01
  • 2022-08-16
  • 1970-01-01
  • 2011-06-02
相关资源
最近更新 更多