I wrote it exactly the same way you say in the video, but it doesn't work. I tried to install an older version, but it didn't work either, I could tell you what I did wrong: CODE: $homedir = 'C:\Users\mattt\Desktop\SC' $pickup = $homedir+'\drop' $completed = $path+'\compressed' $ghost = 'C:\Program Files\gs\gs10.02.1\bin\gswin64c.exe' $pdfs = Get-ChildItem $pickup\*.pdf -File foreach ($pdf in $pdfs){
**** Unable to open the initial device, quitting. When I tried with an older version it gave the same problem. If you know of anything that could solve this, it would help me a lot.
Seems as though its not being run on the entire path of the pdf as the error references " \compressed\compressed-NukeSurvivalToolkit_Documentation_Release_v2.1.0.pdf". Try changing the ghostscript call to the full path of the pdf - $pdf.FullName. Do something like $file = $pdf.fullname then & "$ghost" $Prms "$file"
So I thjis script works, and it does output the compressed PDF files, however it also throws a error message. PowerShell Script: $original = "C:\Location\of\original\PDFs" $compressed = "C:\location\to\place\compressed\PDFs\" # Ghost Script EXE Path Version could be different make sure the path is correct. $ghost = 'C:\Program Files\gs\gs10.03.0\bin\gswin64c.exe' # Pull in all of the PDF files in the Original Path. $pdfs = Get-ChildItem $original\*.pdf -File # Begin loop through all of the PDF files in Original path. foreach ($pdf in $pdfs){
# Rename the compressed files with the word Compressed at the end of file name. $new = $compressed +$pdf.BaseName +'-compressed'+'.pdf' # GhostScript Parameters: $parm = " -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dSubsetFonts=true -dColorImageDownsampleType=/Bicubic -dColorImageResolution=144 -dGrayImageResolution=144 -dMonoImageDownsampleType=/Bicubic -dMonoImageResolution=144 -sOutputFile=$new " # Split the Ghostscript parameters into new lines. $Prms = $parm.Split(" ") # Run Process "&" is similiar to Start-Process. & "$ghost" $Prms "$pdf"
GPL Ghostscript 10.03.0: Can't use an XRef stream before PDF 1.5, ignoring WriteXRefStm directive --- Any idea what the error message is? It still compresses the PDF and seems to just ignore a WriteXRefStm parameter.
Hi, when i run the script, the shell require me hit the "Enter" button for every pages in the pdf and when it is done there is no output file.
I wrote it exactly the same way you say in the video, but it doesn't work. I tried to install an older version, but it didn't work either, I could tell you what I did wrong:
CODE:
$homedir = 'C:\Users\mattt\Desktop\SC'
$pickup = $homedir+'\drop'
$completed = $path+'\compressed'
$ghost = 'C:\Program Files\gs\gs10.02.1\bin\gswin64c.exe'
$pdfs = Get-ChildItem $pickup\*.pdf -File
foreach ($pdf in $pdfs){
$new = $completed+'\compressed-'+$pdf.Name
$parm = " -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dSubsetFonts=true -dColorImageDownsampleType=/Bicubic -dColorImageResolution=144 -dGrayImageResolution=144 -dMonoImageDownsampleType=/Bicubic -dMonoImageResolution=144 -sOutputFile=$new "
$Prms = $parm.Split(" ")
& "$ghost" $Prms "$pdf"
}
ERRO:
gswin64c.exe : GPL Ghostscript 10.02.1: **** Could not open the file
\compressed\compressed-NukeSurvivalToolkit_Documentation_Release_v2.1.0.pdf .
At line:1 char:1
+ & "$ghost" $Prms "$pdf"
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (GPL Ghostscript...se_v2.1.0.pdf .:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
**** Unable to open the initial device, quitting.
When I tried with an older version it gave the same problem. If you know of anything that could solve this, it would help me a lot.
Seems as though its not being run on the entire path of the pdf as the error references " \compressed\compressed-NukeSurvivalToolkit_Documentation_Release_v2.1.0.pdf". Try changing the ghostscript call to the full path of the pdf - $pdf.FullName. Do something like $file = $pdf.fullname then & "$ghost" $Prms "$file"
So I thjis script works, and it does output the compressed PDF files, however it also throws a error message.
PowerShell Script:
$original = "C:\Location\of\original\PDFs"
$compressed = "C:\location\to\place\compressed\PDFs\"
# Ghost Script EXE Path Version could be different make sure the path is correct.
$ghost = 'C:\Program Files\gs\gs10.03.0\bin\gswin64c.exe'
# Pull in all of the PDF files in the Original Path.
$pdfs = Get-ChildItem $original\*.pdf -File
# Begin loop through all of the PDF files in Original path.
foreach ($pdf in $pdfs){
# Rename the compressed files with the word Compressed at the end of file name.
$new = $compressed +$pdf.BaseName +'-compressed'+'.pdf'
# GhostScript Parameters:
$parm = " -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dSubsetFonts=true -dColorImageDownsampleType=/Bicubic -dColorImageResolution=144 -dGrayImageResolution=144 -dMonoImageDownsampleType=/Bicubic -dMonoImageResolution=144 -sOutputFile=$new "
# Split the Ghostscript parameters into new lines.
$Prms = $parm.Split(" ")
# Run Process "&" is similiar to Start-Process.
& "$ghost" $Prms "$pdf"
}
Error Message:
gswin64c.exe : GPL Ghostscript 10.03.0: Can't use Object streams before PDF 1.5, ignoring WriteObjStms directive
At line:16 char:4
+ & "$ghost" $Prms "$pdf"
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (GPL Ghostscript...jStms directive:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
GPL Ghostscript 10.03.0: Can't use an XRef stream before PDF 1.5, ignoring WriteXRefStm directive
---
Any idea what the error message is? It still compresses the PDF and seems to just ignore a WriteXRefStm parameter.