Re: Printing to PDF via GUI scripting
Re: Printing to PDF via GUI scripting
- Subject: Re: Printing to PDF via GUI scripting
- From: Philip Aker <email@hidden>
- Date: Fri, 07 Feb 2003 12:41:52 -0800
On Thursday, February 6, 2003, at 06:31 AM, nino wrote:
Can you please share a bit more of your achievements? Are you
suggesting to print using the "lp" unix command? if so, how would you
print, for example, a selected subset of a database records with a
given format?
Greetings Nino,
I installed the ESP version of Ghostscript that is available through
Apple's download site. I believe it is the recommended GhostScript
installation for Jaguar because the company is contracted by Apple to
implement CUPS.
To print just about any file to my printer, I use 'lp'. This includes
.ps, .pdf., .rtf, .html, plain text files and graphic formats (.jpeg
e.g.). With this method, I currently don't know how to set the printing
options like font, font size, etc. for plain text files. I believe it's
possible however by setting some options to the filter which is invoked
by lp or one of the options for the CUPS environment but don't know
where this is documented yet.
*
To format arbitrary text data for printing to a printer or for printing
to PDF, there are many choices. It all depends on what suits the
situation or what one feels comfortable with.
1.
Firstly there would be the traditional unix markup associated with
'nroff', 'troff', 'groff', and other related calls. This way is almost
totally alien to me except in the case where I don't have to create the
markup like in man files. For instance to print a man page directly to
a printer simply call:
man -t atprint | lp
You may like this method if the database records are relatively simple.
2.
Secondly (and this is what I'm currently using for PDFs) there is the
'enscript' command. If you examine the man page for 'atprint' you'll
see that it is the method recommended for printing with AppleTalk
connected printers. It works with 'lp' just as easily. enscript has
many options including the ability to set the font size, scaling, print
headers and footers, multiple columns, watermarks, etc., etc. It has
many command line options but it seems to me the easiest use is to set
it up properly with a personal configuration file and a personal
resource directory.
The configuration file must be invisible, named ".enscriptrc", and
located in your home folder. Create it like this:
cp /usr/share/enscript/enscript.cfg ~/.enscriptrc
The configuration directory must be invisible, named ".enscript", and
located in your home folder (to start with but you can change the path
later on). Copy the files with the .hdr extension from the
/usr/share/enscript/ folder into the invisible .enscript folder.
To customize the enscript environment, you'll have to read the enscript
man page. Right now, we'll just use some command line options so that
the output can be redirected to a PostScript file on disk. Once there
is a PostScript file, a PDF is easily created with the ps2pdf tool
included with ESP GhostScript. Without any enscript customization,
here's an example of a command line call which outputs to a file on
disk with the font set to Times 9:
enscript --font="Times-Roman9" -p- SomeFile.txt > SomeFile.ps
The "-p-" option tells enscript to redirect the output from a printer
to the stdout file (the Terminal window), and then we redirect stdout
to a file on disk (SomeFile.ps in this case).
Assuming you have your path configured so that the GhostScript tools
are available, you can then convert the .ps file to a PDF like so:
ps2pdf13 SomeFile.ps SomeFile.pdf
Now check it with:
open SomeFile.pdf
3.
Thirdly, there's the option to format arbitrary text to HTML, and then
print that. I think there is an example AppleScript at Apple's site, so
I won't go into that right now. However, I will be investigating that
route in the future because it's easier to have formatting options for
tables, lists. etc., in HTML.
4. Probably the most flexible and powerful method to format arbitrary
text data into a PostScript or PDF file is to use the TeX typesetting
system. On OS 9, the best way to to that is with the Alpha application.
Alpha for OS X won't be available for another few weeks (it's in late
beta right now) but there is a spinoff of it written in Tcl/Tk called
AlphaTk which is available now. I never had the need for TeX on OS 9,
but used have Alpha for my text editor for many years and will probably
investigate TeX when Alpha X is released. Alpha is completely
scriptable with Tcl and can receive such commands from AppleScript's.
HTH,
Philip Aker
http://www.aker.ca
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.