Support for Beveled, Underline and Inset form field border styles
In iText 7 Core 7.1.14 we've implemented some border styles for PDF form fields which we were previously missing. The styles in question are Beveled, Underline and Inset borders.
Below you can find an example code snippet that shows of all 3 of the newly supported border styles, as well as an output example of what you can expect when running this code snippet.
JAVA
JAVA
import com.itextpdf.forms.PdfAcroForm;
import com.itextpdf.forms.fields.PdfFormField;
import com.itextpdf.forms.fields.PdfTextFormField;
import com.itextpdf.kernel.colors.ColorConstants;
import com.itextpdf.kernel.geom.Rectangle;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.kernel.pdf.annot.PdfAnnotation;
import java.io.File;
import java.io.FileNotFoundException;
public class Border_Example {
public static final String DEST = "results/result.pdf";
static {
new File(DEST).getParentFile().mkdirs();
}
public static void main(String[] args) throws FileNotFoundException {
PdfDocument doc = new PdfDocument(new PdfWriter(DEST));
PdfAcroForm form = PdfAcroForm.getAcroForm(doc, true);
// Beveled border
PdfFormField formField1 = PdfTextFormField.createText(doc,
new Rectangle(100, 600, 100, 50), "firstField", "Hello, iText!");
formField1.getWidgets().get(0).setBorderStyle(PdfAnnotation.STYLE_BEVELED);
formField1.setBorderWidth(2).setBorderColor(ColorConstants.BLUE);
// Underline border
PdfFormField formField2 = PdfTextFormField.createText(doc,
new Rectangle(100, 500, 100, 50), "secondField", "Hello, iText!");
formField2.getWidgets().get(0).setBorderStyle(PdfAnnotation.STYLE_UNDERLINE);
formField2.setBorderWidth(2).setBorderColor(ColorConstants.BLUE);
// Inset border
PdfFormField formField3 = PdfTextFormField.createText(doc,
new Rectangle(100, 400, 100, 50), "thirdField", "Hello, iText!");
formField3.getWidgets().get(0).setBorderStyle(PdfAnnotation.STYLE_INSET);
formField3.setBorderWidth(2).setBorderColor(ColorConstants.BLUE);
form.addField(formField1);
form.addField(formField2);
form.addField(formField3);
form.flattenFields();
doc.close();
}
}
C#
C#
using System;
using System.IO;
using iText.Forms;
using iText.Forms.Fields;
using iText.Kernel.Colors;
using iText.Kernel.Geom;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Annot;
namespace ConsoleApp1
{
class Program
{
private static String DEST = "result.pdf";
static void Main(string[] args)
{
PdfDocument doc = new PdfDocument(new PdfWriter(DEST));
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
// Beveled border
PdfFormField formField1 = PdfTextFormField.CreateText(doc,
new Rectangle(100, 600, 100, 50), "firstField", "Hello, iText!");
formField1.GetWidgets()[0].SetBorderStyle(PdfAnnotation.STYLE_BEVELED);
formField1.SetBorderWidth(2).SetBorderColor(ColorConstants.BLUE);
// Underline border
PdfFormField formField2 = PdfTextFormField.CreateText(doc,
new Rectangle(100, 500, 100, 50), "secondField", "Hello, iText!");
formField2.GetWidgets()[0].SetBorderStyle(PdfAnnotation.STYLE_UNDERLINE);
formField2.SetBorderWidth(2).SetBorderColor(ColorConstants.BLUE);
// Inset border
PdfFormField formField3 = PdfTextFormField.CreateText(doc,
new Rectangle(100, 400, 100, 50), "thirdField", "Hello, iText!");
formField3.GetWidgets()[0].SetBorderStyle(PdfAnnotation.STYLE_INSET);
formField3.SetBorderWidth(2).SetBorderColor(ColorConstants.BLUE);
form.AddField(formField1);
form.AddField(formField2);
form.AddField(formField3);
form.FlattenFields();
doc.Close();
}
}
}
Output: