Using PDFTK in PowerShell to Concatenate files RRS feed

  • Question

  • Hello All,

    I have the following code in a Powershell script:

    $pdfext = ...\PDFUnlock\pdftk.exe $file unpack_files output $rootFnNoExt

    which works. I need to now take those pdf files that were unpacked and repack them, there may be 1 or more (pdf) files 

    for that I have the following code:

    $pdfcom = '$rootFnNoExt\pdftk.exe *.pdf CAT OUTPUT $rootFnNoExt\test.pdf'

    which of course does not work. I have tried a multitude of different code but nothing seems to work.  By the way the syntax for pdftk to concatenate files is:

    pdftk.exe file1 file2 file3 cat output fileall.pdf or pdftk.exe *.pdf cat output fileall.pdf 

    I am not asking for anyone to write the script but just to steer me in the right direction



    Thursday, June 23, 2016 6:50 PM


All replies

  • You need to ask the author of the utility.  This is not a scripting issue it is an issue of how to use a third party utility.


    Thursday, June 23, 2016 7:10 PM
  • Hi Bernard,

    One point - don't use single quotes around variables, as that will prevent them from expanding.

    Thursday, June 23, 2016 7:14 PM
  • I know how to use the third party utility, I just don't know how to use it/call it within PowerShell.  As can be seen from the first line of code that I mentioned, that works. I am missing something for the other line of code can't figure out what - although I am leaning towards the *.pdf.


    Thursday, June 23, 2016 7:26 PM
  • Will keep that in mind but I have used double quotes and no quotes.... to no avail.


    Thursday, June 23, 2016 7:27 PM
  • To run an executable, just put its name in the script.

    Do not add parameters after the executable's name within a string and try to execute it. Put the command name, and after that put the parameters.

    Read this first:

    Windows IT Pro - Running Executables in PowerShell

    -- Bill Stewart [Bill_Stewart]

    Thursday, June 23, 2016 7:29 PM
  • Will give that a try.


    Thursday, June 23, 2016 7:38 PM