Сценарий PS берет текстовый документ и создает из него PDF-файл. Большое спасибо @RedGrittyBrick за то, что выкопали этот фрагмент:
%!
%
% From: Jonathan Monsarrat ([email protected])
% Subject: PostScript -> ASCII *and* ASCII -> PostScript programs
% Newsgroups: comp.lang.postscript
% Date: 1992-10-01 04:45:38 PST
%
% "If anyone is interested, here is an interesting program written by
% Professor John Hughes here at Brown University that formats ASCII
% in PostScript without a machine generator of any kind."
%
%%%
%%% Plan:
%%% Start with an empty string.
%%% For each character in the input stream,
%%% check to see if it's a carriage return.
%%% if so, show the current string and reset it to empty
%%% if not, add it to the current string.
/Courier findfont 10 scalefont setfont %% Choose a fixed width font
/lineheight
currentfont /FontBBox get dup %% bbox bbox
0 2 getinterval %% bbox {xm ym}
exch %% {xm ym} bbox
2 2 getinterval %% {xm ym} {xM yM}
aload pop %% {xm ym} xM yM
3 2 roll %% xM yM {xm ym}
aload pop
currentfont /FontMatrix get %% xM yM xm ym MAT
transform %% xM yM xm' ym'
4 2 roll
currentfont /FontMatrix get %% xm' ym' xM yM MAT
transform %% xm' ym' xM' yM'
exch pop %% xm' ym' yM'
sub %% xm' ym'-yM'
exch pop %% dy
neg def
lineheight pstack pop
/str 500 string def %% Room to store a long string...
/empty 500 string def %% An empty string to work with
/stringindex 0 def %% How far we've filled the string
/inch {72 mul } def %% A useful tool...
/pageheight 11 inch def
/topmargin 1 inch def
/botmargin 1 inch def
/leftmargin 1 inch def
/linesperpage pageheight topmargin sub botmargin sub lineheight div cvi def
/linenumber 1 def %% the line we're about to write on
/newline { %% move to a new line; flush page if necessary
linenumber linesperpage gt {/linenumber 1 def showpage } if
leftmargin pageheight topmargin sub linenumber lineheight mul sub moveto
/linenumber linenumber 1 add def
} def
/cleanup { %% print out the last bit of whatever you had there...
str show showpage
} def
/startstring { %% empty the string and reset its counter.
str 0 empty putinterval
/stringindex 0 def
} def
/showstring { %% print the string on a new line and flush it
newline
str show
startstring
} def
pstack
/addtostring { %% put another character in the string, if there's room
dup 500 gt {pop}{str exch stringindex exch put
/stringindex stringindex 1 add def} ifelse
} def
%
% Main program: get characters and deal with them
%
{
currentfile read {}{cleanup exit} ifelse
dup 10 eq %% if it's a carriage return...
{pop showstring} %% write out this line of text and start over
{dup 0 eq %% if it's an end-of-file mark...
{exit} %% stop!
{addtostring} %% otherwise, add the character to current string
ifelse}
ifelse %% Sample data follows.
} loop
В нем есть:
/topmargin 1 inch def
/leftmargin 1 inch def
Но визуально выглядит так, будто верхнее поле составляет 4 дюйма, а не 1 дюйм, как указано в файле. Если я изменю его на 0, готовый PDF-файл визуально будет иметь верхнее поле шириной 1 дюйм. Если я, с другой стороны, изменю левое поле на 0 дюймов, оно дойдет до левой границы. Это не имеет смысла для меня.
Я использую SamutraPDF для открытия файлов PDF.
То, как это визуально выглядит правильно для меня, с правильными, ровными полями сверху/справа/снизу/слева, таково:
/topmargin 0 inch def
/leftmargin 0.8 inch def
Это, согласно коду, должно выглядеть неправильно, но вместо этого выглядит правильно.
Это меня очень беспокоит. Будут ли все остальные видеть мои документы с испорченными полями? Это как-то SumatraPDF делает что-то нестандартное? У него есть ошибка? Что происходит? Добавляет ли PDF невидимое верхнее поле для всех документов по умолчанию?
Должен признаться, что я ничего не понимаю в языке этого файла PostScript. В какой-то момент он упоминает «500», что кажется странно конкретным. Но мой вопрос действительно о «невидимом верхнем поле». Почему это происходит? Что я делаю не так? Почему сценарий, который, по словам парня, который мне его дал, не дает идеальной маржи? Он утверждает, что использовал его в течение очень долгого времени в самых разных средах, поэтому я не знаю, что с этим делать.