rotating an A3 pdf from landscape to portrait

  • afylot

    afylot - 2011-03-26

    I am trying to rotate a pdf document of 10 pages in landascape A3 format, in order to get an A3 portrait.
    My final goal is to get 10 separate tiff images in portrait, in order to use them as input files for an OCR software.
    I was considering to break the problem in two pieces:
    pdf -> rotated pdf
    rotated pdf -> 10 separate tiff
    I am using

    gs -SDEVICE=tiffg4 -r600x600 -sPAPERSIZE=letter -sOutputFile={output folder}/{basename}_%04d.tif -dNOPAUSE -dBATCH - {pdf filename}

    for the second task and it works. 
    I don't know how to accomplish the first one. I tried

    gs -dBATCH -dNOPAUSE -sOutputFile=output_file.pdf -sDEVICE=pdfwrite -dAutoRotatePages=/None \
    -c "<< /PageSize  /Orientation 0 >> setpagedevice" 90 rotate 0 -612 translate -f input_file.pdf


    gs -dBATCH -dNOPAUSE -sOutputFile=output_file.pdf -sDEVICE=pdfwrite  \
    -c "<< /PageSize   >> setpagedevice"  -f input_file.pdf

    but I haven't succeeded. How can I transform this pdf from landscape to portrait?

    Thank you

  • Roger Womersley

    Roger Womersley - 2011-03-28

    I would suggest looking at the following parameter list:

    -c "<< /PageSize   /ImagingBBox null /BeginPage{ 90 rotate 841 0 translate} >> setpagedevice"
    -f input_file.pdf

    You could even do it in one step. I'm not sure why you reference -sPAGESIZE=letter when you are after A3 size pages.
    I tend to generate a text file with the parameters on single lines then call GS using the @ directive to treat the file as a parameter list.

    Good luck !

  • Russell Lang

    Russell Lang - 2011-03-28

    When ghostscript processes a PDF file, it set the page size for each page from the PDF MediaBox.  Setting the page size on the ghostscript command line doesn't help, because it will be overriden.

    Here is the method used in GSview:
    -c "<< /Policies << /PageSize 5 >> /PageSize  "
    /InputAttributes currentpagedevice
    /InputAttributes get mark exch {1 index /Priority eq not
    {pop << /PageSize  >>} if } forall >>
    >> setpagedevice" -f input.pdf

    This sets the page size to A3, and then says it is the only available page size, and that ghostscript should attempt to make it fit on that page (rotating if needed).


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks