TextFragment background color not covering the last character of text

Following the Java PDF API

Z0002.02.pdf (9.5 KB)


TextFragment sbecHeading = new TextFragment(“PURCHASE REQUISITION”);
sbecHeading.setPosition(new Position(leftMargin + 220, pageHeight - 75));
sbecHeading.getTextState().setBackgroundColor(Color.getGray());
sbecHeading.getTextState().setCharacterSpacing(2);

@harmeetbawa,

It appears as this is the output PDF file. Kindly send us your source PDF document and the complete code. We will investigate your scenario inn our environment and share our findings with you.

I am creating a pdf document from scratch. So there is no source pdf document.

I had the fragment of source code that creates the text fragment and sets the texts background above. Hre it is again:


TextFragment sbecHeading = new TextFragment(“PURCHASE REQUISITION”);
sbecHeading.setPosition(new Position(leftMargin + 220, pageHeight - 75));
sbecHeading.getTextState().setBackgroundColor(Color.getGray());
sbecHeading.getTextState().setCharacterSpacing(2);

I figured a solution. I put a space after the last character and it covered it.

TextFragment sbecHeading = new TextFragment(“PURCHASE REQUISITION ”);

I hope I am being clear enough. And if I am, will you be able to tell me why does it not cover the whole text fragment and with the background color?

@harmeetbawa,

We have created a PDF from scratch, and the background color covers all text characters. Kindly open this PDF and let us know how that goes in your environment: Output.pdf (1.8 KB). Please send a snapshot of the problematic area.

I downloaded your Output.pdf file and when I open it I see exactly the same thing. The last letter “N” in “PURCHASE REQUISITION” is only half covered with the background.

Adding an extra space does the trick as I mentioned above.

Harmeet.

@harmeetbawa,

Please send us a snapshot of the problematic area, and share all details of the environment, including Operating System (edition & name) and local display settings etc. Your response is awaited.