通过iTextSharp在pdf中生成单选按钮。 [英] Generate radio button inside pdf through iTextSharp.
本文介绍了通过iTextSharp在pdf中生成单选按钮。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在通过iTextSharp创建一个可编辑的pdf表单我可以在其中创建文本框但是我试图在it.code中创建单选按钮我正在使用:
使用(文档文档= new 文档())
{
PdfWriter writer = PdfWriter.GetInstance(文件,ms);
document.Open();
PdfPCell cell;
TextField tf;
RadioCheckField rd;
Phrase phSec;
iTextSharp.text.pdf.events.FieldPositioningEvents事件;
PdfPTable表;
字体f;
bool aa = true ;
bool bb = true ;
BaseFont bf = BaseFont.CreateFont(BaseFont.TIMES_ROMAN,BaseFont.CP1252, false );
iTextSharp.text.Image img;
// 对于徽标nad主要标题
table = new PdfPTable( 2 );
table.SetWidths( new int [] { 2 , 6 });
img = iTextSharp.text.Image.GetInstance(Server.MapPath( 〜/ logo .gif注意跨度>));
table.AddCell(img);
cell = new PdfPCell();
cell.BackgroundColor = BaseColor.WHITE;
cell.PaddingLeft = 40f;
cell.PaddingTop = 10f;
cell.BorderWidthLeft = 0f;
phSec = new 短语( 患者信息系统跨度>);
f = new 字体(bf,15f,Font.BOLD);
phSec.Font = f;
cell.Phrase = new 短语(phSec);
cell.PaddingBottom = 7f;
table.AddCell(cell);
// img = iTextSharp.text.Image.GetInstance(Server.MapPath(〜 /QR.png));
// img.ScaleToFit(25f,15f) ;
// table.AddCell(img);
document.Add(table);
// 结束
/ / 对于章节标题-----个人详细信息
table = new PdfPTable( 2 );
table.SetWidths( new int [] { 2 , 8 });
cell = new PdfPCell();
cell.BackgroundColor = BaseColor.LIGHT_GRAY;
cell.BorderWidthRight = 0f;
phSec = new 短语( A部分跨度>);
f = new 字体(bf,10f,Font.BOLD);
phSec.Font = f;
cell.Phrase = new 短语(phSec);
cell.PaddingBottom = 7f;
table.AddCell(cell);
cell = new PdfPCell();
cell.BackgroundColor = BaseColor.LIGHT_GRAY;
cell.BorderWidthLeft = 0f;
cell.Phrase = new 短语( 个人资料);
cell.PaddingBottom = 7f;
table.AddCell(cell);
document.Add(table);
// Section Header Ends
table = new PdfPTable( 4 );
table.SetWidths( new int [] { 2 , 3 , 2 , 3 });
table.AddCell( 名称:);
cell = new PdfPCell();
tf = new TextField(writer, new 矩形( 10 , 15 ), txtFName跨度>);
events = new iTextSharp.text.pdf.events.FieldPositioningEvents(writer,
tf.GetTextField());
cell.CellEvent = events;
table.AddCell(cell);
table.AddCell( 性别:);
cell = new PdfPCell();
// tf = new TextField(writer,new Rectangle(10,15),radGender);
rd = new RadioCheckField(writer, new Rectangle( 10 , 10 ), gender, 否);
events = new iTextSharp.text.pdf.events.FieldPositioningEvents(writer,
rd.GetRadioGroup( false , true ));
cell.CellEvent = events;
table.AddCell(cell);
document.Add(table);
}
File.WriteAllBytes(Server.MapPath( 〜/ FilledformRadio.pdf),ms.ToArray());
名称的文本框创建成功但不是单选按钮。
如果有人有任何想法请帮助....
解决方案
查看此帖子
http://stackoverflow.com/questions/13245208/how-to-create-pdfformfields-using-itextsharp [ ^ ]
hi i am creating a editable pdf form through iTextSharp i am able to create textboxes inside it but iam trying to create radio buttons inside it.code that i am using as:
using (Document document = new Document())
{
PdfWriter writer = PdfWriter.GetInstance(document, ms);
document.Open();
PdfPCell cell;
TextField tf;
RadioCheckField rd;
Phrase phSec;
iTextSharp.text.pdf.events.FieldPositioningEvents events;
PdfPTable table;
Font f;
bool aa=true;
bool bb=true;
BaseFont bf = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
iTextSharp.text.Image img;
//For Logo nad Main Foem Header
table = new PdfPTable(2);
table.SetWidths(new int[] { 2, 6});
img = iTextSharp.text.Image.GetInstance(Server.MapPath("~/logo.gif"));
table.AddCell(img);
cell = new PdfPCell();
cell.BackgroundColor = BaseColor.WHITE;
cell.PaddingLeft = 40f;
cell.PaddingTop = 10f;
cell.BorderWidthLeft = 0f;
phSec = new Phrase("Patient Information System");
f = new Font(bf, 15f, Font.BOLD);
phSec.Font = f;
cell.Phrase = new Phrase(phSec);
cell.PaddingBottom = 7f;
table.AddCell(cell);
//img = iTextSharp.text.Image.GetInstance(Server.MapPath("~/QR.png"));
//img.ScaleToFit(25f, 15f);
//table.AddCell(img);
document.Add(table);
// End
// For Section Header ----- Personal Details
table = new PdfPTable(2);
table.SetWidths(new int[] { 2, 8 });
cell = new PdfPCell();
cell.BackgroundColor = BaseColor.LIGHT_GRAY;
cell.BorderWidthRight = 0f;
phSec = new Phrase("Section A");
f = new Font(bf, 10f, Font.BOLD);
phSec.Font = f;
cell.Phrase = new Phrase(phSec);
cell.PaddingBottom = 7f;
table.AddCell(cell);
cell = new PdfPCell();
cell.BackgroundColor = BaseColor.LIGHT_GRAY;
cell.BorderWidthLeft = 0f;
cell.Phrase = new Phrase("Personal Details");
cell.PaddingBottom = 7f;
table.AddCell(cell);
document.Add(table);
// Section Header Ends
table = new PdfPTable(4);
table.SetWidths(new int[] { 2, 3, 2, 3 });
table.AddCell("Name:");
cell = new PdfPCell();
tf= new TextField(writer, new Rectangle(10, 15), "txtFName");
events = new iTextSharp.text.pdf.events.FieldPositioningEvents(writer,
tf.GetTextField());
cell.CellEvent = events;
table.AddCell(cell);
table.AddCell("gender:");
cell = new PdfPCell();
//tf = new TextField(writer, new Rectangle(10, 15), "radGender");
rd = new RadioCheckField(writer, new Rectangle(10, 10), "gender", "No");
events = new iTextSharp.text.pdf.events.FieldPositioningEvents(writer,
rd.GetRadioGroup(false,true));
cell.CellEvent = events;
table.AddCell(cell);
document.Add(table);
}
File.WriteAllBytes(Server.MapPath("~/FilledformRadio.pdf"), ms.ToArray());
textbox for name is creating successfully but not radio button.
If anybody have any idea plz help....
解决方案
check this post
http://stackoverflow.com/questions/13245208/how-to-create-pdfformfields-using-itextsharp[^]
这篇关于通过iTextSharp在pdf中生成单选按钮。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文