I'm trying to convert a plaintext document to PDF. The only method which has come anywhere close to actually working is installing "GhostScript" and then using the following PostScript script, dug up by the SE user @RedGrittyBrick (thanks), which takes a plaintext document (underneath the script) and produces a PDF from it.
It technically works, but visually messes up the top and left margins for each page in such a manner that the top margin becomes "way too much" and the left margin is "a bit too for in" (compared to the right margin). At least when viewed in SumatraPDF, which is the only PDF viewer I have.
The script states:
/topmargin 1 inch def
/leftmargin 1 inch def
However, it visually looks like the top margin is maybe 4 inches and not 1 inch as it says in the file. If I modify it to 0, the finished PDF visually appears to have 1 inch top margin. If I, on the other hand, modify the leftmargin to 0 inch, it goes all the way to the left border.
The way it visually looks right to me, with proper, even margins on top/right/bottom/left, is:
/topmargin 0 inch def
/leftmargin 0.8 inch def
But I can't just keep it like that as it will more than likely break on others' computers/PDF viewers. And even if it doesn't, I still really bugs me that I don't understand what is going on.
I have been told that the reason for this happening is that the PostScript does not specify a "page size". However, I have no idea how I would specify this into the document, nor how it can be possible that the author of the script never did this in the first place. It seems like such a basic, major mistake, yet the person who gave it to me claims to have used it for many years in many different environments successfully, so what does that mean? That SumatraPDF has very exotic default settings? That the person in question has very low standards? That I'm going insane? I really don't know what to make of this, or how to fix it.
I thought the whole point of PDF was to always create a 1:1 copy, with no ambiguity whatsoever in the dimensions and how things will be rendered... Apparently not. This is the script:
%!
%
% From: Jonathan Monsarrat (jgm@cs.brown.edu)
% 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
I then run:
ps2pdf in.ps out.pdf