ralfstuckert/pdfbox-layout

Using Indents causes warning messages in PDPageContentStream

Opened this issue · 5 comments

Hi Ralf,

we are using you API in our current project and it helps us a lot. So first of all a big thank you for the time and effort you spend on this regularly.

We have one question remaining:
When it comes to use lists, we are using Indents, as shown in

https://github.com/ralfstuckert/pdfbox-layout/wiki/IndentationAndLists

, but we are facing a lot of warning messages being logged by the underlying PDPageContentStream class.

Nov 15, 2018 3:40:18 PM org.apache.pdfbox.pdmodel.PDPageContentStream transform
WARNUNG: Modifying the current transformation matrix is not allowed within text objects.

Is this expected behaviour or are we doing something wrong?

These warnings also occur when using your example Indentation.java directly, so we are wondering if you were facing this problem already before and know the trick how to solve this?

Any idea?

Codefragment (from your Indentation.java):

Document document = new Document(40, 60, 40, 60);
Paragraph paragraph = new Paragraph();
paragraph
	.addMarkup(
		"This is an example for the new indent feature. Let's do some empty space indentation:\n",
		11, BaseFont.Times);
paragraph.add(new Indent(50, SpaceUnit.pt));
paragraph.addMarkup("Here we go indented.\n", 11, BaseFont.Times);
    document.add(paragraph);

Many thanks,

Jan (&& several other team members)

Hi Lichthupe ((O O))
I have used Indentation without any problem, but I have not tried to create a list.
Can you be more specific? Can tell at what step this warning occurs?
Does it happen every time you try to indent or just when using numbered lists or ...?

This IllegalStateException is thrown, when transform is called and PDContentStream is in text mode.
So it may depend on the time and state of contentstream and document, if you get this warning.

Hi Arnthom.
Many thanks for your reply!
Well, this warning (or exception message) occurs even when using the Indentation.java example provided by Ralf Stuckert. So the example I provided in my first comment above is already causing this message.
In our case, what we are doing, is creating a container like shown above and add this container to a frame to have a background for this element. But as I said, already using the example above (the original one) causes this messages.

Fragment from my code:

/**
* This method adds a bullet point with a fixed indention.
*
* @param text Text to show as list item.
* @param frameWidth Width of the underlying frame
* @param frameHeigth height of the underlying frame
* @param leftPadding padding left of the underlying frame
* @param rightPadding padding right of the underlying frame
*
* @throws Exception Thrown in case of an error.
*/
private void addListElement(String text, float frameWidth, float frameHeigth, int leftPadding, int rightPadding) throws Exception {

	String bulletPoint = CompatibilityHelper.getBulletCharacter(1) + " ";
	
	container = new Paragraph();
	container.setLineSpacing(1.0f);
	// this is the recommended way, but it causes warnings in pdfbox 
	container.add(new Indent(bulletPoint, 4, SpaceUnit.em, 11,	PDType1Font.HELVETICA, Alignment.Right));
	container.addMarkup(text, FONT_SIZE_REGULAR_TEXT, FONT);
	
	frame = new Frame(container, frameWidth, frameHeigth);
	frame.setPadding(leftPadding, rightPadding, 0, 0);
	frame.setShape(new Rect());
	frame.setBackgroundColor(BACKGROUND_COMMON_TEXT);
	
	document.add(frame);
	
}

which is called for each list item I want to have on the page.
like
addListElement("some text", width, 20.0f, 0, PADDING_RIGHT);

What I do not understand is why this message already occurs when using Ralf's original example.

Anyway, many thanks already for having a look here.

Jan

Sorry, there is no advice I can give you.
Meanwhile I tested the indentation.java file and it runs without any problem or warning on my system.
Maybe Ralf looks into this issue later ...

Hi Arnthom,

don't worry and many thanks for your effort, highly appreciated.
Maybe I will have some time during Christmas Time and I will dive deeper into this topic.

Have a good time!

Jan

Was anything found with this issue? I seem to be having the issue when using bullet lists, same error. I validated it was the bullet list by commenting out the -+, it saved with no warnings, as soon as they're back in warnings again.