DEV Community

Anthony Leignel
Anthony Leignel

Posted on

Comparing PDF and XML Data Locally with Python, Open Source

PDF / XML Comparator, an open source tool for comparing PDF and XML data locally

A lightweight open source tool for detecting differences between two representations of the same document

A PDF and an XML file can represent the same document while containing different information.

A value may have been modified in one representation, a reference may be missing, a number may use a different format, or some information may simply exist in one file but not the other.

When both files become part of the same workflow, checking them manually can quickly become tedious.

This is why I built PDF / XML Comparator, a small open source Python tool designed to perform a first comparison locally.

View PDF / XML Comparator on GitHub

The problem

PDF and XML serve very different purposes.

The PDF provides a human-readable representation of a document, while XML provides structured data that can be processed by software.

Even when both representations originate from the same process, having two files does not automatically guarantee that every value represented in one can also be found in the other.

For example, you may encounter situations where:

  • a reference differs between the PDF and XML
  • an amount was changed in one representation
  • a value exists only in the XML
  • information visible in the PDF cannot be found in the XML
  • equivalent values use different formatting

Opening both files and searching for every value manually works for a single document, but it quickly becomes inefficient when repeated.

A deliberately simple approach

PDF / XML Comparator does not try to understand the business meaning of every field.

Instead, it performs a bidirectional comparison.

The process can be summarized as:

PDF ──► Text extraction ──► Search values in XML
                              │
                              ▼
                         Differences
                              ▲
                              │
XML ──► Data extraction ──► Search values in PDF
Enter fullscreen mode Exit fullscreen mode

https://palks-studio.com

Top comments (0)