Pdf 重影脚本旋转页面
我使用Ghostscript将PDF文档转换为PCL进行打印。最近,我有一个额外的要求,所有的页面必须旋转到肖像打印前。我已经找到了一种方法,可以使用Ghostscript和下面的命令和postscript函数来实现这一点Pdf 重影脚本旋转页面,pdf,ghostscript,postscript,printer-control-language,Pdf,Ghostscript,Postscript,Printer Control Language,我使用Ghostscript将PDF文档转换为PCL进行打印。最近,我有一个额外的要求,所有的页面必须旋转到肖像打印前。我已经找到了一种方法,可以使用Ghostscript和下面的命令和postscript函数来实现这一点 "C:\Program Files (x86)\gs\bin\gswin32c.exe" "-dNOPAUSE" "-dNOPROMPT" "-dBATCH" "-sDEVICE=pxl
"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"
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
我知道有一些非Ghostscript的方法可以旋转页面,但如果我能让它正常工作,它将很好地适应我的流程,并且不会降低性能
以下是我的一个pdf文件示例:
PostScript是一种编程语言,因此您可以用它做很多事情。这里需要做的是重新定义请求页面大小的操作。PostScript中的页面大小和内容是分开的,因此您需要做两件事: 1) 将媒体请求从横向更改为纵向 2) 旋转页面的内容 最简单的方法是重新定义“setpagedevice”操作符。下面是一个例子:
/oldsetpagedevice /setpagedevice load def %% copy original definition
/setpagedevice {
dup /PageSize known { %% Do we have a page size redefinition ?
dup /PageSize get %% get the array if so
aload pop %% get elements remove array copy
gt { %% is width > height ?
dup /PageSize get aload %% get size array, put content on stack
3 1 roll %% roll stack to put array at back
exch %% swap width and height
3 -1 roll %% bring array back to front of stack
astore %% put swapped elements into array
/PageSize exch %% put key on stack and swap with value
2 index %% copy the original dict
3 1 roll %% move dict to back of stack
put %% put new page size array in dict
90 rotate %% rotate content 90 degrees anti-clockwise
} if
} if
oldsetpagedevice %% call the original definition
} bind def
这将检查配置更改,以查看页面大小是否被更改,如果是,则获取新大小,并查看宽度>高度(一个简单的横向定义)。如果这是真的,那么它通过交换宽度和高度来改变请求,然后将页面内容旋转90度
您可以将上述内容放入一个文件(例如prolog.ps)中,然后在自己的作业之前运行该文件,从而将其用于Ghostscript:
gs。。。。。。prolog.ps job.ps
我尝试过这个,但没有使用横向文件,因为我手头没有横向文件。还请注意,可以构造一个PostScript程序来解决这个问题。我找到了一个可行的解决方案。它不像我希望的那样通用,但它满足了我的所有要求 以下附言将A4、信件和法律文件旋转成纵向。要使其执行其他页面大小,请调整最小和最大大小
%!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
%!附言
%序列设置为单个页面大小,自动适应所有页面。
%将A4字母和法定页面尺寸自动旋转至纵向
/InputAttributes currentpagedevice/InputAttributes获取%current dict
dup{pop 1 index exch undef}forall%删除所有页面大小
dup 0>put%[min-w min-h max-w max-h]
>>设置页面设备
这篇后记将把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
%!附言
%序列设置为单个页面大小,自动适应所有页面。
%将A4字母和法定页面大小自动旋转到横向
/InputAttributes currentpagedevice/InputAttributes获取%current dict
dup{pop 1 index exch undef}forall%删除所有页面大小
dup 0>put%[min-w min-h max-w max-h]
>>设置页面设备
此解决方案基于我在项目源代码中找到的auto-rotate.ps文件。该项目似乎是根据BSD获得许可的。尽管答案运行良好,但从那时起,出现了一个新的选项
-dFIXEDMEDIA
witch适用于任何纸张尺寸,而不仅仅适用于a4
有关其他详细信息,请参阅。我尝试了此脚本,但没有产生错误,但也没有旋转页面。下面是一个输入pdf文件的示例。
%!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