pdf-replace/README.md
2024-01-23 14:15:27 +01:00

57 lines
1.1 KiB
Markdown

# PDF Replace
About replacing text and links on PDF files.
## PDF - Print all links
See [pdf_replace/print_links.py](pdf_replace/print_links.py)
## PDF - Print text from all pages
See [pdf_replace/print_text.py](pdf_replace/print_text.py)
## PDF - Replace text or links
Source: https://gist.github.com/Nezteb/e761bb85ced6ce965e37d54ceb04635d
1) Uncompress the PDF file
```shell
nix-shell -p qpdf
qpdf --qdf --object-streams=disable input.pdf uncompressed.pdf
```
or
```shell
nix-shell -p pdftk
pdftk input.pdf output uncompressed.pdf uncompress
```
2) Edit the PDF as "plain text" file
Works:
- With `LC_ALL=C sed`
- `LC_ALL=C sed -e 's|some text||g' uncompressed.pdf > uncompressed-output.pdf`
Does **not** work:
- With `nano` by pressing `ALT` + `r` (search and replace). The resulting PDF is distorted - some text is missing or misaligned.
Untested:
- With a text editor using "search and replace". Warning, on large files this might be laggy.
3) Compress the PDF
```shell
qpdf uncompressed-output.pdf output.pdf
```
or
```shell
pdftk uncompressed-output.pdf output output.pdf compress
```