1326
Finished Programs / Re: IDEA: Batch merge many pdf (result : only one big pdf per subfolder)?
« Last post by 4wd on June 27, 2016, 02:10 AM »jity2's Strange PDF Thing (jsPDFt) 
Requires the files from PDF Toolkit either extract them from the setup file using UniExtract or install it and then copy the files into the same folder as the script, (then you can uninstall it).
So your folder will look like this:

Run jsPDFt.ps1 using the shortcut.
Hopefully it'll work - it did here.
NOTES:

Code: PowerShell [Select]
- <#
- jsPDFt.ps1
- Concatenate PDFs in sub-folders
- #>
- Function Get-Folder {
- Add-Type -AssemblyName System.Windows.Forms
- $FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
- [void]$FolderBrowser.ShowDialog()
- $temp = $FolderBrowser.SelectedPath
- If($temp -eq '') {Exit}
- If(-Not $temp.EndsWith('\')) {$temp = $temp + '\'}
- Return $temp
- }
- Function Get-PDF {
- Param(
- [String]$folder,
- [string]$source,
- [string]$dest,
- [string]$command
- )
- If(-Not $folder.EndsWith('\')) {$folder = $folder + '\'}
- # If there are any PDFs in the folder then execute the concatenation
- If(@(Get-ChildItem -Path ($folder + '*') -Include *.pdf -File).Count -gt 0) {
- Write-Host 'Folder:' $folder -BackgroundColor Black -ForegroundColor Yellow
- # Create output file name
- If((Split-Path -Path $folder -Leaf).EndsWith('\')) { # Input was root folder
- $outFile = $dest + '\' + $source.Substring(0, 1) + '.pdf'
- } else {
- $outFile = $dest + $folder.Replace($source, "") + '\' + (Split-Path -Path $folder -Leaf) + '.pdf'
- }
- $outFile = $outFile.Replace('\\', '\')
- # Otherwise, check if output folder exists and create if necessary
- If(-Not (Test-Path (Split-Path -Path $outFile))) {
- New-Item (Split-Path -Path $outFile) -Type Directory | Out-Null
- }
- Write-Host 'File: ' $outFile -BackgroundColor Black -ForegroundColor White
- # Compose argument string
- $arguments = '"' + $folder + '*.pdf" cat output "' + $outFile + '"'
- # Execute pdftk.exe with arguments
- Start-Process -FilePath $command -Wait -ArgumentList $arguments -NoNewWindow
- }
- }
- $console = $host.UI.RawUI
- $size = $console.WindowSize
- $size.Width = 80
- $size.Height = 30
- $console.WindowSize = $size
- If($PSVersionTable.PSVersion.Major -lt 3) {
- Write-Host '** Script requires at least Powershell V3 **'
- } else {
- Write-Host 'Choose folder with PDF files: ' -NoNewline -BackgroundColor DarkGreen -ForegroundColor White
- $srcFolder = (Get-Folder)
- Write-Host $srcFolder
- Write-Host 'Choose output folder: ' -NoNewline -BackgroundColor DarkGreen -ForegroundColor White
- Do {$dstFolder = (Get-Folder)} While($dstFolder -eq $srcFolder)
- Write-Host $dstFolder
- # Full path to pdftk.exe which should be in the same folder as Powershell script
- $pdftk = '"' + (Split-Path $SCRIPT:MyInvocation.MyCommand.Path -Parent) + '\pdftk.exe"'
- # List of sub-folders
- $aFolders = @(Get-ChildItem -Path $srcFolder -Recurse -Directory | Select-Object -ExpandProperty Fullname)
- for($i=0; $i -lt $aFolders.Count; $i++) {
- # For each sub-folder call the routine
- Get-PDF $aFolders[$i] $srcFolder $dstFolder $pdftk
- }
- # Finally, call routine on source folder
- Get-PDF $srcFolder $srcFolder $dstFolder $pdftk
- }
- Write-Host ''
- Write-Host 'Close window to exit ...'
- cmd /c pause | out-null
Requires the files from PDF Toolkit either extract them from the setup file using UniExtract or install it and then copy the files into the same folder as the script, (then you can uninstall it).
So your folder will look like this:
Run jsPDFt.ps1 using the shortcut.
Hopefully it'll work - it did here.
NOTES:
- No provision for password protected PDFs, it'll probably die a horrible death while running if it finds one.
- No provision for seeing if the output file already exists, if it does it will probably be overwritten.

Recent Posts

That's the reason I purchased the one with the HDMI DIP.