是否可以在 EndPage 程序中使用 EPS 文件(使用 eps2write 创建)?

Is it possible to use EPS file (created with eps2write) in EndPage procedure?

出于测试目的,让我们绘制一些无意义的矩形:

gswin32c -q -o f.pdf -sDEVICE=pdfwrite -c "<</PageSize[595 842]>>setpagedevice 0 0 595 842 rectfill showpage"

+

gswin32c -q -o f.eps -sDEVICE=eps2write -f f.pdf

和ps.ps文件:

<<
    /EndPage {
        exch pop 
        2 ne dup {
            1 dict begin
            /showpage {} def
            (f.eps) run
            end
        } if
    }
>> setpagedevice

然后

gswin32c -q -o out.pdf -sDEVICE=pdfwrite -f ps.ps -f f.pdf

产生错误:

%%[ Error handled by opdfread.ps : GPL Ghostscript 9.15: Unrecoverable error, exit code 1 Unrecoverable error: typecheck in if Operand stack: typecheck ebuf false false --nostringval--

另一方面,如果我使用其他工具创建 EPS,例如xpdfpdftops:

pdftops -eps f.pdf f.eps

...然后可以将 EPS 放置为例如带有上述命令的水印或徽标:

gswin32c -q -o out.pdf -sDEVICE=pdfwrite -f ps.ps -f f.pdf

所以问题是,是否可以使用 Ghostscript 的 eps2write 来达到目的,也许我遗漏了什么。

我试图将 (f.eps) run 与对 BeginEPSFEndEPSF 的调用括起来,如 Adob​​e 的 EPSF 格式规范 中所定义,但它没有帮不上忙在解码 eps2write 创建的序言之后(如果 EndPage 中的 运行 本身会给出相同的错误),在我看来它违反了 Illegal and Restricted 部分上述规范的运算符

编辑: 如果代码是 EndPage 中的 运行,我认为 立即评估的名称 存在问题。在 eps2write 创建的序言中,有一段距离开头不远的片段:

//SetPageSize{
//RotatePages//FitPages or//CenterPages or{
mark(/RotatePages, /FitPages and CenterPages are not allowed with /SetPageSize)//error exec
}if
}
{
//FitPages//CenterPages and{
mark(CenterPages is not allowed with /FitPages)//error exec
}if
}
ifelse

如果我这样构图:

SetPageSize ==
//SetPageSize ==
{

//SetPageSize{
//RotatePages//FitPages or//CenterPages or{
mark(/RotatePages, /FitPages and CenterPages are not allowed with /SetPageSize)//error exec
}if
}
{
//FitPages//CenterPages and{
mark(CenterPages is not allowed with /FitPages)//error exec
}if
}
ifelse

} stopped { (***\n) print } if

并稍微修改ps.ps

<<
    /EndPage {
        exch pop 
        2 ne dup {
            1 dict begin
            /showpage {} def
            (prologue.ps) run
            end
        } if
    }
>> setpagedevice

然后这个命令:

gswin32c -q -o out.pdf -sDEVICE=pdfwrite -f ps.ps -f f.pdf

...给出此输出:

false 
/SetPageSize
*** 
%%[ Error handled by opdfread.ps : GPL Ghostscript 9.14: Unrecoverable error, exit code 1

即它在上面的片段中失败了(我认为出于明显的原因)然后在 prologue.ps 内的其他地方失败了。

好的,所以我做了一些与您的经历类似的事情。我从一个简单的 PostScript 文件开始 (testeps.ps):

%!
0 1 0 setrgbcolor
0 0 100 100 rectfill
showpage

然后我 运行 通过 Ghostscript 使用 eps2write 设备:

./gs -sDEVICE=eps2write -sOutputFile=out.eps -dCompressPages=false testeps.ps

然后我构建了另一个测试文件(test.ps):

%!

<<
    /EndPage {
        exch pop 
        2 ne dup {
            1 dict begin
            /showpage {} def
            (/temp/out.eps) run
            end
        } if
    }
>> setpagedevice

1 0 0 setrgbcolor
0 100 100 100 rectfill

showpage

和运行 通过 GS:

./gs test.ps

文件 运行 完成,并在页面的正确位置包含适当颜色的矩形。

这可能是已修复的问题(您没有说明您使用的是哪个版本的 Ghostscript)。下一个版本 (9.16) 很快就会发布,或者您可以自己从源代码构建 iot,我建议您在可用时尝试一下。