PDFCreator - Page Orientation Solved :-)

Hi,

I really need to create landscape slides (PDFs) from landscape printing from a vb.net application. Unfortunately, for the last 5 years, PDFCreator always decided to print the PDF’s with a portrait orientation. I then turn them using a Web PDF Rotation service.

So I had a look under the bonnet of PDFCreator and realised it is little more than a wrapper around a product called Ghostscript. More reading suggested the Ghostscript’s autorotatepages function was struggling and needed a hand. Lots of reading of the Postscript Manuals left me realising that I need PDFCreator to read this line of Postscript:

-c "<</Orientation 3>> setpagedevice"

I set the “Additional Ghostscript parameters” textbox in PDFCreator and tried again. Still no luck!

I searched for other approaches and found this:

<< 
 /EndPage 
 { exch pop 2 ne 
   { [{ThisPage} <</Rotate 90>> /PUT pdfmark true} 
 {false}ifelse 
 } 
>>setpagedevice 

I could see no way to prefix this with a “-c” so I saved it in a file called rotate.ps, in the “C:\Program Files\PDFCreator\GS9.10\gs9.10\Lib” folder and put rotate.ps in the “Additional Ghostscript parameters” textbox.

This time I had success. The output from my application reliably produces landscape output from a landscape original.

Whats more if “<</Orientation 3>> setpagedevice” is put into the rotate.ps file this works too!

So like buses, I now have two different functional solutions.

I would be grateful if a pdfforge engineer, a Ghostscript engineer or a postscript professional would comment about the functioning of “-c”.

Thanks

Hi,

from Ghostscript docs:
“-c string …
Interprets arguments as PostScript code up to the next argument that begins with “-” followed by a non-digit, or with “@”. For example, if the file quit.ps contains just the word “quit”, then -c quit on the command line is equivalent to quit.ps there. Each argument must be valid PostScript, either individual tokens as defined by the token operator, or a string containing valid PostScript.
Because Ghostscript must initialize the PostScript environment before executing the commands specified by this option it should be specified after other setup options. Specifically this option 'bind’s all operations and sets the systemdict to readonly.”
https://ghostscript.com/doc/current/Use.htm#Options

Thanks for sharing, we will look at this to see if we can improve the situation in PDFCreator (which is a lot more than just a wrapper around Ghostscript - see the source on GitHub :wink: )

Best regards,

Robin

Hi Robin,

It is clear that the driver works by first spooling a postscript file and finally converting this file to a PDF. This conversion to a PDF appears to be powered by Ghostscript. The “Additional Ghostscript parameters” textbox in PDFCreator is potentially useful as it allows the creation of a “-c” switch with arguments.

My difficulty is that it is very difficult to find examples of the “-c” switch in use, but I suspect my examples may have characters that need escaping. I am not sure in which environment Ghostscript is being called, so am not sure what to escape or how to escape it.

Can you advise further?

Many thanks

Hi Robin,

Thanks for indicating where the source code can be found. A look through the code identifies a potential problem. The file \PDFCreator-master\Source\Application\Conversion\Settings\Ghostscript.cs has the lines:

public void ReadValues(Data data, string path)
    		{
    			try { AdditionalGsParameters = Data.UnescapeString(data.GetValue(@"" + path + @"AdditionalGsParameters")); } catch { AdditionalGsParameters = "";}
    		}

This issue might be the UnescapeString() method. I guess this is pdfforge code as I cannot find any documentation.

Can you advise further?

Many thanks

Hi,

you are right, this is part of the DataStorage.dll and the source isn’t available on GitHub.
But it isn’t really secret sauce so I can post it here:
public static string UnescapeString(string s)
{
return System.Text.RegularExpressions.Regex.Unescape(s);
}
https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.unescape(v=vs.110).aspx

Best regards,

Robin

Hi Robin,

Finally, I have discovered a simple solution to this problem. Set the “Additional Ghostscript parameters” textbox in PDFCreator to:

-c|<</Orientation 3>>setpagedevice

The pipe character is all important.

Many thanks


I'm using V2.5.3. It keeps asking "No script file is specified". What should I do? BTW, I'm using a Japanese keyboard. Does that potentially cause any trouble?

Hi,

you don’t need to configure any script action for this, the place to set it is in the registry:
http://docs.pdfforge.org/pdfcreator/latest/en/pdfcreator/pdfcreator-settings/profile-settings/hidden-settings/
For portrait, I think it will need to -c|<</Orientation 0>>setpagedevice , the number sets the orientaion and 3 seems to set landscape according to the op.

Best regards,

Robin