powershellpdfsplitpdftk

Create multiple PDF files from one large PDF file based on page


I have a large PDF file containing employee information. One page per employee, 500+ pages. I need to create a single PDF file per employee by splitting out this large file into smaller ones. I researched similiar questions regarding that subject here and found a answer that may help but I have run into a glitch of sorts.

While the code executes without errors and says it is processing the files, even giving the file name, it outputs nothing at all. by output I mean no files are created

I am using PDFtk to accomplish this on Powershell. Hopefully someone can point out why I am not getting any output.

this is my code

$pdfPath = 'C:\pdffiles\'
$pdfFile = Join-Path $pdfPath "empdf.pdf"
$OutDir = "C:\TestOutput\"
$SetsOfPages = 2
$NumberOfPages = 546
for ($Page=1;$Page -le $NumberOfPages;$Page+=$SetsOfPages){
  $File = Get-Item $pdfFile
  $Range = "{0}-{1}" -f $page,[math]::min($Page+$SetsOfPages-1,$NumberOfPages)
  $OutFile = Join-Path $OutDir ($File.BaseName+"_$Range.pdf")
  "processing: {0}" -f $OutFile
  pdftk $pdfFile cat $Range Burst output $OutFile
}

I have ensured that the pdftk executable file is in the proper location. The code runs without any displayed errors.


Solution

  • "My pleasure, @RobinOlsen. It is actually $env:PATH that matters here, but, yes, locating the executable isn't the problem here. Rather, it seem like pdftk.exe's installation is incomplete or got corrupted ("module" in the context of the cited error (-1073741515, "The specified module could not be found.") does not refer to PowerShell modules).
    I'm not familiar with pdftk.exe, but you can try reinstalling it."

    –mklement0