-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathclean_metadata_pdf.sh
executable file
·50 lines (44 loc) · 1.03 KB
/
clean_metadata_pdf.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env bash
set -e
# set -x
################################################################################
# Removes metadata and optionally set author and title
#
# Usage:
# bash clean_metdata_pdf.sh [-t] [-a] file.pdf
#
# Arguments:
# -t or --title: new title
# -a or --author: new author
##
# Please report issues at https://github.com/jfilter/pdf-scripts/issues
#
# related: https://0xacab.org/jvoisin/mat2
#
# GPLv3, Copyright (c) 2020 Johannes Filter
################################################################################
title="" && author=""
while [[ "$#" -gt 2 ]]; do
case $1 in
-t | --title)
title="$2"
shift
;;
-a | --author)
author="$2"
shift
;;
*)
echo "Unknown parameter passed: $1"
exit 1
;;
esac
shift
done
# remove all metdata
exiftool -all= "$1"
# set only the most important
exiftool -Title="$title" -Author="$author" "$1"
# exitool only adds new data, but does not remove old one. The following command
# fixes the PDF ultimately.
qpdf --linearize "$1" "$1".tmp && mv "$1".tmp "$1"