Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ghostscript merge of pdf's is causing orientation to flip

Ghostscript merge of pdf's is causing orientation to flip

I'm using a similar method as this SO question: How to merge two postscript files together?

On the merged PDF, every couple pages are flipped upside down. I haven't seen it mentioned anywhere else about this symptom. Merging a single troublesome pdf still has the orientation upside down.

@echo off
REM FILE: merge.bat

call :merge 1 155 out.pdf
pause
goto :eof

REM MERGE PDFs
REM @param # of first file in sequence
REM @param # of last file in sequence
REM @param new file of merged pdf
goto :eof
:merge
SET START=%1
SET END=%2
SET OUT=%3
echo START=%START%
echo END=%END%
echo OUT=%OUT%
echo.
SET CMD="c:\Program Files\gs\gs9.01\bin\gswin32c.exe"
SET INPUT_DIR=c:\input
SET CMD_ARGS=args.bat
echo Generating args file...
(echo.|set /p="-dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=%OUT% ") > %CMD_ARGS%
for /L %%G IN (%START%,1,%END%) do (
  (echo.|set /p=" "%INPUT_DIR%\%%G.pdf" ") >> %CMD_ARGS%
)
echo. >> %CMD_ARGS%
del %OUT%
if exist %OUT% goto :error
echo Executing command...
%CMD% @%CMD_ARGS%
del %CMD_ARGS%
echo Done.
if not exist %OUT% goto :error
goto :eof

:error
echo Error processing command.
goto :eof
like image 831
TJR Avatar asked May 10 '11 00:05

TJR


1 Answers

TJR, you could try to play with adding one of the following commandline parameters to your Ghostscript call:

-dAutoRotatePages=/None
-dAutoRotatePages=/All 
-dAutoRotatePages=/PageByPage

If this doesn't change the outcome, try this instead:

gswin32c.exe ^
 -o c:/path/to/output.pdf ^
 -sDEVICE=pdfwrite ^
 -dPDFSettings=/prepress ^
 -dAutoRotatePages=/None ^
 -c "<</Orientation 0>> setpagedevice" ^
 -f /path/to/first.pdf ^
    /path/to/second.pdf ^
    /path/to/third.pdf 

The part with /Orientation 0 should turn all pages to portrait. Using 3 should make it landscape (1 for seascape, 2 for upside down).

However, this will not work reliably, because (some of) your source files may be containing weird page orientation and rotation settings of their own. In this case only a 'repair' of the source files one by one will be able to fix this....

like image 54
Kurt Pfeifle Avatar answered Oct 19 '22 00:10

Kurt Pfeifle