You can compare the XMP data in two PDF documents using XPath. Comparing XFA and XMP data are basically the same. And because the previous chapter 3.37: “XFA Data” describes the tests in detail, this section is very short.
If you are in doubt about the structure and values of the XMP data you can extract them
with the program ExtractXMPData
. See chapter
9.12: “Extract XMP Data to XML”.
PDFUnit provides the following method:
// Method for tests with XMP data:
.haveSameXMPData().matchingXPath(XPathExpression)
@Test public void haveSameXMPData() throws Exception { String filenameTest = "documentUnderTest.pdf"; String filenameReference = "reference.pdf"; XPathExpression expression = new XPathExpression("//pdf:Producer"); AssertThat.document(filenameTest) .and(filenameReference) .haveSameXMPData() .matchingXPath(expression) ; }
If the XMP data is compared in two documents, but neither contains XMP data, PDFUnit throws an exception.