本文介绍了ITextSharp - PdfPCell中的文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在使用iTextSharp创建PDF,如何将textField添加到PdfPCell中?I'm using iTextSharp to create a PDF, how can I add a textField into PdfPCell?推荐答案给这个尝试。它对我有用。Give this a try. It works for me.Document doc = new Document(PageSize.LETTER, 18f, 18f, 18f, 18f);MemoryStream ms = new MemoryStream();PdfWriter writer = PdfWriter.GetInstance(doc, ms);doc.Open();// Create your PDFPTable here....TextField tf = new TextField(writer, new iTextSharp.text.Rectangle(67, 585, 140, 800), "cellTextBox");PdfPCell tbCell = new PdfPCell();iTextSharp.text.pdf.events.FieldPositioningEvents events = new iTextSharp.text.pdf.events.FieldPositioningEvents(writer, tf.GetTextField());tbCell.CellEvent = events;myTable.AddCell(tbCell);// More code...我改编了这段代码这篇文章。 编辑:这是一个完整的工作控制台应用程序,它将TextBox放在表格单元格中。我试图将代码保持在最低限度。Here is a full working console application that puts a TextBox in a table cell. I tried to keep the code to a bare minimum.using System;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, Color.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"); 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(); Console.WriteLine("End Of Program Execution"); Console.ReadLine(); } }}机遇 这篇关于ITextSharp - PdfPCell中的文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-03 14:07