且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过iTextSharp在pdf中生成单选按钮。

更新时间:2023-09-29 17:58:40

查看此帖子

http://***.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://***.com/questions/13245208/how-to-create-pdfformfields-using-itextsharp[^]