abarker / pdfCropMargins

pdfCropMargins -- a program to crop the margins of PDF files
Other
349 stars 32 forks source link

Modify original without backup #62

Open samuelbradshaw opened 1 month ago

samuelbradshaw commented 1 month ago

Thanks for this library! Is it possible to modify the original without creating backup files?

If I use this command:

pdfcropmargins --percentRetain4 100 100 100 0 --pages 1 --modifyOriginal my-file.pdf

I get a bunch of backup files that I then need to clean up.

When I try this command:

pdfcropmargins --percentRetain4 100 100 100 0 --pages 1 --modifyOriginal --outfile my-file.pdf my-file.pdf

I get this error:

Error in pdfCropMargins: The input file is the same as
the output file.
abarker commented 1 month ago

The output file with --outfile cannot be the same as the input file because as currently implemented the original file is needed when writing out the new file. Also, the GUI allows for multiple crops which may need to access the original.

The --modifyOriginal option works as the very last step so it does not have that problem. For the next release I've added the option --replaceOriginal which implies --modifyOriginal but removes the original file instead of moving it to a backup filename. It can still work in conjunction with the gui, preview, and --queryModifyOriginal options.

samuelbradshaw commented 1 month ago

Awesome, thank you!

abarker commented 1 month ago

The new version has been pushed to PyPI as 2.1.4.