Note that there are some explanatory texts on larger screens.

plurals
  1. POPowerShell and GhostScript
    primarykey
    data
    text
    <p>I have a batch script that loops over a folder and flattens the PDFs inside it using GhostScript (9.07). I want to convert it to a PowerShell script because it seems to like to crash every once in a while and I'm just tired of debugging batch files.</p> <p>Anyway, I have a PS script that seems to work, based on it's output in the console, but I don't actually get any files. Manual entry in PS seems to work even less... What am I doing wrong?</p> <p><strong>Batch Script</strong></p> <pre><code>@ECHO OFF :: :: Process all PDFs and flatten them to PDF/A format :: ===================================================================================== FOR %%F IN ("J:\Finals\*.pdf") DO ( IF /I %%F NEQ "*Floor Plan*.pdf" ( :: Convert the original PDF to a flattened PDF PDF/A :: ======================================================================== "%ProgramFiles%\gs\gs9.07\bin\gswin64.exe" -dPDFA -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile="J:\Finals\%%~nF (Final).pdf" "%%F" :: :: Delete the original PDF file :: ======================================================================== DEL "%%F" /F /Q :: :: Rename the flattened PDF PDF/A to the original PDF's name :: ======================================================================== MOVE "J:\Finals\%%~nF (Final).pdf" "%%F" ) ) :: :: Move files form the Readdle drive to the Digital Documents drive :: ===================================================================================== ROBOCOPY J:\Finals\ K:\ *.* /MOV /R:0 /W:0 /MT </code></pre> <p><strong>PowerShell Script (so far)</strong></p> <pre><code>$GhostScript = "$env:ProgramFiles\gs\gs9.07\bin\gswin64c.exe" Get-ChildItem "C:\Test In\*.pdf" | Where { $_.BaseName -NotMatch "Floor Plan" } | ForEach-Object { $InputFile = $_.FullName $OutputFile = "C:\Test Out\{0} (Final).pdf" -F $_.BaseName &amp; "$GhostScript" -dPDFA -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile="$OutputFile" "$InputFile" } </code></pre> <p><strong>Output of the PowerShell Script</strong></p> <pre><code>GPL Ghostscript 9.07 (2013-02-14) Copyright (C) 2012 Artifex Software, Inc. All rights reserved. This software comes with NO WARRANTY: see the file PUBLIC for details. Processing pages 1 through 1. Page 1 Substituting font Times-Italic for TimesNewRomanPS-ItalicMT. Loading NimbusRomNo9L-ReguItal font from %rom%Resource/Font/NimbusRomNo9L-ReguItal... 4198200 2870566 3665244 2332637 3 done. Substituting font Courier for CourierNewPSMT. Loading NimbusMonL-Regu font from %rom%Resource/Font/NimbusMonL-Regu... 3755680 2306439 4089108 2566088 3 done. Loading NimbusRomNo9L-Regu font from %rom%Resource/Font/NimbusRomNo9L-Regu... 3796376 2391131 4078352 2484871 3 done. Loading Dingbats font from %rom%Resource/Font/Dingbats... 3917480 2509851 4280192 2689988 3 done. </code></pre> <p>For anyone who cares this is being tested on a Windows Server 2008 R2 virtual machine. It has 4GB of RAM and 4vCPUs. I've also checked if there was permissions issues with the test folders I was using and it wasn't the case.</p> <p><strong>UPDATE</strong></p> <p>I've updated my post to show what the current script looks like. Surrounding the <code>$OutputFile</code> variable in quotes doesn't do anything. Regardless of quotes or not, I always get output (which I've added above) that indicates the GhostScript is doing what it's supposed to, but ultimately I get no file created...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload