public static void main(String[] args) throws IOException { // Load the PDF document created by SimpleForm.java try (PDDocument document = PDDocument.load(new File("target/SimpleForm.pdf"))) { PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm(); // Get the field and the widget associated to it. // Note: there might be multiple widgets PDField field = acroForm.getField("SampleField"); PDAnnotationWidget widget = field.getWidgets().get(0); // Create the definition for a green border PDAppearanceCharacteristicsDictionary fieldAppearance = new PDAppearanceCharacteristicsDictionary(new COSDictionary()); PDColor green = new PDColor(new float[] { 0, 1, 0 }, PDDeviceRGB.INSTANCE); fieldAppearance.setBorderColour(green); // Set the information to be used by the widget which is responsible // for the visual style of the form field. widget.setAppearanceCharacteristics(fieldAppearance); document.save("target/AddBorderToField.pdf"); } } }
appearanceCharacteristics.setBorderColour(new PDColor(new float[] { 1, 0, 0 }, PDDeviceRGB.INSTANCE)); appearanceCharacteristics.setBackground(new PDColor(new float[]{0, 1, 0.3f}, PDDeviceRGB.INSTANCE));
fieldAppearance1.setBorderColour(new PDColor(new float[]{0,1,0}, PDDeviceRGB.INSTANCE)); fieldAppearance1.setBackground(new PDColor(new float[]{1,1,0}, PDDeviceRGB.INSTANCE)); widget1.setAppearanceCharacteristics(fieldAppearance1); fieldAppearance2.setBorderColour(new PDColor(new float[]{1,0,0}, PDDeviceRGB.INSTANCE)); fieldAppearance2.setBackground(new PDColor(new float[]{0,1,0}, PDDeviceRGB.INSTANCE)); widget2.setAppearanceCharacteristics(fieldAppearance2);
fieldAppearance.setBorderColour(new PDColor(new float[]{0,1,0}, PDDeviceRGB.INSTANCE)); fieldAppearance.setBackground(new PDColor(new float[]{1,1,0}, PDDeviceRGB.INSTANCE)); widget.setAppearanceCharacteristics(fieldAppearance);
appearanceCharacteristics.setBorderColour(new PDColor(new float[]{1, 0, 0}, PDDeviceRGB.INSTANCE)); appearanceCharacteristics.setBackground(new PDColor(new float[]{1, 1, 0}, PDDeviceRGB.INSTANCE));
public static void main(String[] args) throws IOException { // Load the PDF document created by SimpleForm.java PDDocument document = PDDocument.load(new File("target/SimpleForm.pdf")); PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm(); // Get the field and the widget associated to it. // Note: there might be multiple widgets PDField field = acroForm.getField("SampleField"); PDAnnotationWidget widget = field.getWidgets().get(0); // Create the definition for a green border PDAppearanceCharacteristicsDictionary fieldAppearance = new PDAppearanceCharacteristicsDictionary(new COSDictionary()); PDColor green = new PDColor(new float[] { 0, 1, 0 }, PDDeviceRGB.INSTANCE); fieldAppearance.setBorderColour(green); // Set the information to be used by the widget which is responsible // for the visual style of the form field. widget.setAppearanceCharacteristics(fieldAppearance); document.save("target/AddBorderToField.pdf"); document.close(); } }
borderColorArray.add(new COSFloat((float) (226f/255f))); PDColor blue = new PDColor(borderColorArray, PDDeviceRGB.INSTANCE); fieldAppearance.setBorderColour(blue); fieldAppearance.setBackground(blue); fieldAppearance.setNormalCaption("Click Me");
PDAppearanceCharacteristicsDictionary fieldAppearance = new PDAppearanceCharacteristicsDictionary(new COSDictionary()); fieldAppearance.setBorderColour(colourBlack); COSArray arr = new COSArray(); arr.add(new COSFloat(227/255f));
fieldAppearance1.setBorderColour(new PDColor(new float[]{0,1,0}, PDDeviceRGB.INSTANCE)); fieldAppearance1.setBackground(new PDColor(new float[]{1,1,0}, PDDeviceRGB.INSTANCE)); widget1.setAppearanceCharacteristics(fieldAppearance1); fieldAppearance2.setBorderColour(new PDColor(new float[]{1,0,0}, PDDeviceRGB.INSTANCE)); fieldAppearance2.setBackground(new PDColor(new float[]{0,1,0}, PDDeviceRGB.INSTANCE)); widget2.setAppearanceCharacteristics(fieldAppearance2);
fieldAppearance.setBorderColour(new PDColor(new float[]{0,1,0}, PDDeviceRGB.INSTANCE)); fieldAppearance.setBackground(new PDColor(new float[]{1,1,0}, PDDeviceRGB.INSTANCE)); widget.setAppearanceCharacteristics(fieldAppearance);
PDAppearanceCharacteristicsDictionary fieldAppearance = new PDAppearanceCharacteristicsDictionary(new COSDictionary()); fieldAppearance.setBorderColour(colourBlack); button.getWidget().setAppearanceCharacteristics(fieldAppearance);