←All posts

How to find duplicate invoice attachments without deleting originals

Create a duplicate-invoice review report using file IDs, content hashes and document references. Separate identical copies from revised or similar invoices.

Find duplicate invoice attachments by comparing the files’ contents and keeping the source of every copy. Group identical files separately from documents that merely share a supplier, reference or amount. Produce a report for review before taking any cleanup action.

Two files named invoice.pdf are not necessarily duplicates. Two differently named PDFs may be identical. A revised invoice can also carry the same reference as the original while containing an important correction.

Define the kind of duplicate you want to find

Use two categories rather than one broad Duplicate label:

CategoryEvidenceAppropriate result
Identical file candidatesMatching content hash and sizeGroup the copies and retain source links
Possible document duplicatesMatching supplier and invoice referenceAsk someone to compare the documents
Similar documentsSimilar amount, date or filename onlyWeak match requiring context
Revised documentsSame reference with changed contentPreserve the versions and identify the difference

This report does not establish whether an invoice was paid twice. That requires a separate comparison with payment records. Keep the first workflow focused on duplicate documents so its result is clear.

Choose a bounded folder or attachment archive for the first pass. Record the account, folder ID, date range and whether subfolders are included. A report covering one monthly folder should not imply that it searched every company mailbox.

Option 1: Compare a small batch manually

For a few suspect files, list their filenames, sizes, source links and visible invoice references in a spreadsheet. Open each candidate pair side by side and compare the supplier, document number, dates, totals and page count.

Keep a reason for each match: “same PDF received from the supplier and forwarded by operations” is useful. “Looks duplicated” is difficult for another person to evaluate later.

Do not rename or move files during the first comparison. Preserve the original email or folder link so you can understand how each copy arrived. If a file is unreadable, list it as unassessed rather than treating it as a unique invoice.

This approach is often enough when the archive is small and the suspected duplicates are obvious. Automation becomes more useful when you need to compare many files repeatedly or track candidates across several sources.

Option 2: Build a duplicate review report with Pillow

Pillow is an AI assistant that builds editable workflows from plain-English instructions through its workflow builder.

Give it the exact archive to inspect and ask for a report with evidence for every group. Specify that content matches and possible business-document matches are different findings. Connect the selected sources and review the proposed comparison method before scheduling it.

Create a disabled workflow that reports possible duplicate invoice PDFs.
Ask me which mailbox archive or Drive folders to inspect, whether to
include subfolders, and the period to cover. Do not delete or move files.
Build an inventory containing source file/message IDs, names, sizes,
links and any available content checksum. If file contents are readable,
compare their hashes using one consistent method. Keep identical-file
candidates separate from possible matches based on supplier and invoice
reference. Do not use filename or amount alone as proof of duplication.
For each group, list every source, the matching evidence and any content
differences. Preserve revised invoices, credit notes and originals.
Put unreadable files and incomplete searches in separate exceptions.
Save a review report with stable group IDs and retain my resolutions on
later runs. Do not mark invoices paid, change accounting records or
contact suppliers. Show missing access and comparison capabilities
before building, then let me review the first proposed report.
Download Pillow

Copy the prompt above, then open Pillow to build your automation.

Option 3: Compare file inventories in n8n

Build an inventory before grouping candidates. Read file IDs, names, sizes and source locations from the selected archive. For email attachments, retain the mailbox, message ID and attachment ID as well as the downloaded file.

Google Drive exposes an md5Checksum for files with binary content, including ordinary uploaded PDFs. It is not a universal field for every kind of Drive item. Drive file metadata.

Where a consistent checksum is unavailable, download the selected file and compute a hash of its actual bytes. n8n’s Crypto node supports hashing text or files. Use the file input, not its name, URL or extracted text, and keep the algorithm name with the value.

Arrange the workflow as follows:

  1. Enumerate the agreed folders or attachments and retain their identifiers.
  2. Confirm that all result pages were retrieved.
  3. Read an available checksum or calculate one consistently from the file content.
  4. Group files by algorithm, hash and size.
  5. Put groups containing more than one distinct source file into the identical-file candidate report.
  6. Run a separate optional comparison of extracted supplier IDs and invoice references.
  7. Save the report and its coverage details without changing the archive.

Do not mix an MD5 value from one source with a SHA-256 value from another and compare the strings. Recalculate using the same algorithm if you need to compare files across those sources.

Distinguish content identity from document meaning

A content hash is a useful way to group likely identical files. It does not tell you which copy should be retained, whether the document is valid or whether it has already been used elsewhere.

Consider three fictional files:

  • invoice-1042.pdf, received directly from the supplier.
  • forwarded-invoice.pdf, containing the same bytes.
  • invoice-1042-revised.pdf, with a changed purchase-order reference.

The first two belong in an identical-file group. The third belongs in a possible related-document group because its content differs. An automated cleanup based only on the invoice number could remove the corrected version by mistake.

For important cleanup decisions, open the grouped files and verify the content. A hash match is comparison evidence, not a substitute for deciding whether two source records have distinct purposes. This workflow deliberately stops at the report.

If you compare extracted text, label that as a text match. Two PDFs can contain the same words but differ in signatures, images or attachments. Conversely, scanning the same paper twice can produce different binary files even when the underlying invoice is the same.

Make the report actionable

Give each group a stable identifier and include every source link, not just a recommended copy. Useful columns are Group ID, Match type, Evidence, Source count, File links, First observed and Review outcome.

Keep the evidence specific. “Same SHA-256 and byte size” explains an identical-file candidate. “Same supplier ID and invoice reference; totals differ” explains why two files need closer inspection.

Use outcomes such as Unreviewed, Same document in different sources, Revised version, Different documents and Needs supplier clarification. Keep the reviewer’s note and date. An earlier decision should remain visible when the report is regenerated.

For recurring scans, retain group membership by source file ID. A renamed file should remain in the same group. A file whose content changes needs its hash recomputed and its prior group membership reconsidered.

Handle incomplete and unreadable inputs

A report with no candidate groups is meaningful only if the intended files were actually inspected. Record the number of folders scanned, files listed, files hashed and files that could not be read.

Keep protected PDFs, failed downloads and unsupported file types in an exceptions section. Do not assign an empty checksum and group all empty values together. That creates an impressive-looking but meaningless duplicate group.

Exclude folders and shortcuts from byte comparisons unless you deliberately resolve the shortcut to an approved target. A shortcut is a pointer, not another PDF copy. Retain its presence in the inventory if it helps explain how users reach the document.

For a large archive, process a bounded batch and checkpoint completed files. Compare a file’s current version or modification information before reusing an old hash. The report should identify its scan date so someone does not mistake last month’s comparison for a current one.

Questions about duplicate invoice documents

Can I automatically delete the extra copies?

Keep deletion out of this workflow. First establish which source is authoritative, whether other records link to each copy and whether the files are truly interchangeable. The report provides evidence for that separate decision.

Why do visually identical scans have different hashes?

Different scans can contain different image data, metadata or compression. Hashing compares file bytes. Use supplier/reference matching to identify those as possible document duplicates, then review them visually.

Does an identical invoice file mean a duplicate payment?

No. It only means the archive contains matching document content. Payment verification requires separate records and controls; do not infer it from attachment duplication.

Keep going

Browse all guides