You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by Vladimir Rapatskiy <vr...@accusoft.com> on 2017/03/24 09:57:20 UTC

How to mock or trace PDFBox

Hello!

I'm developing unit tests for PDFBox tool.

The idea is to get the list of all commands that
will be applied by PDFBox to PDF instead of actual
editing of the file. Then unit test will verify the
commands list to verify the functionality.

Please tell me what is the best way?

Is it possible to get the PDF editing commands trace
from PDFBox?

Or is it possible to mock I/O part of PDFBox to generate
the commands list, instead of actual document editing?

Best regards,
Vladimir

Re: How to mock or trace PDFBox

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 24.03.2017 um 10:57 schrieb Vladimir Rapatskiy:
> Hello!
>
> I'm developing unit tests for PDFBox tool.
>
> The idea is to get the list of all commands that
> will be applied by PDFBox to PDF instead of actual
> editing of the file. Then unit test will verify the
> commands list to verify the functionality.
>
> Please tell me what is the best way?
>
> Is it possible to get the PDF editing commands trace
> from PDFBox?
>
> Or is it possible to mock I/O part of PDFBox to generate
> the commands list, instead of actual document editing?

I have not fully understood you. If you mean the commands in a page 
content stream, you can get these tokens as shown in the 
RemoveAllText.java example in the source code download. But this isn't 
possible that easy for the complete PDF.

A better method would be to do a rendering test comparison, or at least 
a text extraction comparison.

Note that a rendering test comparison may fail when java versions or 
PDFBox versions change, due to slight differences in rendering glyphs. 
You then have to manually look at the diff files. Most of the times 
these are seemingly blank, or have only shadows of the glyphs.

To see how this works, see
org\apache\pdfbox\pdmodel\interactive\form\AcroFormsRotationTest.java 
near the end. The test doesn't fail on the build server, but in private 
development the System.err.println is relaced with "fail". The 
TestPDFToImage class is used which does a pixel comparison.

And no we don't have a mock PDFBox.

Tilman


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org