Marco
Marco

Reputation: 55

PDFs - Delete all pages except the 1st page in a PDF in a folder

I really need some help as my script works but makes a mess

@echo off
set OutputFilePath=trimmed

pushd 
for /r %%i in (*.pdf) do (
       pdftk "%%i" cat 1 output "%OutputFilePath%%%~ni-1stpage%%~xi"
)
popd

Can someone help to correct my script as follows

  1. Have it scan only in the current directory, currently it goes also in sub folder and it also processes the files already done.

It can also by something brand new also in PowerShell or Python

Upvotes: 0

Views: 961

Answers (2)

lit
lit

Reputation: 16266

If you wanted to try this in PowerShell, the following might work.

Get-ChildItem -File -Path 'C:\src\t' -Filter '*.pdf' |
    ForEach-Object {
        pdftk $_.FullName cat 1 output "C:\pdf\new\dir\$($_.BaseName)-1stpage$($_.Extension)"
    }

Upvotes: 0

Marco
Marco

Reputation: 55

Thank Lit for your tips, worked with that to get the answer. I created the following script

@echo off
set OutputFilePath=<output path>

pushd 
for %%i in (*.pdf) do (
    pdftk "%%i" cat 1 output "%OutputFilePath%%%~ni-1stpage%%~xi"
)
popd

Upvotes: 1

Related Questions