public override void Draw(DrawContext context) { int pageNumber = GetOccupiedArea().GetPageNumber(); Rectangle bbox = GetInnerAreaBBox(); PdfDocument pdf = context.GetDocument(); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdf, true); PdfFormField chk = PdfFormField.CreateRadioButton(pdf, bbox, _group, _value, PdfAConformanceLevel.PDF_A_1B ); chk.SetPage(pageNumber); chk.SetValue("Off"); chk.RegenerateField(); chk.SetVisibility(PdfFormField.VISIBLE); chk.SetBorderColor(ColorConstants.BLACK); chk.SetBackgroundColor(ColorConstants.WHITE); chk.SetReadOnly(true); PdfFormXObject appearance = new PdfFormXObject(bbox); PdfCanvas canvas = new PdfCanvas(appearance, pdf); canvas.SaveState().MoveTo(bbox.GetLeft(), bbox.GetBottom()).LineTo(bbox.GetRight(), bbox.GetBottom()).LineTo (bbox.GetRight(), bbox.GetTop()).LineTo(bbox.GetLeft(), bbox.GetTop()).LineTo(bbox.GetLeft(), bbox.GetBottom ()).SetLineWidth(1f).Stroke().RestoreState(); form.AddFieldAppearanceToPage(chk, pdf.GetPage(pageNumber)); chk.SetAppearance(PdfName.N, "v1".Equals(_value) ? _value : "Off", appearance.GetPdfObject()); }
protected void ManipulatePdf(String dest) { PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest)); Document doc = new Document(pdfDoc); PdfFont font = PdfFontFactory.CreateFont(StandardFonts.HELVETICA); Rectangle rect = new Rectangle(40, 788, 20, 18); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true); // Radio buttons will be added to this radio group PdfButtonFormField radioGroup = PdfFormField.CreateRadioGroup(pdfDoc, "Language", ""); for (int page = 1; page <= LANGUAGES.Length; page++) { pdfDoc.AddNewPage(); // Create a radio button that is added to a radio group. PdfFormField field = PdfFormField.CreateRadioButton(pdfDoc, rect, radioGroup, LANGUAGES[page - 1]); field.SetBorderWidth(1); field.SetBorderColor(ColorConstants.BLACK); // Method specifies on which page the form field's widget must be shown. field.SetPage(page); doc.ShowTextAligned(new Paragraph(LANGUAGES[page - 1]).SetFont(font).SetFontSize(18), 70, 786, page, TextAlignment.LEFT, VerticalAlignment.BOTTOM, 0); } form.AddField(radioGroup); doc.Close(); }
public virtual void PdfA1aCheckFieldOffAppearanceTest() { String name = "pdfA1a_checkFieldOffAppearance"; String outPath = destinationFolder + name + ".pdf"; String cmpPath = cmpFolder + "cmp_" + name + ".pdf"; String diff = "diff_" + name + "_"; PdfWriter writer = new PdfWriter(outPath); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1A, new PdfOutputIntent("Custom", "" , "http://www.color.org", "sRGB IEC61966-2.1", @is)); doc.SetTagged(); doc.GetCatalog().SetLang(new PdfString("en-US")); doc.AddNewPage(); PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true); PdfFormField chk = PdfFormField.CreateCheckBox(doc, new Rectangle(100, 500, 50, 50), "name", "Off", PdfFormField .TYPE_CHECK, PdfAConformanceLevel.PDF_A_1A); chk.SetBorderColor(ColorConstants.BLACK); chk.SetBorderWidth(1); form.AddField(chk); doc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff )); }
private void AddCheckBox(PdfDocument pdfDoc, float fontSize, float yPos, float checkBoxW, PdfFormField checkBox ) { PdfPage page = pdfDoc.GetFirstPage(); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true); if (fontSize >= 0) { checkBox.SetFontSize(fontSize); } checkBox.SetBorderWidth(1); checkBox.SetBorderColor(ColorConstants.BLACK); form.AddField(checkBox, page); PdfCanvas canvas = new PdfCanvas(page); canvas.SaveState().BeginText().MoveText(50 + checkBoxW + 10, yPos).SetFontAndSize(PdfFontFactory.CreateFont (), 12).ShowText("okay?").EndText().RestoreState(); }