Strip Digital Signatures from PDFs Before Feeding Them to AI (Linux Guide)

· Medium ·

4 min read Original article ↗

Giovambattista Vieri

A note on scope
Although this article is written with Italian users in mind (where digitally signed documents and the codice fiscale are extremely common), the privacy risk it describes applies to anyone handling documents under the GDPR. The Linux commands and sanitisation techniques work the same way regardless of jurisdiction.

Scope: the aim of this short text is to highlight a potential privacy issue that arises when uploading digitally signed PDFs to remote ‘AI’ models, and to provide a practical solution.

Environment: Linux Ubuntu 24.04

We often receive digitally signed documents, sometimes with legal or financial value. We live in the age of agents and ‘AI’ — how can we resist the temptation to have our favourite electronic assistant read them, looking for traps or simply extracting the key elements to put into a calendar or task list?

Remember that in the EU (and especially in Italy) there are strict privacy rules (GDPR first and foremost).

Depending on the digital signature used, the certificate may contain the signatory’s first and last name, the organisation they work for, or their Italian tax identification number (codice fiscale).

Apart from the organisation, the other two are clearly personal data. The seemingly inconspicuous tax ID is particularly sensitive.

If the signature also contains an e-mail address and phone number (as is common with private individuals), that would only add to the problem.

Many PDF files may also carry EXIF metadata of various origins, such as the original author, etc.

Other hidden data formats may exist as well, but they are not covered here.So the PDF file you have received is quite likely to contain non-obvious personal data.

First problem: verification.

First, install a few tools:

sudo apt update
sudo apt install mc poppler-utils ghostscript exiftool

The venerable mc (Midnight Commander) will be useful later.

Let’s check whether certificates are present:

pdfsig <filename>

f you see text such as “Signature #1:”, the document contains digital signatures.It is not the purpose of this text to verify whether the document is correctly signed, whether it has a single or multiple signatures, etc.

REMEMBER THAT REMOVING THE DIGITAL SIGNATURE AND/OR MODIFYING THE FILE ELIMINATES THE LEGAL VALUE OF THE DOCUMENT

Now let’s remove the signature:

gs -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/default -dDetectDuplicateImages=true -sOutputFile=cleaned_step1.pdf <filename.pdf>

Check whether the digital signature survived the process:

pdfsig cleaned_step1.pdf
File 'cleaned_step1.pdf' does not contain any signatures

f you get this result, the digital signature is no longer present — for better or for worse.

If the signature was also present in graphical form, you will still see it, together with any watermarks (that topic alone would probably require a whole book).

The problem of the digital signature inside the PDF file, and of the personal data embedded in it, is now solved. The following command lets you remove a few more things

exiftool -all= -overwrite_original cleaned_step1.pdf

The file is cleaner, but not necessarily completely clean.

It is worth pointing out that if you do not check and simply upload a digitally signed file to a (possibly foreign) website, you may have just transferred third-party personal data to an entity outside the EU/EEA. Or worse: you may have given an ‘AI’ the chance to train on your texts and those of others.

MOREOVER

We are not finished yet. With programs such as LibreOffice Draw or Xournal++ it is possible to modify the graphical appearance of the PDF while leaving the underlying ASCII (or other character-set) text unchanged.

Therefore launching mc (Midnight Commander) and taking a good look inside the file seems a wise precaution in order to avoid future problems caused by discrepancies between the graphical layer and the text layer. Remember that this may not be enough to find everything — some information may be stored in compressed streams. If in doubt, use pdftotext or any other tool you prefer.

Imagine a contract in which someone has put different figures in the “graphical” layer and in the “text” layer. The ‘AI’ evaluation could then be wrong.

Or someone might have added a “prompt-engineering injection” only in the text layer; if the model takes it into account (depending on the model used), it could influence the assessment.

In fact, many ‘AI’ systems appear to use both the graphical and the textual parts. This would open the door to an attack via invisible text in the graphical layer — a subject that, in my view, would also require a book to be treated properly.

Text reviewed with the help of z.ai, Grok and Gemini.P.S. In my opinion they are just neural networks. That’s why I put the quotes around ‘AI’ (Artificial Intelligence).

Copyright © 2026 Giovambattista Vieri

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.

A copy of the license is available at gnu.org/licenses/fdl-1.3.html.