Please give a brief summary of your issue:
Unable to remove background and border color from Widget annotations using PDFTron Java SDK.
Please describe your issue and provide steps to reproduce it:
I’m trying to remove the background and border color from all Widget annotations in a PDF using PDFTron Java SDK. I attempted to set the color to transparent using ColorPt(0, 0, 0) and ColorSpace.e_device_rgb , followed by refreshAppearance() and flatten() . However, the annotations still retain their background or border color.
Load a PDF document with form fields.
Iterate through each page and annotation.
For each Widget annotation:
Set background and border color to transparent.
Call refreshAppearance().
Optionally call eraseAppearance() and flatten().
Code:
for (int i = 1; i <= pdfDoc.getPageCount(); i++) {
Page page = pdfDoc.getPage(i);
int numAnnots = page.getNumAnnots();
for (int j = numAnnots - 1; j >= 0; j--) {
Annot annot = page.getAnnot(j);
if (annot.isValid() && annot.getType() == Annot.Type.e_Widget) {
Widget widget = new Widget(annot);
ColorPt transparentRGB = new ColorPt(0, 0, 0); // Transparent
widget.setBackgroundColor(transparentRGB, ColorSpace.e_device_rgb);
widget.setBorderColor(transparentRGB, ColorSpace.e_device_rgb);
widget.refreshAppearance();
annot.removeAppearance();
annot.flatten(page);
}
}
}
Hello, I’m AiRon, an automated tech support bot While you wait for one of our customer support representatives, I can help you with your question.
It seems like you’re trying to remove the background and border color from Widget annotations using the PDFTron Java SDK. Setting the color to transparent using ColorPt(0, 0, 0) may not be the correct approach, as this represents the color black in e_device_rgb color space. For transparency, you might need to ensure that you’re setting the colors to a transparent state properly.
Some things you can try:
Ensure that you are using ColorSpace.e_device_rgb correctly and setting the color to null or using a method that supports transparency.
Consider using widget.setBackgroundColor(null) and widget.setBorderColor(null) if the API supports it for transparency.
After setting the colors, ensure you call widget.refreshAppearance() to update the annotation’s appearance.
Check if annot.removeAppearance() is being used correctly as it might already be sufficient to remove the appearance.
Verify that annot.flatten(page) is necessary for your use case, as flattening makes the annotation part of the page content, which might not be needed if you only want to remove the appearance.
Note that (0, 0, 0) in RGB color space designates black. If you want to suppress the border, you can use Annot.SetBorderStyle. We have a forum post with a code sample showing how to do this.
Regarding the background, are you working with text-based annotations?
Additionally, I’m looking to remove the background color from a TextWidget annotation so that it appears transparent or blends with the page background.
Thank you for clarifying what widget type you’re working with. For test-based annotations, you can use one of these workflows.
// either (a) delete the C entry
annot.getSDFObj().erase(“C”); // uppercase latin C
// or (b) set zero component color entry
annot.setColor(new ColorPt(), 0);
Regarding the link, I apologize for the confusion. The forum post is a few years old, and we’ve made somec changes in our documentation since. Here’s the updated link to the setBorderStyle() function.
In this case, you should able to create a custom BorderStyle() with a width of 0.