【发布时间】:2019-02-24 09:50:24
【问题描述】:
我想(手动)在 postscript 文件中插入额外的 postscript 命令,该文件是通过 ghostscript 的 pdf2ps 从 PDF 文件转换而来的。出于测试目的,我使用pdflatex从以下文件创建了一个 PDF 文件:
\documentclass[a4paper]{article}
\begin{document}
Mostly empty.
\end{document}
在转换后的 postscript 文件中,我进行以下编辑:
...
%%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
postscipt/PDF 文件没有产生对角线,而是保持(看似)不变。但是,如果我将页面尺寸从 A4 更改为字母大小,则会显示该行:
%%Page: 1 1
%%PageBoundingBox: 0 0 612 792
%%BeginPageSetup
4 0 obj
<</Type/Page/MediaBox [0 0 612 792]
...
我显然在这里遗漏了一些东西(鉴于我对后记的基本知识,这并不奇怪)。我的问题是:如何在保持页面尺寸不变的情况下使线条出现?
P.S.:我偶然发现的一条评论提到 pdftops(来自 poppler-utils)在某种意义上优于 pdf2ps。实际上,在showpage 命令(使用pdf2ps 时根本不存在)之前将命令插入到转换后的postscript 文件中效果很好。所以我可能已经找到了解决我的问题的方法。但是,我想了解使用pdf2ps 时页面尺寸与它有什么关系。
解决方案
感谢KenS的建议并参考他对this question的回答,通过在postscript文件中添加一个EndPage过程,我能够达到预期的效果:
<<
/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。)
【问题讨论】:
标签: ghostscript postscript poppler