Search code examples
htmlprintingjeditorpane

JEditorPane print dropping spaces


I have a JEditorPane containing HTML like this:

use the <strong>File</strong> menu, <strong>Open File</strong> to run the conversion

In the interactive window it looks like what I expect: "use the File menu, Open File to run the conversion"

However, when I print it using JEditorPane.print I get: "use theFile menu, Open File to run the conversion"

i.e. It is dropping the space between 'the' and 'File'.

This is happening apparently at random throughout the HTML file, happens on 'span', 'strong', 'a', and 'em' tags that I have tried. About half such tags in the html are dropping a space. As in the example, it will happen on one such tag in a line, and not the next one. Or visa-versa. Or both. I've tried putting the space inside the 'strong' or 'a', or both inside and outside, and it doesn't make any difference. And the space only gets dropped at the start of a tag, not the end.

It happens on two physical printers, and on PDF creation, so I don't think its printer dependent. I have also tried multiple JEditorPane printing methods and they all have the same behavior. I have also tried different scaling, no difference either.

Using a nsbp; does keep a space, but I have many hundreds of such tags, and its going to be a real pain to insert that everywhere. I'm hoping to find something that is causing this and turn it off.

Thanks


Solution

  • I guess this happens because of incorrect fractional measuring.

    Try to call editorPaneInstance.getDocument().putProperty("i18n", Boolean.TRUE);

    Similar problem is explained here and here