手动编辑(每页)后记文件 [英] Edit (every page of a) Postscript file manually

查看:67
本文介绍了手动编辑(每页)后记文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想(手动)在通过ghostscript的 pdf2ps 从PDF文件转换的Postscript文件中插入其他Postscript命令.为了进行测试,我使用 pdflatex 从以下文件创建了PDF文件:

I want to (manually) insert additional postscript commands in a postscript file that was converted from a PDF file via ghostscript’s pdf2ps. For the purpose of testing I created a PDF file from the following file using pdflatex:

\documentclass[a4paper]{article}
\begin{document}
Mostly empty.
\end{document}

在转换后的脚本文件中,进行以下

In the converted postscript file I make the following edit:

...
%%Page: 1 1
%%PageBoundingBox: 0 0 595 841
%%BeginPageSetup
4 0 obj
<</Type/Page/MediaBox [0 0 595.28 841.89]
/Parent 3 0 R
/Resources<</ProcSet[/PDF]
/Font 8 0 R
>>
/Contents 5 0 R
>>
endobj
%%EndPageSetup
% BEGIN MANUAL EDIT
0 setgray 0 0 moveto 595 841 lineto stroke
% END MANUAL EDIT
5 0 obj
<</Length 257>>stream
q 0.1 0 0 0.1 0 0 cm
0 G
0 g
q
10 0 0 10 0 0 cm BT
/R6 9.9626 Tf
1 0 0 1 139.746 706.129 Tm
[(M)-0.699638(os)-0.399443(t)-0.900585(l)-0.798886(y)-333.819(e)-0.400668(m)-0.300195(p)-0.599165(t)26.0974(y)83.192(.)-0.800112]TJ
154.421 -615.691 Td
(1)Tj
ET
Q
Q

endstream
endobj
pagesave restore
%%PageTrailer
%%Trailer
end
%%EOF

postcipt/PDF文件没有产生对角线,而是(似乎)保持不变.但是,如果我将页面尺寸从A4更改为letter大小,则会显示以下行:

Instead of producing a diagonal line the postscipt/PDF file remains (seemingly) unchanged. However, if I alter the page dimensions from A4 to letter size the line is shown:

%%Page: 1 1
%%PageBoundingBox: 0 0 612 792
%%BeginPageSetup
4 0 obj
<</Type/Page/MediaBox [0 0 612 792]
...

我显然在这里缺少某些东西(考虑到我对后记的基本了解,这不足为奇).我的问题是:如何在保持页面尺寸不变的同时使线条出现?

I am obviously missing something here (which is not surprising given my rudimentary knowledge of postscript). My question is: How can I make the line appear while keeping the page dimensions unchanged?

P.S .:我偶然发现的一条评论提到, pdftops (来自poppler-utils)在某种意义上要优于 pdf2ps .确实,在 showpage 命令之前(在使用 pdf2ps 时根本不存在)之前将命令插入转换后的脚本文件中,效果很好.因此,我可能已经找到解决问题的方法.但是,我想了解使用 pdf2ps 时页面尺寸与它有什么关系.

P.S.: A comment I stumbled across mentioned that pdftops (from poppler-utils) is in some sense superior to pdf2ps. Indeed, inserting commands into the converted postscript file immediately before the showpage command (which is not there at all when using pdf2ps) worked fine. So I have probably already found a solution to my problem. However, I would like to learn what the page dimensions have to do with it when using pdf2ps.

感谢KenS的建议,并参考他对

Thanks to KenS’s advice and referring to his answer to this question I was able to achieve the desired effect by adding an EndPage procedure to the postscript file:

<<
/EndPage
{
  exch pop 2 lt
  {
    gsave
    0 0 translate
    0 setgray 0 0 moveto 596 842 lineto stroke
    grestore
    true
  }{false} ifelse
} bind
>> setpagedevice

(假设页面大小为a4.)

(This assumes the page size is a4.)

推荐答案

PostScript是一种只写语言:-)

PostScript is a write-only language :-)

严重的是,它是一种编程语言.为了了解发生了什么,您需要了解该程序,对于从Ghostscript的ps2write设备输出的程序来说,它显然是不平凡的.

Seriously, its a programming language. In order to understand what's going on, you need to understand the program, which in the case of the output from Ghostscript's ps2write device, is distinctly non-trivial.

语法基本上是PDF,带有一个Prolog程序,可以用PostScript术语对其进行解释.

The syntax is basically PDF, with a prolog program which interprets it in PostScript terms.

程序使用showpage,该程序在执行EndStream过程时执行(基本上是在页面流中包含endobj关键字时).您会看到它看起来像:

The program will use showpage, it does it when the procedure EndStream is executed, which is (basically) when the endobj keyword is encoutnered in a page stream. You'll see that it looks like:

ET
Q
Q
Q

endstream
endobj
%%Page: 2 2

您可以在端点和endobj之间放置任何您喜欢的东西,但是您需要知道,此时的图形状态取决于已经执行的任何操作.这可能包括缩放,排列,倾斜,翻转垂直轴等.因此,仅在其中插入一些PostScript不太可能起作用.您可以进行初始化,至少可以将图形状态重置为已知设置.

You could place anything you like between the endstream and the endobj, but you need to be aware that the graphics state at that point is determined by whatever operations have already taken place. This can include scaling, oration, skeing, flipping the vertical axis, etc. So simply inserting some PostScript into there is unlikely to work. You could do an initgraphics which would at least reset the graphics state to a known setup.

作为测试,我运行了Ghostscript的ds ps2write设备,如下所示:

As a test I ran Ghostscript'sd ps2write device like this:

gs -sDEVICE = pdfwrite -o out.ps -c显示页面" -f

gs -sDEVICE=pdfwrite -o out.ps -c "showpage" -f

生成PostScript程序,其中(有效)内容为:

which produces a PostScript program where the (effective) content is:

%%EndResource
%%EndProlog
%%Page: 1 1
%%PageBoundingBox: 0 0 595 842
%%BeginPageSetup
4 0 obj
<</Type/Page/MediaBox [0 0 595 842]
/Parent 3 0 R
/Resources<</ProcSet[/PDF]
>>
/Contents 5 0 R
>>
endobj
%%EndPageSetup
5 0 obj
<</Length 23>>stream
q 0.1 0 0 0.1 0 0 cm
Q

endstream
endobj
%%Trailer
end
%%EOF

然后按照您的建议或多或少地对此进行了修改:

I then modified this more or less as you suggested:

%%EndPageSetup
0 setgray 0 0 moveto 595 842 lineto stroke
5 0 obj
<</Length 23>>stream
q 0.1 0 0 0.1 0 0 cm
Q

endstream
endobj
%%Trailer

对我来说,这产生了从左下到右上的预期笔画.显然,如果没有您最初生成的PostScript文件,就无法告诉您您的体验为何不同.(不,我无法运行乳胶来生产这种东西,即使我这样做,我也无法知道您使用的是哪个版本的Ghostscript和其他工具).

For me this produced the expected stroke from bottom left to top right. Obviously without the PostScript file you originally produced I can't tell you why your experience is different. (no I'm not in a position to run latex to produce such a thing, and even if I did I have no way to know which version of Ghostscript and the other tools you used).

我的猜测是您的PDF文件中的内容"覆盖了整个页面,但这并非完全不常见.

My guess would be that 'something' in your PDF file overwrote the entire page, its not entirely uncommon.

这篇关于手动编辑(每页)后记文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆