Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Border of cross check field not visible in Chrome viewer #1261

Open
dadza opened this issue Jan 23, 2025 · 1 comment · May be fixed by #1262
Open

Border of cross check field not visible in Chrome viewer #1261

dadza opened this issue Jan 23, 2025 · 1 comment · May be fixed by #1262
Labels

Comments

@dadza
Copy link
Contributor

dadza commented Jan 23, 2025

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 dadza added the bug label Jan 23, 2025
dadza added a commit to Jaspersoft/OpenPDF that referenced this issue Jan 23, 2025
dadza added a commit to Jaspersoft/OpenPDF that referenced this issue Jan 23, 2025
@dadza dadza linked a pull request Jan 23, 2025 that will close this issue
@mkl-public
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants