PostScript Template Language

From $1

Table of contents
  1. 1. Testing the Examples
  2. 2. Co-ordinate System
  3. 3. Operators
    1. 3.1. at
    2. 3.2. Showpage
    3. 3.3. Text
    4. 3.4. Keywords
    5. 3.5. Font
    6. 3.6. Standard PostScript Fonts
    7. 3.7. Color
    8. 3.8. linewidth
    9. 3.9. newpath
    10. 3.10. line
    11. 3.11. box
    12. 3.12. Fill
    13. 3.13. Circle
    14. 3.14. setgray
    15. 3.15. Gsave
    16. 3.16. Grestore
    17. 3.17. reset-matrix
    18. 3.18. rotate
    19. 3.19. scale
    20. 3.20. translate
    21. 3.21. textbox
    22. 3.22. flowbox
    23. 3.23. EPS
    24. 3.24. Barcodes
  4. 4. Other Resources

Synapse uses a template language to describe the page layout in letters, prescriptions, and various request forms.  The language is designed to be similar to postscript, but does not allow full postscript functionality.  You can draw simple shapes, lines and place text on the page in different fonts and colors.  You can also include external images, but they do have to be in EPS, or encapsulated postscript format.

The main requirement for documents is to be able to place text at certain positions on the first page, and then have longer text spill over to subsequent pages without the need to place text at specific locations - apart from footers, and page numbers.  So, Synapse allows just this, and uses the gonzo.ps text formatter to provider footers, and micro-justification.

There are a few important things to remember when writing templates

  1. Fonts remain in place until changed to another
  2. There is no concept of current location so each element has to placed there
  3. Colors remain in place until changed to another
  4. Special words are used to access patient data and the physician's details

Testing the Examples

Synapse has a preview system that allows you to test your template code, and therefore the examples that follow.  Simply navigate to Settings/PostScript, and in the blank text box on the right, enter

at 300x450 "Hello World!"
showpage

and then click on the "Test" button.  A display comes up with the print preview of a page with "Hello World" near the center of the page.

Co-ordinate System

As in PostScript, the bottom left hand corner of the page is 0,0 or 0x0 in our template language, and the top right of the page is 595x842 for A4 paper, and 612x792 for American Letter paper.  Each of these divisions is called a point, and there are 72 points per inch.  So, at 72x72 we are one inch from the bottom and left edges.  These are the same points as used to describe the size of fonts eg. 10 point font size.

Operators

The postscript template language ( or PTL for short ) has a number of operators that direct the placement of text, and the drawing of graphical elements.  We shall cover these one by one.

 

 

 

The pagesize operator should be the first command on each template.  It defines the size of the page.  It is then followed by the actual page size.  You can use A4, letter, A5 or specify the actual size in points.  Eg:

pagesize letter

pagesize 400x500 

All the default templates use A4 as they were developed outside the USA.  You should modify them to use letter if you use American letter paper. 

at

The at operator is followed by a pair of x-y coordinates.  These tell the PTL where the next object is going to be placed on the page. The x-y coordinates should be within the visible page boundaries otherwise they will not be printed, or visible in the preview screen.  The x-y position is kept until the very next drawing operation, and is then generally discarded.

Now if we wish to place some text on the page, we can just write "Some text" like this

at 72x500 "Some text"
showpage

but if we now wish to place some text directly after this, we can't do this

at 72x500 "Some text" "This won't work"
showpage

as you will see the "This won't work" text appear above the "Some text" instead of at the end as you might expect.  So, instead you need to do:

at 72x500 "Some text"
at 120x500 "And this works"
showpage

Showpage

The showpage operator is not needed in these examples to view the preview screen, but is necessary if you want the page to print properly.  It tells the postscript printer or interpreter to put all the preceding on the current print page and move on to the next page.

Text

As you will have seen from the above, literal text strings are placed on the page simply by enclosing them in double quotes.  If you want to place text that is derived from the patient's demographics, or your details, you will use keywords that do not use double quotes, eg.

at 120x500 my-name

which places at 120x500 the text that is stored in Settings/User/Full name field.  So, double quotes are used for literal text.

Keywords

 line1  Settings/User/Line1
 line2  Settings/User/Line2
 line3  Settings/User/Line3
 ph  Settings/User/ph
 fx  Settings/User/fx
 my-name  Settings/User/Full name
 medical-registration  Settings/User/Registration No
 today  today's date
 time  time the consult started
 consult-date  the date of the consult, or today depending on settings at print time
 consult-date-usa  the same as above but using different date format
 provider  the name used for the addressee in the print dialog
 provider-template  Settings/User/Letters/To Provider template
 patient-template  Settings/User/Letters/Patient Details template
 patient-table  Settings/User/Letters/To Patient template
 diagnoses-table  A column of diagnoses with codes
 meds-table  A column of medications
 consult  The text from the current consult
 prescription  The current prescription
 superbill  The contents of services provided today
 followup
 The followup period as specified in the superbill
 totalcharge  The totalcharge field from the superbill
 request  The contents of any requests ( labs, radiology etc )

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Font

The font command allows you to change the font used for the page.  That font then remains active until changed again. Normally you would want to set the font right after the pagesize command.  Since it is not actually doing any printing, it does not need to be preceded by an at operator.

font Times-Roman 12

Note that the operator font is followed by the name of the font family, and then the font size.

If you are using ghostscript, you are limited to the fonts included in the distribution.  If you are using a postscript printer, you are limited to those fonts included with the printer, or those you can download to the printer.

Standard PostScript Fonts

  • Bookman-Demi
  • Bookman-DemiItalic
  • Bookman-Light
  • Bookman-LightItalic
  • Courier
  • Courier-Oblique
  • Courier-Bold
  • Courier-BoldOblique
  • AvantGarde-Book
  • AvantGarde-BookOblique
  • AvantGarde-Demi
  • AvantGarde-DemiOblique
  • Helvetica
  • Helvetica-Oblique
  • Helvetica-Bold
  • Helvetica-BoldOblique
  • Helvetica-Narrow
  • Helvetica-Narrow-Oblique
  • Helvetica-Narrow-Bold
  • Helvetica-Narrow-BoldOblique
  • Palatino-Roman
  • Palatino-Italic
  • Palatino-Bold
  • Palatino-BoldItalic
  • NewCenturySchlbk-Roman
  • NewCenturySchlbk-Italic
  • NewCenturySchlbk-Bold
  • NewCenturySchlbk-BoldItalic
  • Times-Roman
  • Times-Italic
  • Times-Bold
  • Times-BoldItalic
  • Times-BoldOblique
  • Symbol
  • ZapfChancery-MediumItalic
  • ZapfDingbats

Color

The color operator changes the current pen color.  It defaults to black.  It can then be followed by an rgb tuple ( red green blue ) such as

color 255.0.0 which is red
color 0.255.0
which is green
color 0.0.255
which is blue
color 128.128.128
which is gray

or, it can use the named Rebol colors but these must be enclosed by parentheses

color (red)

The named colors are:

black  blue    navy   orange gold    tan
    coal   green   leaf   forest brown   coffee
    gray   cyan    teal   aqua   water   sky
    pewter red     maroon brick  crimson pink
    silver magenta purple violet papaya  rebolor
    snow   yellow  olive  oldrab khaki   mint
    white  ivory   linen  beige

 

linewidth

The linewidth operator specifies the width of a line drawn including those in lines, boxes, circles etc.  It takes an integer.  So, a thin line would be

linewidth 1

and a thick line

linewidth 5

The linewidth remains operative until changed by another command.

newpath

The newpath operator tells the postscript printer to start a new drawing command.  Otherwise it might continue drawing from the previous position.  This is one instance in which it can remember where it was before.  So, you should use the newpath operator before each new line or other graphic object. 

line

The line operator draws a line in the current color, and linewidth from one position to another.  

newpath
at 75x740 line 530x740
showpage

says we are going to draw a new straight line from the point 75x740 to 530x740, ie. a horizontal line.

box

The box operator draws a closed rectangle using the current linewidth.  If followed by the operator fill, it then fills in the box with the current color.

pagesize A4
newpath

at 300x300 box 10x20

color (green)

fill

showpage

So, you can use this to setup check boxes on the page.

Fill

The fill operator as shown above will fill in any closed path drawing eg. box, circle with the current color.

Circle

The circle operator ( available in R211B25 and higher ) take a location and a radius.  It can also be filled in.

 

pagesize A4
color (red)
newpath
circle 72x72 15
fill
newpath
color (green)
circle 540x650 20
fill
showpage

 

In this example a couple of circles of differing fill colors and radii are drawn to the screen.

setgray

The setgray operator sets the grayscale level of any black lines drawn.  By default, setgray is 0, so that any lines drawn will be black.  If you use a value of 1, then lines will drawn in white.

pagesize A4
linewidth 4
setgray 0
at 72x72 line 300x300
newpath
setgray 1
at 76x72 line 304x300
newpath
setgray .5
at 80x72 line 308x300
showpage

In the example above, an oblique black line is drawn, then a white line parallel to it, and then a gray line parallel to the white line.  The lines slightly overlap each other.

Gsave

This allows the postscript printer to save the current working state.  You can then change various parameters, colors, etc, and return to that state by using a grestore. 

Grestore

Grestore restores the postscript interpreter to a previously saved state 

reset-matrix

rotate

Don't use 

scale

Don't use 

translate

Don't use 

textbox

In the text examples we looked at before, we usually placed a literal text string on the page, at a spot we determined using the at operator.  However, we also want to be able to place columns of text such as lists of diagnoses, and medications where the length of that column remains undetermined until print time.  We therefore have created a textbox which is a region on the page into which you can pour text.  The text will fill as much of the textbox as it can, and if there is more text than space, the extra text will be lost.  So, textboxes need to be created to be able to hold as much text as reasonably one expect there to be.

The textbox takes two sets of coordinates, the bottom left and the top right of the box - which acts as an invisible restraint on any text poured into it.

textbox 100x0 280x530

In the templates as distributed appears the above.  This textbox is used to hold the diagnoses and starts at the bottom of the page 100 points  from the left edge, and  ends  its top right corner at 280x530.

Once a textbox has been defined, it must be filled immediately with text.

textbox 100x0 280x530
flow diagnoses-table only

 

Here the flow operator is fed two parameters - the first returns all the diagnoses for the current patient, and the only modifier tells the flow operator to ignore any text that does not fit the textbox.  Flow takes the diagnoses column of data and puts it into the textbox.  It also internally records the bottom line where it stops putting text.  The other modifiers are left and gonzo.  The left modifier leaves text unjusified.

flowbox

A flowbox is a textbox which can have its contents modified in several ways.  Any text put into a flowbox can be justified, paginated, and can spill into another flowbox on the following page. Unlike textboxes, flowboxes must be defined as a group before text can be flowed into them.

flow-translate 0x0
flowbox 75x150 540x700 float 20
flow-translate 0x0
flowbox 75x150 540x720
gonzo
flow consult gonzo

This group of commands first off tells the postscript to reset any translations in operation.  A translation is where one point is moved to another arithmetically.

It then defines the flowbox as being something which largely covers the whole page at 75x150 540x700.  But it then follows this with the float modifier.  This basically says that if any text is poured into this flowbox, it must start 20 points below the lowest y value of any text in any textboxes.  In this way we can get the consult text to start below the diagnoses and medications.

The operator gonzo tells Synapse to include the gonzo text formatter utility written by PostScript guru Don Lancaster. 

Finally the flow operator is told to take the consult text, flow it into all the available flowboxes, and apply the gonzo text formatter to the contents so that they are fully justified, and paginated. 

Synapse will place each flowbox on separate pages.   This is why the second flowbox in the above example lacks the float modifier because it will be printing onto a blank page, and therefore does not need to drop below any other text.

EPS

The eps operator allows you to specify an image in EPS format which is to be placed upon the page. This might be letterhead, or a signature for a prescription or request.  In all of these cases, the image will appear at the same place, so it does not work if you wish to have your signature at the end of the consult as that location remains unknown until print time.

The eps operator takes a REBOL path to an eps image like this:

at 210x-450 eps %/c/texmf/demofig.eps

A yellow square will appear on the preview screen to show that there is an eps image there, but at this time it is not possible to show a screen preview of that image.

Eps images will have some instructions in them to place the image somewhere on the page, so you willl have to experiment to get the location correct.  So, even though we have placed the image at 450 points below the bottom of the page, this makes this particular image appear in the middle of the page!

Using eps images is a black art.  Our experience is that eps images created by Adobe products don't work, and those created on Macintosh computers often do not work. 

Eps images are just postscript code, so in some instances it is possible to fix them by recoding the instructions in the image. 

If you are going to use an eps image, make sure it is on a mapped drive so that the server and your PC can both see it at the same drive letter and location.  Otherwise, when you do a server generated PDF, it won't fail because the image is actually on your local PC! 

Barcodes

You can print words in the 3of9 bar code font by enclosing them in surrounding "*".

For example the following code placed just before the "showpage" prints a vertically oriented barcode on the left edge of the superbill

gsave
at 50x200 
rotate 90
(uppercase rejoin ["*" ssnfld/text "*"])
grestore

Other Resources

  • A tutorial on altering the prescription template, and showing how an eps image can be added.
  • Logging on the prescription who it was faxed to ( An urgent care facility which keeps paper copies of all faxes sent )



 

Tags:
 
Images (0)
 
Comments (0)
You must login to post a comment.