NAME

PDF::Make::Markup::Diff - which pages changed between two renders

SYNOPSIS

my $d = PDF::Make::Markup::Diff->diff($bytes_before, $bytes_after);
printf "%d of %d pages changed\n", $d->{changed}, $d->{pages_b};
for my $p (@{ $d->{pages} }) {
    next unless $p->{changed};
    printf "page %d: -%s +%s\n", $p->{page},
        "@{$p->{removed}}", "@{$p->{added}}";
    printf "page %d: %s moved\n", $p->{page}, "@{$p->{moved}}"
        if @{ $p->{moved} };
}

WHAT IS REPORTED

Words are kept in reading order - lines top to bottom, words left to right - and the two pages are aligned by a longest common subsequence over the text. Each page then reports three lists, all in reading order:

removed

Words present before and gone after.

added

Words new after.

moved

Words whose text survived but whose position did not - and only when nothing was removed or added. Editing a word shifts every word after it on the line, so once the text has changed, movement is the consequence rather than the news. A page whose every word survived in a new place is the reflow an engine upgrade has to be checked for, and that is the case this list exists to name.

changed is true if any of the three is non-empty, so a page that only reflowed is still flagged. Each list is capped at forty words: a page that changed wholesale says so with its first few dozen.

METHODS

pages

my $pages = PDF::Make::Markup::Diff->pages($pdf_bytes);

Per-page words in reading order, each { text, x, y } with the coordinates rounded to the point.

Before 0.11 this returned per-page bags of "text@x,y" counts.

diff

my $d = PDF::Make::Markup::Diff->diff($bytes_a, $bytes_b);

{ pages_a, pages_b, changed, pages => [ { page, changed, removed, added, moved } ] }.