【发布时间】:2014-08-07 19:18:21
【问题描述】:
我认为这可能是一个错误,但如果有人可以提供帮助,我将不胜感激。我目前还有一个处理类似问题的未解决问题,但我认为这个问题更好地说明了这个问题,而且也更简单。话虽如此,我不想删除旧的,以防它增加我的等待时间。我让模组决定哪个问题更好。
这是一个创建 pdf 的示例应用程序,然后是一个表格。它将一个单元格添加到表格中,然后将字段定位事件与单元格事件联系起来。
using System;
using System.Diagnostics;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
namespace iTextSharpTextBoxInTableCell
{
class Program
{
static void Main(string[] args)
{
// Create a PDF with a TextBox in a table cell
BaseFont bfHelvetica = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, false);
Font helvetica12 = new Font(bfHelvetica, 12, Font.NORMAL, BaseColor.BLACK);
Document doc = new Document(PageSize.LETTER, 18f, 18f, 18f, 18f);
FileStream fs = new FileStream("TextBoxInTableCell.pdf", FileMode.Create);
PdfWriter writer = PdfWriter.GetInstance(doc, fs);
doc.Open();
PdfPTable myTable = new PdfPTable(1);
myTable.TotalWidth = 568f;
myTable.LockedWidth = true;
myTable.HorizontalAlignment = 0;
TextField tf = new TextField(writer, new iTextSharp.text.Rectangle(67, 585, 140, 800), "cellTextBox");
tf.Text = "test";
PdfPCell tbCell = new PdfPCell(new Phrase(" ", helvetica12));
iTextSharp.text.pdf.events.FieldPositioningEvents events =
new iTextSharp.text.pdf.events.FieldPositioningEvents(writer, tf.GetTextField());
tbCell.CellEvent = events;
myTable.AddCell(tbCell);
doc.Add(myTable);
doc.Close();
fs.Close();
Process.Start("TextBoxInTableCell.pdf");
Console.WriteLine("End Of Program Execution");
Console.ReadLine();
}
}
}
这是该字段生成时的样子:
如您所见,文本被压扁了。我已经发布了生成的 pdf here.
【问题讨论】:
标签: c# pdf pdf-generation itextsharp