OpenPDF icon indicating copy to clipboard operation
OpenPDF copied to clipboard

Border of cross check field not visible in Chrome viewer

Open dadza opened this issue 10 months ago • 5 comments

Creating a RadioCheckField of type TYPE_CROSS with a border results in the border being visible in Acrobat Reader but not in the Google Chrome PDF viewer.

To Reproduce

Code to reproduce the issue

import java.awt.Color;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;

import com.lowagie.text.Document;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfBorderDictionary;
import com.lowagie.text.pdf.PdfFormField;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.RadioCheckField;

public class PdfCheckbox {
	public static void main(String[] args) throws IOException {
		Document document = new Document();
		try (OutputStream out = Files.newOutputStream(Paths.get("checkbox.pdf"))) {
			PdfWriter writer = PdfWriter.getInstance(document, out);
			document.open();
			document.newPage();
			
			RadioCheckField checkField = new RadioCheckField(writer, 
					new Rectangle(100, 600, 150, 650), "field", "on");
			checkField.setCheckType(RadioCheckField.TYPE_CROSS);
			checkField.setBorderStyle(PdfBorderDictionary.STYLE_SOLID);
			checkField.setBorderColor(Color.BLACK);
			checkField.setBorderWidth(1);
			
			PdfFormField formField = checkField.getFullField();
			writer.addAnnotation(formField);
			
			document.close();
		}
	}
}

Expected behavior

The checkbox border should be visible in the Google Chrome PDF viewer.

Screenshots

Image

checkbox.pdf

System

  • OS: Windows 11
  • Used font: none
  • OpenPDF version: 2.0.3

Thank you, Lucian Chirita

dadza avatar Jan 23 '25 14:01 dadza

An analysis of the supplied example document:

The form field widget contains /BS<</S/S/W 1>> and /MK<</BC[0 0 0]/CA(8)>>, i.e. a border style of a stroked border with a width of one unit and a border color of RGB black. Thus, a PDF processor generating the appearance by itself, should draw a border.

The appearance streams of the widget, on the other hand, do not contain instructions to draw a border. Thus, a PDF processor relying on the supplied appearance, will not draw a border.


The appearance streams look as follows.

  • For the on state:

    q 0 0 0 rg 1 w 0 0 0 RG 1 1 48 48 re W n 2 48 m 48 2 l 48 48 m 2 2 l s Q 
    

    The rectangle here explicitly is not drawn, using the n instruction neither fills nor strokes.

  • For the Off state:

    q 0 0 0 rg 1 w 0 0 0 RG 1 1 48 48 re W Q 
    

    Here there actually is a syntax error, between W and Q there should have been a path drawing instruction but is not.

mkl-public avatar Jan 23 '25 14:01 mkl-public

Hey, getting this behaviour on JDK 11 1.4.2 - can’t move to anything greater right now :(

I checked out the changes made in the corresponding PR and patched to 1.4.3-SNAPSHOT and get the desired result. I see however, the PR was closed before merge - @dadza did you find another solution or are you using your fork?

cbm64chris avatar Jun 09 '25 10:06 cbm64chris

I don't have a solution other than the fix that I proposed, which was not accepted.

dadza avatar Jun 09 '25 15:06 dadza

@mkl-public is there anything I can do to move this on?

cbm64chris avatar Jun 09 '25 16:06 cbm64chris

@mkl-public is there anything I can do to move this on?

Please ask the maintainers of this repository, in particular @asturio or probably @andreasrosdal .

mkl-public avatar Jun 09 '25 19:06 mkl-public