Ghostscript旋转页面

Zig*_*158 6 pdf postscript printer-control-language ghostscript

我使用Ghostscript将PDF文档转换为PCL进行打印.最近我还要求在打印前将所有页面旋转到Portrait.我已经找到了一种使用Ghostscript和以下命令和postscript函数的方法.

"C:\Program Files (x86)\gs\bin\gswin32c.exe" "-dNOPAUSE" "-dNOPROMPT" "-dBATCH" "-sDEVICE=pxlmono" "-Ic:\Program Files (x86)\gs\fonts\;c:\Program Files (x86)\gs\lib\;c:\Program Files (x86)\gs\lib\;" "-r300" "-sOutputFile=C:\EXPORTFILE_e542e04f-5e84-4c8e-9b41-55480cd5ec52.cache" "rotate612x792.ps" "C:\EXPORTFILE_3a5de9da-d9ca-4562-8cb6-10fb8715385a.cache"
Run Code Online (Sandbox Code Playgroud)

rotate612x792.ps的内容

%! Rotate Pages
<< /Policies << /PageSize 5 >> 
   /PageSize [612 792] 
   /InputAttributes currentpagedevice 
   /InputAttributes get mark exch {1 index /Priority eq not {pop << /PageSize [612 792] >>} if }  forall >>
   >> setpagedevice
Run Code Online (Sandbox Code Playgroud)

问题是此函数用字母大小替换所有页面大小.我的文件有时是合法的或A4.我试图修改此功能,以使用肖像对应物替换横向大小,但无法生成功能性的postscript.我需要指向正确的方向来生成以下伪代码的postscript等价物.

for(each page)
{
   if(PageSize == [792 612])
       PageSize = [612 792];
}
Run Code Online (Sandbox Code Playgroud)

我知道有非Ghostscript旋转页面的方法,但如果我能让它工作,它将很好地适应我的过程,不会降低性能.

以下是我的一个pdf文件的示例: Sample1.pdf

Zig*_*158 3

我找到了一个可行的解决方案。它并不像我希望的那么通用,但它满足了我的所有要求。

以下 postscript 脚本将 A4、Letter 和 Legal 文档旋转为纵向。要使其适应其他页面尺寸,请调整最小和最大尺寸。

%!PS
  %   Sequence to set up for a single page size, auto fit all pages.
  %   Autorotate A4 Letter and Legal page sizes to Portrait
  << /Policies << /PageSize 3 >>
     /InputAttributes currentpagedevice /InputAttributes get    %current dict
     dup { pop 1 index exch undef } forall    % remove all page sizes
     dup 0 << /PageSize [ 595 0 612 99999 ] >> put    % [ min-w min-h max-w max-h ]
  >> setpagedevice
Run Code Online (Sandbox Code Playgroud)

此 postscript 脚本将 A4、信函和法律文档旋转为横向。唯一的区别是最小/最大页面大小值。

%!PS
  %   Sequence to set up for a single page size, auto fit all pages.
  %   Autorotate A4 Letter and Legal page sizes to Landscape
  << /Policies << /PageSize 3 >>
     /InputAttributes currentpagedevice /InputAttributes get    %current dict
     dup { pop 1 index exch undef } forall    % remove all page sizes
     dup 0 << /PageSize [ 0 595 99999 612 ] >> put    % [ min-w min-h max-w max-h ]
  >> setpagedevice
Run Code Online (Sandbox Code Playgroud)

该解决方案基于我在hylafax项目源代码中找到的 auto-rotate.ps 文件。该项目似乎是在 BSD 下获得许可的。