6

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
Community
  • 1
  • 1
TJR
  • 3,617
  • 8
  • 38
  • 41
  • What's in your "args.bat" file? – Mark Storer May 10 '11 at 17:24
  • @Mark Storer: I assume you did see that TJR's main batch file does (attempt to) create the content of the args.bat dynamically. You want to know what was the actual result of the `(echo.|set /p=...` part? – Kurt Pfeifle May 11 '11 at 13:34

1 Answers1

11

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....

Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
  • Viewed individually, the source pdf's are all orientated the same. The source pdf's were generated through the application Scribus. – TJR May 12 '11 at 14:18
  • @TJR: Which viewer did you use? Which viewer settings? Be aware, that viewers may be set to auto-rotate pages for viewing depending on the predominant flow direction of text strings on the page (or whatever the viewer deems "predominant"). Also, there may be a sort of "rotate for viewing" flag embedded on pages... – Kurt Pfeifle May 12 '11 at 15:08
  • @TJR: Can you provide a couple of example PDF files which display the behaviour you describe? Then I would take a closer look at them and tell you my results... – Kurt Pfeifle May 12 '11 at 16:57
  • @TJR: Which version of Ghostscript did you use? (The newest one is v9.02). – Kurt Pfeifle May 12 '11 at 16:58
  • 1
    `AutoRotatePages=/None` did the trick. I have *no* idea, though, why this is not default. – Torsten Bronger Aug 30 '17 at 16:03