/* (non-Javadoc) * @see com.itextpdf.html2pdf.attach.impl.layout.form.renderer.AbstractFormFieldRenderer#applyAcroField(com.itextpdf.layout.renderer.DrawContext) */ protected internal override void ApplyAcroField(DrawContext drawContext) { String value = GetDefaultValue(); String name = GetModelId(); UnitValue fontSize = (UnitValue)this.GetPropertyAsUnitValue(Property.FONT_SIZE); if (!fontSize.IsPointValue()) { ILog logger = LogManager.GetLogger(typeof(iText.Html2pdf.Attach.Impl.Layout.Form.Renderer.ButtonRenderer)); logger.Error(MessageFormatUtil.Format(iText.IO.LogMessageConstant.PROPERTY_IN_PERCENTS_NOT_SUPPORTED, Property .FONT_SIZE)); } PdfDocument doc = drawContext.GetDocument(); Rectangle area = flatRenderer.GetOccupiedArea().GetBBox().Clone(); ApplyPaddings(area, true); PdfPage page = doc.GetPage(occupiedArea.GetPageNumber()); PdfButtonFormField button = PdfFormField.CreatePushButton(doc, area, name, value, font, fontSize.GetValue( )); Background background = this.GetProperty <Background>(Property.BACKGROUND); if (background != null && background.GetColor() != null) { button.SetBackgroundColor(background.GetColor()); } ApplyDefaultFieldProperties(button); PdfAcroForm.GetAcroForm(doc, true).AddField(button, page); }
public override void Draw(DrawContext drawContext) { base.Draw(drawContext); if (!IsFlatten()) { String value = GetDefaultValue(); String name = GetModelId(); UnitValue fontSize = (UnitValue)this.GetPropertyAsUnitValue(Property.FONT_SIZE); if (!fontSize.IsPointValue()) { fontSize = UnitValue.CreatePointValue(DEFAULT_FONT_SIZE); } PdfDocument doc = drawContext.GetDocument(); Rectangle area = GetOccupiedArea().GetBBox().Clone(); ApplyMargins(area, false); PdfPage page = doc.GetPage(occupiedArea.GetPageNumber()); PdfButtonFormField button = PdfFormField.CreatePushButton(doc, area, name, value, doc.GetDefaultFont(), fontSize .GetValue()); button.GetWidgets()[0].SetHighlightMode(PdfAnnotation.HIGHLIGHT_NONE); button.SetBorderWidth(0); button.SetBackgroundColor(null); TransparentColor color = GetPropertyAsTransparentColor(Property.FONT_COLOR); if (color != null) { button.SetColor(color.GetColor()); } PdfAcroForm forms = PdfAcroForm.GetAcroForm(doc, true); //Add fields only if it isn't already added. This can happen on split. if (forms.GetField(name) == null) { forms.AddField(button, page); } } }
public override void Draw(DrawContext drawContext) { base.Draw(drawContext); if (!IsFlatten()) { String value = GetDefaultValue(); String name = GetModelId(); UnitValue fontSize = (UnitValue)this.GetPropertyAsUnitValue(Property.FONT_SIZE); if (!fontSize.IsPointValue()) { fontSize = UnitValue.CreatePointValue(DEFAULT_FONT_SIZE); } PdfDocument doc = drawContext.GetDocument(); Rectangle area = GetOccupiedArea().GetBBox().Clone(); ApplyMargins(area, false); PdfPage page = doc.GetPage(occupiedArea.GetPageNumber()); PdfButtonFormField button = PdfFormField.CreatePushButton(doc, area, name, value, doc.GetDefaultFont(), fontSize .GetValue()); button.GetWidgets()[0].SetHighlightMode(PdfAnnotation.HIGHLIGHT_NONE); button.SetBorderWidth(0); button.SetBackgroundColor(null); TransparentColor color = GetPropertyAsTransparentColor(Property.FONT_COLOR); if (color != null) { button.SetColor(color.GetColor()); } PdfAcroForm forms = PdfAcroForm.GetAcroForm(doc, true); //Add fields only if it isn't already added. This can happen on split. if (forms.GetField(name) == null) { forms.AddField(button, page); } if (doc.IsTagged()) { TagTreePointer formParentPointer = doc.GetTagStructureContext().GetAutoTaggingPointer(); IList <String> kidsRoles = formParentPointer.GetKidsRoles(); int lastFormIndex = kidsRoles.LastIndexOf(StandardRoles.FORM); TagTreePointer formPointer = formParentPointer.MoveToKid(lastFormIndex); String lang = this.GetProperty <String>(Html2PdfProperty.FORM_ACCESSIBILITY_LANGUAGE); if (lang != null) { formPointer.GetProperties().SetLanguage(lang); } formParentPointer.MoveToParent(); } } }
protected void ManipulatePdf(String dest) { PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest)); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true); PdfButtonFormField button = PdfFormField.CreatePushButton(pdfDoc, new Rectangle(36, 700, 36, 30), "post", "POST"); button.SetBackgroundColor(ColorConstants.GRAY); button.SetValue("POST"); // The second parameter is optional, it declares which fields to include in the submission or which to exclude, // depending on the setting of the Include/Exclude flag. button.SetAction(PdfAction.CreateSubmitForm("http://itextpdf.com:8180/book/request", null, PdfAction.SUBMIT_HTML_FORMAT | PdfAction.SUBMIT_COORDINATES)); button.SetVisibility(PdfFormField.VISIBLE_BUT_DOES_NOT_PRINT); form.AddField(button); pdfDoc.Close(); }