It looks great, like the PDF output of the iText PdfGraphics2D interface, in the worst case. The usual case is also not so hot, but it is not so bad.
If I'm right, there is still no answer, but you can write it yourself, since you are clearly not afraid of content flows:
ByteBuffer internalBuf = myPdfContentByte.getInternalBuffer(); String newContents = magic( internalBuf.toString() ); internalBuf.reset(); internalBuf.append( newContents );
magic() is foggy foggy, but writing code to remove the "q Q" pairs should be trivial. Yanking clipping regions in which there is nothing inside (linear line W n) should not be much more complicated with a small number of registers.
Getting rid of line / line connection settings (j and J) when they are not used will be more complicated. Same thing with combining text blocks or discarding redundant changes to fill / stroke colors, font and size, etc.
The "difficult use of text operators" will soon begin to look like an optimization of the black magic compiler.
And if it is iText, we will all appreciate it if you share your code. I assure you, we will gladly accept all the data on the output of PdfGraphics2D.
source share