ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Finished Programs

DONE: batch print silently pdf-2-pdf using SumatraPdf and Bullzip

(1/2) > >>

jity2:
Dear all,

I have noticed that trying to OCR some of my PDF files causes a crash. But if I open the file with (and only!) SumatraPDF I can print the pdf to a pdf file (with bullzip) and get a new pdf file that I can then OCR successfully. ;)
So I need to print pdf-to-pdf many pdf files gathered inside one big folders and its many sub-folders.

I thought that an .ahk script would help me : I choose the folder where I have the original pdf files. It opens SumatraPDF silently, it logs the possible files in error then continue, and print to the default free printer Bullzip silently.
I have already chosen the default output folder and the silent part in the settings of Bullzip.

I have tried to adapt an old ahk file to my purpose, but it doesn't work. ;(


--- ---FileSelectFolder,SourcePath,,0,Select Source Folder
If SourcePath =
ExitApp

Loop,%SourcePath%\*.*,2,0
{
FolderSize = 0
Loop, %A_LoopFileFullPath%\*.*, , 1
FolderSize += %A_LoopFileSize%
If FolderSize >0
RunWait,C:\Program Files (x86)\SumatraPDF\SumatraPDF.exe  -print-to-default -silent "%A_LoopFileFullPath%\*.*"
}
Many thanks in advance ;)

ps: I also use these freeware a lot which helps reduce the list of pdf files which have problems with OCR : PDF Text Checker https://www.donationcoder.com/forum/index.php?topic=27311.0, PDFInfoGUI http://skwire.dcmembers.com/fp/?page=pdfinfogui both from skwire and this command line script WINDOWS+R : https://www.donationcoder.com/forum/index.php?topic=35339.msg330784#msg330784

4wd:
NOTE: Only written for the OP's original purpose - requires SumatraPDF and Bullzip.

In Powershell, run it using the shortcut:


--- Code: PowerShell ---<#  PrintPDFs.ps1    Print PDFs to default Bullzip PDF printer using SumatraPDF#> 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}   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   $aFiles = (Get-ChildItem -Include *.pdf -Path ($srcFolder + "*") -Recurse)  for($i=0; $i -lt $aFiles.Count; $i++) {    $inFile = [string]$aFiles[$i]    Write-Host 'File:' $inFile -BackgroundColor DarkBlue -ForegroundColor Yellow    $outFile = '  output=' + $dstFolder + $inFile.Replace($srcFolder, "")    Write-Host '-->' $outFile -BackgroundColor DarkBlue -ForegroundColor White    (Get-Content "$Env:APPDATA\PDF Writer\Bullzip PDF Printer\settings.ini") `      -Replace "(^..output=.+\.pdf$)", $outFile | `      Out-File "$Env:LOCALAPPDATA\PDF Writer\Bullzip PDF Printer\runonce.ini"    Start-Sleep -Seconds 2    $args = '-print-to-default -silent "' + $inFile + '"'    Start-Process -FilePath "C:\Program Files (x86)\SumatraPDF\SumatraPDF.exe" -Wait -ArgumentList $args  }}Write-Host ''Write-Host 'Close window to exit ...'cmd /c pause | out-null
First turn off Print Spooling in the Printer Properties:

DONE: batch print silently pdf-2-pdf using SumatraPdf and Bullzip

This is so a job finishes before the next is sent (was the easiest way to do it)


* Run the script from the shortcut
* Select the source folder (where the PDFs are)
* Select the destination folder
For each file it will rewrite the "output= ..." line in settings.ini (%APPDATA%\PDF Writer\Bullzip PDF Printer\settings.ini) and save the new file as runonce.ini (%LOCALAPPDATA%\PDF Writer\Bullzip PDF Printer\runonce.ini).  Bullzip uses this file in preference to settings.ini if it exists and deletes it after a job is finished.

Once it's finished you can re-enable Print Spooling for Bullzip.

I've included the Bullzip settings.ini file I was testing it with for comparison.

UPDATED (20160609):

* Won't let you choose destination folder same as source folder, just loops until they are different.
* Can now choose drive root of source folder for destination, (barring condition where they are both the same) - strips the source path from the file path/name so the output folder structure is a bit more normal, ie. the extra folder levels aren't output.

jity2:
Hi 4wd,
Many thanks for your help. ;)

I tested your code and it is working. ;) Alas I have made an error : I can select the output folder in Bullzip but it does not create the same subfolders of the source by itself. It put all processed pdf files into the same folder. ;(
This is very annoying for me as I need this.
Any idea ? Maybe using another pdf printer (apparently Bullzip runs in part ghostscript ; I also found this link but I don't understand everything! http://www.techrepublic.com/forums/discussions/printing-microsoft-access-report-as-pdf-to-specific-folder/) ?

Many thanks in advance ;)

4wd:
If you drop the -Recurse parameter from the following line:

$aFiles = (Get-ChildItem ...

then it will only do the folder you choose, no sub-folders.  You can then do a folder at a time changing the output folder for Bullzip as you go - slow but an easy way to do it.

I'll download Bullzip/SumatraPDF and play.

EDIT: Looks like you can specify the full output path/file for Bullzip's next job by using the config command it comes with, eg: config.exe /S "Output" "X:\output\<basedocname>.pdf"

jity2:
Hi "4wd",

I haven't seen you edit before. Sorry. Thanks for your answer. ;)

Great find. My config is located at : C:\Program Files\Bullzip\PDF Printer\API\EXE\config.exe

So I guess I should add somewhere in your code the line :
C:\Program Files\Bullzip\PDF Printer\API\EXE\config.exe /S "Output_folder_or_subfolder" "I:\output_folder_or_subfolder\<basedocname>.pdf"


Also, would it be possible that the code sends only one file to be printed ?  Then it is printed by Bullzip. Then once bullzip has finished, the code sends another file to be printed ? I ask this because I have noticed that if I add many pdf to be printed, my computer becomes not responsive. I have checked and a 10 MB pdf file become easily a 2 GB or more (no typo!) file to be printed !

Thanks in advance ;)


Navigation

[0] Message Index

[#] Next page

Go to full version