2014-03-05 2 views
1

C# 용 iTextSharp 라이브러리를 사용하여 하나의 확인란 만 추가하려고합니다. 몇 가지 예를 살펴보고 수정하려고 시도 했으므로 그룹의 확인란을 만드는 방법을 보여줍니다. 하나만 만들려면 어떻게해야합니까?iTextSharp와 함께 하나의 확인란을 추가하십시오.

private static void WriteFooter(Document doc, int page, int maxPages, bool lastPage, PdfWriter writer, PdfAppearance[] checkBoxAppearance) 
    { 
     if(!lastPage) 
     { 
      doc.Add(new Paragraph("\nMA-2028.1-F2(Portrait) Page " + page + " of " + maxPages, Fonts.ExtraSmall)); 
      doc.NewPage(); 
     } else 
     { 
      PdfContentByte cb = writer.DirectContent; 
      PdfFormField _checkGroup = PdfFormField.CreateRadioButton(writer, true); 
      RadioCheckField _radioG; 
      PdfFormField _radioField1; 
      _radioG = new RadioCheckField(writer, new Rectangle(20, 20), null, "Yes"); 
      _radioG.CheckType = RadioCheckField.TYPE_CHECK; 
      _radioField1 = _radioG.RadioField; 
      _checkGroup.AddKid(_radioField1); 
      ColumnText.ShowTextAligned(cb, Element.ALIGN_RIGHT, new Phrase("No Users Require Deletion"), 20, 20, 0); 
      writer.AddAnnotation(_checkGroup); 
      cb = writer.DirectContent; 
      doc.Add(
       new Paragraph(
        "Operations Management:\n\n", Fonts.Small) { Alignment = Element.ALIGN_CENTER }); 
      doc.Add(
       new Paragraph(
        "Automation Manager or Designee: \n\n", Fonts.Small) { Alignment = Element.ALIGN_CENTER }); 
     } 
    } 

작성자 및 checkBoxAppearance는 다른 함수에서 전달됩니다. 이전에 코드에서 체크 박스가있는 테이블을 만들었지 만이 테이블 외부에 하나를 추가해야합니다. 나는 코드를 따랐다 http://simpledotnetsolutions.wordpress.com/2012/11/01/itextsharp-creating-form-fields/

checkboxAppearance는 체크 박스의 동작을 정의하는 배열이다.

그리고 하나의 체크 박스 만 수정하려고했습니다. 그 옆에 텍스트가 표시되도록하려고합니다.

편집 : 나는이를 시도하고있다 :

private static void WriteFooter(Document doc, int page, int maxPages, bool lastPage, PdfWriter writer, PdfFormField checkboxField, PdfAppearance[] checkbox, PdfContentByte cb) 
    { 
     if(!lastPage) 
     { 
      doc.Add(new Paragraph("\nMA-2028.1-F2(Portrait) Page " + page + " of " + maxPages, Fonts.ExtraSmall)); 
      doc.NewPage(); 
     } else 
     { 
      PdfFormField field; 
      RadioCheckField checkBox; 

      for (int i = 0; i < 1; i++) 
      { 
       checkBox = new RadioCheckField(writer, new Rectangle(20, 20), "noDelete", "Yes"); 
       field = checkBox.CheckField; 
       field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", checkbox[0]); 
       field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Yes", checkbox[1]); 
       writer.AddAnnotation(field); 
       //ColumnText.ShowTextAligned(cb, Element.ALIGN_RIGHT, new Phrase("No Users Need Deletion"), 210, 790, 0); 
      } 
      doc.Add(
       new Paragraph(
        "Operations Management:\n\n", Fonts.Small) { Alignment = Element.ALIGN_CENTER }); 
      doc.Add(
       new Paragraph(
        "Automation Manager or Designee:\n\n", Fonts.Small) { Alignment = Element.ALIGN_CENTER }); 
     } 
    } 

답변

4

신경 쓰지 마십시오, 내가 더 좋은 방법을 발견했다. 내 솔루션은 테이블에 확인란을 넣고 그런 식으로 PDF에 추가하는 것이 었습니다. 상사가 원래 원했던 방식보다 훨씬 깨끗해 보입니다.

private static void WriteFooter(Document doc, int page, int maxPages, bool lastPage, PdfWriter writer, PdfFormField checkboxField, PdfAppearance[] checkbox, PdfContentByte cb) 
    { 
     if(!lastPage) 
     { 
      doc.Add(new Paragraph("\nMA-2028.1-F2(Portrait) Page " + page + " of " + maxPages, Fonts.ExtraSmall)); 
      doc.NewPage(); 
     } else 
     { 
      PdfFormField footerField = PdfFormField.CreateEmpty(writer); 
      PdfPTable footerTbl = new PdfPTable(2); 
      float[] footerWidths = new float[] { 1f, 4f }; 
      PdfPCell noDeleteCell = new PdfPCell(); 
      PdfPCell noDeleteText = new PdfPCell(new Paragraph("No Users Require Deletion", Fonts.Small)); 
      RadioCheckField fCell = new RadioCheckField(writer, new Rectangle(20, 20), "NoDeletion", "Yes"); 
      fCell.CheckType = RadioCheckField.TYPE_CROSS; 
      PdfFormField footerCheck = null; 
      footerCheck = fCell.CheckField; 
      footerCheck.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", checkbox[0]); 
      footerCheck.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Yes", checkbox[1]); 
      noDeleteCell.CellEvent = new ChildFieldEvent(footerField, footerCheck, 1, 20, 20); 
      footerField.FieldName = "no_delete_table"; 
      footerTbl.SetWidths(footerWidths); 
      footerTbl.AddCell(noDeleteCell); 
      footerTbl.AddCell(noDeleteText); 
      doc.Add(footerTbl); 
      writer.AddAnnotation(footerField); 
      doc.Add(
       new Paragraph(
        "\n\nOperations Management: _______________________________________________ Date: ___________\n\n", Fonts.Small) { Alignment = Element.ALIGN_CENTER }); 
      doc.Add(
       new Paragraph(
        "Automation Manager or Designee: _______________________________________________ Date: ___________\n\n", Fonts.Small) { Alignment = Element.ALIGN_CENTER }); 
      doc.Add(new Paragraph("\nMA-2028.1-F2(Portrait) Page " + page + " of " + maxPages, Fonts.ExtraSmall)); 
     } 
    } 
+0

iTextSharp v5.5.11에서 작동하지 않는 것은 정말 수치스러운 일입니다. – CarneyCode

관련 문제