6

我想裁剪一个PSPDF文件的主要区域以创建一个EPS没有空白的文件。ghostrciptps2pdf、的命令epstools可以从文档文件中裁剪出主图。

问题是它们只以原始形式裁剪,但我想用BoundingBox 0 0 x y;创建一个 EPS 文件。裁剪并移动到左下角。

当我们想要在 PS 文档中插入生成的 EPS 文件时的区别。当有 时BoundingBox x0 y0 x y,PS 文档在点 x0 y0 处插入 EPS 文件,而不是我们所在的位置。

例子:

考虑一个简单的PS文件

%!
/Times-Roman findfont 
11 scalefont setfont

72 700 moveto
(This is a test)show

如果EPS使用类似的命令将其转换为

ps2eps test.ps test.eps

它会产生

%!PS-Adobe-2.0 EPSF-2.0
%%BoundingBox: 72 700 127 708
%%HiResBoundingBox: 72.000000 700.000000 127.000000 707.500000
%%EndComments
% EPSF created by ps2eps 1.68
%%BeginProlog
save
countdictstack
mark
newpath
/showpage {} def
/setpagedevice {pop} def
%%EndProlog
%%Page 1 1
/Times-Roman findfont 
11 scalefont setfont
72 700 moveto
(This is a test)show
%%Trailer
cleartomark
countdictstack
exch sub { end } repeat
restore
%%EOF

它已在其原始坐标中进行裁剪,结果BoundingBox72 700 127 708. 现在,如果尝试EPS在文档中插入此文件PS,它会尝试在此坐标处嵌套。

如果EPS使用BoundingBox: 0 0 55 8. 当然,所有绘图坐标(此处为 moveto)都必须使用此新参考进行修改。

注意:如前所述,我修复 BoundingBox 参考点的目的是使其可在 PS 文档中导入。因此,这个问题的另一个答案是:如何在 PS 文档中插入 EPS 文件,而不管它的 BoundingBox。

例如,如何将此 EPS 文件插入到200 200 255 208PS 文档的位置。我尝试使用以下代码插入 EPS,但除非 BoundingBox 从以下位置启动,否则它将不起作用0 0

200 200 translate 
save 
/showpage {} bind def 
(test.eps)run 
restore
4

2 回答 2

3

简单地取消翻译怎么样?

-72 -700 translate

是在eps本身,还是在包含之前的准备部分?


尴尬的!

以下打字稿说明了一个 awk 脚本,该脚本在 DSC 注释的指导下对 eps 执行所需的修改(就像妈妈以前做的那样!)。

优点是:如果您可以保证输入 EPS 充分符合 DSC 以提供这些标记,那么这种方法将比通过ghostscript 传递文件快几个数量级。

简单性既是这个程序的优点也是局限性。它扫描 DSC 评论,从 BoundingBox 评论中提取值,抑制 HiResBoundingBox,并在 Page 评论之后添加 postscript 'translate' 和 'rectclip' commnds。只要 EPS 确实是真实的,这应该会产生正确的结果。但是另一个答案中的 ghostscript 方法会在输入文件上产生不太可靠的 DSC 一致性的结果(因为它不走捷径,它将 DSC 视为注释并完全忽略它们)。

严格来说,'rectclip' 不应该是必要的,但问题要求输出被“裁剪”。

592(1)11:27 AM:~ 0> cat epscrop.awk
/%%BoundingBox: ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*)/{x=$2;y=$3;w=$4-x;h=$5-y;print $1,0,0,w,h}
!/%%BoundingBox:/&&!/%%HiRes/{print}
/%%Page /{print -x,-y,"translate"; print 0,0,w,h,"rectclip"}


593(1)11:27 AM:~ 0> awk -f epscrop.awk etest.eps
%!PS-Adobe-2.0 EPSF-2.0
%%BoundingBox: 0 0 55 8
%%EndComments
% EPSF created by ps2eps 1.68
%%BeginProlog
save
countdictstack
mark
newpath
/showpage {} def
/setpagedevice {pop} def
%%EndProlog
%%Page 1 1
-72 -700 translate
0 0 55 8 rectclip
/Times-Roman findfont
11 scalefont setfont
72 700 moveto
(This is a test)show
%%Trailer
cleartomark
countdictstack
exch sub { end } repeat
restore
%%EOF
于 2012-10-02T04:34:33.450 回答
3

要将其转换为您想要的 BoundingBox 样式的 EPS,我会使用 Ghostscript 并让 EPS 进行往返:EPS => PDF => EPS。

诀窍是通过添加参数来确保 PDF 使用与 BoundingBox 宽度和高度相同的媒体大小-dEPSCrop

这两个命令创建您的“没有空格的 EPS”

第一步:将EPS转换为PDF:

gs                   \
  -o so#12682621.pdf \
  -sDEVICE=pdfwrite  \
  -dEPSCrop          \
   so#12682621.eps

第二步:将PDF转换回EPS:

gs                                \
  -o so#12682621.roundtripped.eps \
  -sDEVICE=epswrite               \
   so#12682621.pdf 

要测试生成的 EPS 的保真度,您可以使用 ImageMagickcompare将差异以红色像素形式显示为 PNG 文件:

 compare                      \
   -density 600               \
    12682621.roundtripped.eps \
    12682621.eps              \
   -compose src               \
    12682621.png

这导致:在此处输入图像描述

您会注意到存在一些像素差异。它们是由 707.500000 的值引起的%%HiResBoundingBox,这会导致稍后出现舍入错误(PNG 不能有“半像素”)。

于 2012-10-02T07:38:23.590 回答