« Linux tools PDF » : différence entre les versions
| (9 versions intermédiaires par le même utilisateur non affichées) | |||
| Ligne 1 : | Ligne 1 : | ||
== | == '''🧰 <code>ghostscript</code> ''' == | ||
'''<code>ghostscript</code>''' est un outil pour compresser des fichiers pdf | |||
<syntaxhighlight lang="bash" copy> | <syntaxhighlight lang="bash" copy> | ||
gs -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook -sOUTPUTFILE=fichier_outout.pdf -f input.pdf | gs -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook -sOUTPUTFILE=fichier_outout.pdf -f input.pdf | ||
| Ligne 19 : | Ligne 20 : | ||
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=fichier_outout_screen.pdf input.pdf | gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=fichier_outout_screen.pdf input.pdf | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== | |||
== '''🧰 <code>img2pdf</code> ''' == | |||
<syntaxhighlight lang="bash" copy> | <syntaxhighlight lang="bash" copy> | ||
| Ligne 30 : | Ligne 33 : | ||
== '''🧰 <code>pdftk</code> ''' == | == '''🧰 <code>pdftk</code> ''' == | ||
'''<code>pdftk</code>''' est un outil pour fusionner des fichiers pdf | |||
<syntaxhighlight lang="bash"> | === 🚀 '''Utilisation de base''' === | ||
<syntaxhighlight lang="bash" copy>sudo apt-get install pdftk</syntaxhighlight> | |||
<syntaxhighlight lang="bash" copy>pdftk fichier1.pdf fichier2.pdf cat output fichier3.pdf</syntaxhighlight> | |||
</syntaxhighlight> | <syntaxhighlight lang="bash" copy>pdftk mon-document.pdf output mon-document.comprimé.pdf compress</syntaxhighlight> | ||
source https://debian-facile.org/doc:editeurs:pdftk | source https://debian-facile.org/doc:editeurs:pdftk | ||
| Ligne 41 : | Ligne 44 : | ||
== '''🧰 <code>pdftotext</code> ''' == | == '''🧰 <code>pdftotext</code> ''' == | ||
'''<code>pdftotext</code>''' | '''<code>pdftotext</code>''' est un outil en ligne de commande issu de la suite **Poppler** | ||
permettant d’extraire le texte brut contenu dans un fichier PDF. | permettant d’extraire le texte brut contenu dans un fichier PDF. | ||
Il est très utilisé pour l’analyse, l’indexation, la recherche ou le traitement | Il est très utilisé pour l’analyse, l’indexation, la recherche ou le traitement | ||
| Ligne 52 : | Ligne 55 : | ||
sudo apt install poppler-utils | sudo apt install poppler-utils | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==== ℹ️ À noter ==== | |||
Le paquet '''<code>poppler-utils</code>''' fournit plusieurs outils PDF utiles, dont : | |||
* <code>pdfinfo</code> → informations sur le PDF (pages, auteur, version…) | |||
* <code>pdftotext</code> → extraction du texte | |||
* <code>pdfimages</code> → extraction des images | |||
* <code>pdffonts</code> → liste des polices | |||
* <code>pdfseparate</code> / <code>pdfunite</code> | |||
----- | ----- | ||
| Ligne 117 : | Ligne 131 : | ||
----- | ----- | ||
== '''🧰 <code>pdfinfo</code> ''' == | |||
(fournie par `poppler-utils`) | |||
=== 1️⃣ Informations de base sur un PDF === | |||
<syntaxhighlight lang="bash">pdfinfo document.pdf</syntaxhighlight> | |||
Exemple de sortie : | |||
<pre>Title: Rapport annuel | |||
Author: ACME Corp | |||
Creator: LibreOffice | |||
Producer: LibreOffice | |||
CreationDate: Mon Jan 15 10:22:00 2024 | |||
ModDate: Tue Jan 16 09:10:00 2024 | |||
Pages: 42 | |||
Page size: 595 x 842 pts (A4) | |||
File size: 1234567 bytes | |||
PDF version: 1.7</pre> | |||
----- | |||
=== 2️⃣ Obtenir uniquement le nombre de pages === | |||
<syntaxhighlight lang="bash">pdfinfo document.pdf | grep Pages</syntaxhighlight> | |||
Utile pour : | |||
* scripts | |||
* validation avant traitement | |||
* automatisation (batch PDF) | |||
----- | |||
=== 3️⃣ Connaître la taille et l’orientation des pages === | |||
<syntaxhighlight lang="bash">pdfinfo document.pdf | grep "Page size"</syntaxhighlight> | |||
Résultat typique : | |||
<pre>Page size: 842 x 595 pts (A4)</pre> | |||
➡️ paysage (landscape) | |||
----- | |||
=== 4️⃣ Vérifier si le PDF est protégé === | |||
<syntaxhighlight lang="bash">pdfinfo document.pdf | grep Encrypted</syntaxhighlight> | |||
Sortie possible : | |||
<pre>Encrypted: yes</pre> | |||
👉 Indique qu’un mot de passe est requis (à traiter ensuite avec <code>qpdf</code>) | |||
----- | |||
=== 5️⃣ Afficher les métadonnées complètes === | |||
<syntaxhighlight lang="bash">pdfinfo -meta document.pdf</syntaxhighlight> | |||
Affiche les métadonnées XMP (XML), très utile pour : | |||
* audit | |||
* conformité | |||
* analyse forensique légère | |||
----- | |||
=== 6️⃣ Informations page par page === | |||
<syntaxhighlight lang="bash">pdfinfo -box document.pdf</syntaxhighlight> | |||
Montre : | |||
* MediaBox | |||
* CropBox | |||
* BleedBox | |||
* TrimBox | |||
Utile en '''impression professionnelle'''. | |||
----- | |||
=== 7️⃣ Script shell : compter les pages === | |||
<syntaxhighlight lang="bash">PAGES=$(pdfinfo document.pdf | awk '/Pages/ {print $2}') | |||
echo "Nombre de pages : $PAGES"</syntaxhighlight> | |||
----- | |||
=== 8️⃣ Tester si un PDF contient du texte exploitable === | |||
<syntaxhighlight lang="bash">pdfinfo document.pdf && pdftotext document.pdf -</syntaxhighlight> | |||
➡️ si <code>pdftotext</code> ne sort rien → PDF scanné | |||
----- | |||
=== 9️⃣ Batch sur plusieurs fichiers === | |||
<syntaxhighlight lang="bash">for f in *.pdf; do | |||
echo "== $f ==" | |||
pdfinfo "$f" | grep Pages | |||
done</syntaxhighlight> | |||
----- | |||
=== ⚠️ Notes importantes === | |||
* <code>pdfinfo</code> '''n’extrait pas le texte''' | |||
* il '''n’altère jamais''' le fichier | |||
* fonctionne même sur PDF protégés (lecture des infos seulement) | |||
----- | |||
=== 🧠 Résumé rapide === | |||
{| class="wikitable" | |||
|- | |||
! Besoin | |||
! Commande | |||
|- | |||
| Infos générales | |||
| <code>pdfinfo file.pdf</code> | |||
|- | |||
| Pages | |||
| <code>grep Pages</code> | |||
|- | |||
| Sécurité | |||
| <code>grep Encrypted</code> | |||
|- | |||
| Métadonnées | |||
| <code>pdfinfo -meta</code> | |||
|- | |||
| Mise en page | |||
| <code>pdfinfo -box</code> | |||
|} | |||
----- | |||
== '''🧰 <code>qpdf</code> ''' == | == '''🧰 <code>qpdf</code> ''' == | ||
| Ligne 197 : | Ligne 352 : | ||
----- | ----- | ||
== '''🧰 <code>ExifTool</code> ''' == | |||
voir [[Logiciels_terminal#🧰_ExifTool|ExifTool]] | |||
[[Catégorie:Linux]] [[Catégorie:Tools]] [[Catégorie: Terminal Tools]] | [[Catégorie:Linux]] [[Catégorie:Tools]] [[Catégorie: Terminal Tools]] | ||