Semi-Autocrop PDF using Inkscape command line

Programs intend to save a whole page for everything that is saved as PDF, even if the content just takes 5% of a page. If you then have to crop a large batch of PDFs manually it is really a pain, but Inkscape offers a nice way to do this using the command line.

Just create a batch file i.e. semiautocrop.bat, put the following code inside (don’t forget to change to path to you Inkscape folder, just place the path without brackets i.e. c:inkscape) and place it into the folder of your PDFs.

The batch will run through all of the PDFs in the current folder and open Inkscape to crop the PDFs. Unfortunately I didn’t find a way to omit the dialogs for importing the PDF, saving and closing Inkscape without saving a SVG.

But nonetheless it’s way faster then doing everything manually. If you have an idea how to improve this leave me a comment.

Related

HI! I make a .txt file and I put inside
for /r %cd% %%i in (*.pdf) do C:Program Files (x86)Inkscapeinkscape.exe –verb=FitCanvasToSelectionOrDrawing –verb=FileSave –verb=FileClose %%i
then, save and rename the .txt in .bat
I put the .bat in the same folder with pdf, double click on the bat, just appears/disappear a dos windows, no other effects. I wonder, where I’m wrong?
I need something like this to cut away white borders from pdf, in order to have all the pdf straighten. that’s my sake. can you help me?

The best way to check this is to use the console.
Start -> Run -> type: “cmd”
Then move with the “cd” command to the location of your “.bat”- file. And run it from there. If something is wrong there will propably be some error messages.

that’s the new sintax you suggest. I tried from CMD both the *.bat with and without quotes, the result is an italian message, which translation must be PDF NOT ATTEND. (pdf non atteso.)
if it can be useful I’m running a seven 64bit.
thank you again for your time

I updated the command and added quotes around %cd%, the path to inkscape and the last %%i

On my 64bit vista it worked like that.

Whitewizard

thank you again for your efforts but it still doesn’t work.
if I write this sintax

for /r “%cd%” %%i in (*.pdf) do “C:Program Files (x86)Inkscapeinkscape.exeinkscape.exe” –verb=FitCanvasToSelectionOrDrawing
(that is as the command line above) I receive the message Name Directory Not Valid.

If I remove inkscape.exe, with this other sintax
for /r “%cd%” %%i in (*.pdf) do “C:Program Files (x86)Inkscapeinkscape.exe” –verb=FitCanvasToSelectionOrDrawing
I receive as answer
“C:program files inkscapeinkscape.exe” –verb=FitCanvasToSelectionOrDrawing

then Inkscape start itself with a new document 1 open, but there are no change, no crop in the pdf I put in the same folder of the *.bat

you’re right, now the *.bat works well.
I still have a problem: inkscape crops the white areas only on a vectorial pdf. is there a way to have the same results with raster pdf?
anyway thank you so much for your file, your patience and your time