Author Topic: (Ghostscript) Join Multiple Postscript/PDF files via batch script  (Read 5456 times)

0 Members and 1 Guest are viewing this topic.

JohnK

  • Administrator
  • Seagull
  • Posts: 10638
T. Willey and I have just collaborated on a neat little postscript file combiner batch script which allows you to drag and drop files to it. Please save this code as a ``.bat'' file on your computer. You must have access to Ghostscript either installed locally or on a accessible network location.

Enjoy...
And please remember that all praise and/or monetary contributions can be directed at me (Se7en) and all criticisms may be directed at T.Willey


Code: [Select]
@echo off
:: ps_combine.bat
::
:: Given either Postscript (ps) or PDF, put all files into one PDF
:: via `drag and drop'
::
:: This batch program is meant to offer AutoCAD/Ghostscript users a
:: fast easy way to create a combined PDF production tool. It offers
:: us a way to drag and drop either pre-defined PDFs or Postscript
:: plot files.
::
:: Last Updated: 08.06.08 1:30:03 PM
::
:: A coliboration from: Se7en and T.Willey
::                      theSwamp.org
::
::
:: =================================================
:: Basic variables which might need modifications
:: depending on you setup.
::
set PROG=c:\gs\gs8.61\bin\gswin32c
set OUT=%~dp1Combined.pdf
::
:: =================================================

::
:: Begin CODE
::
rem Check that we have at least one parameter
if [%1] == [] goto noparams
call :sort %*

:noparams
echo .
echo No paramaters...Exiting now.
echo .
goto endmark

:sort
:: Code cobbled from
:: Paulius Maruska
:: http://www.codeproject.com/KB/winsdk/Batch_File_Bubble_Sort.aspx
set swaps=0
set sorted=
if $%1$ == $$ goto :sort_loop_end
set var1=%1
shift
:sort_loop
if $%1$ == $$ goto :sort_loop_end
set var2=%var1%
set var1=%1
shift
set varT=%var1%
if /I %var1% LSS %var2% (
set var1=%var2%
set var2=%varT%
set /A swaps=swaps+1
)
set sorted=%sorted% %var2%
goto sort_loop
:sort_loop_end
set sorted=%sorted% %var1%
if /I %swaps% GTR 0 (
rem echo %swaps% : %sorted%
call :sort %sorted%
)
        goto processargs

:processargs
        call %PROG% -o %OUT% -sDEVICE=pdfwrite -f %sorted%
        ::
        :: To force documents to the seascape orientation you can use the
        :: following line. Dont forget to comment out the previous line...
        ::
        :: call %PROG% -o %OUT% -sDEVICE=pdfwrite -c "<</Orientation 1>> setpagedevice" -f %sorted%
        echo .
        echo file "%OUT%" created.
        echo .
        goto endmark

:endmark
rem
rem     finished
pause
exit
rem
::
:: End CODE
::
:: EOF
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

T.Willey

  • Needs a day job
  • Posts: 5251
Re: (Ghostscript) Join Multiple Postscript/PDF files via batch script
« Reply #1 on: August 06, 2008, 05:30:53 PM »
Enjoy...
And please remember that all praise and/or monetary contributions can be directed at me (Se7en) and all criticisms may be directed at T.Willey
I don't know if I like how this calbo has worked out.  I seem to have gotten the short end of the stick.

But I do really like the batch file, and how that works.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

JohnK

  • Administrator
  • Seagull
  • Posts: 10638
Re: (Ghostscript) Join Multiple Postscript/PDF files via batch script
« Reply #2 on: August 06, 2008, 05:48:35 PM »
Oh, huh?! ...I see what your talking about: Two to one. I want to try and make it easy on everyone; I seem to have forgotten `complaints' would you like those?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org