Skip to content

Add an option to shrink the PDF file where it is#23

Open
arwarw wants to merge 2 commits intoaklomp:masterfrom
arwarw:inplace
Open

Add an option to shrink the PDF file where it is#23
arwarw wants to merge 2 commits intoaklomp:masterfrom
arwarw:inplace

Conversation

@arwarw
Copy link
Copy Markdown

@arwarw arwarw commented Jun 29, 2025

This makes use of a temporary directory that is securely (as far as possible) created and cleaned up.

arwarw added 2 commits June 29, 2025 18:09
Add an option -i to replace the input file with the shrunk output (if
smaller). This creates a temporary directory in a secure and portable
manner, cleaning it up afterwards.

The temporary directory is created using 'mktemp' if present, otherwise
the less secure method of including the PID, current time and possibly
(if available) $RANDOM is used. The directory is removed upon exit, but
carefully: 'rm -fr' is only executed on a then-empty directory after
output.pdf has been removed. This could leak directories, but I consider
that less of a problem than possibly removing something important.
@arwarw arwarw mentioned this pull request Jun 29, 2025
@camlafit
Copy link
Copy Markdown

camlafit commented Apr 7, 2026

Hello,

Looks nice, I was looking for a way to manage in‑place behaviour.
Why do you create a temporary directory instead of a temporary file directly?

It could also be interesting if, when -o is not set, it implied in‑place mode by default.

@arwarw
Copy link
Copy Markdown
Author

arwarw commented Apr 7, 2026

Looks nice

Thanks!

Why do you create a temporary directory instead of a temporary file directly?

I made a habit out of always using temporary directories instead of files because it's easier to clean up and less prone to race conditions in case one needs multiple files. I guess in this case one could also just use a file.

It could also be interesting if, when -o is not set, it implied in‑place mode by default.

Yes, maybe. On the other hand I'm not sure if existing users would appreciate their files being overwritten in the new behaviour. I thought it would be better to have an explicit switch for that behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants