Creating unit tests for generated PDF files using iText

We use iText to read the input PDF file, then add the messaging and save the output.

PdfReader reader = new PdfReader(inputFilepath);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outputFilename, true));
PdfContentByte over = stamper.getOverContent(1);
over.beginText();
over.showTextAligned(align, text, x, y, angle);
...
over.endText();
stamper.close();

Is there a way to read in the PDF generated in the unit test, and then check for existing text in the correct x, y coordinates?

+4
source share
2 answers

Generally speaking, do not test the platform (or, in this case, the third-party libraries that you use.) Instead, the test is that you are communicating correctly with it.

, showTextAligned() , . .

, , , PDF , , , .

+2

PDF , PdfReader.getPageContent(int pageNumber).

, , , .

-1

Source: https://habr.com/ru/post/1538961/


All Articles