Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help with beginpage and array

Status
Not open for further replies.

Wolfie7873

Technical User
Jan 15, 2004
94
US
Another newbie question . . . although I think i'm picking up fairly quickly...

From reading the PLRM, I understand there's a way to define a beginpage procedure that will execute when a new page is begun. Can this be used to display a "header" or banner or some other such thing? How do you define such a procedure? The PLRM is a little lacking in concrete examples.

Also, I think I get how to define an array (a useful thing for defining coordinate pairs in user space), but I don't understand the limitations, etc. For example if I say something like:

/inch 72 def
/width 8.5 inch mul def
/height 11 inch mul def
/size 2 array [width height] def
<</PageSize size>>setpagedevice

why doesn't it work? My understanding of the argument needed for PageSize is a 2x1 array and that's what size is, so why doesn't it work?

Eddie
 
First for the array; you've simply defined it incorrectly.

There are two ways to create an array. One way is to use the array operator to create an emtpy array, and then later fill it:
Code:
2 array dup 0 width put 1 height put

That will leave a two element array on the stack, but doesn't associate it in userdict with a key.

The other way is to simply put a mark on the stack: &quot;[&quot;, then your array elements, and then the &quot;]&quot; operator.

Note the terminology: &quot;[&quot; is just a mark. &quot;]&quot; is a special operator that creates an array.

So for your purposes, rewrite your code as follows:

Code:
/inch 72 def
/width 8.5 inch mul def
/height 11 inch mul def
/size [width height] def
<</PageSize size>>setpagedevice


Ok, for BeginPage, yes, you can use it for headers, footers, watermarks, pagination, etc.

It works in conjunction with setpagedevice. Here's an example:

Code:
<<
   /BeginPage
   { gsave
      /Helvetica 144 selectfont
      45 rotate
      .5 setgray
      288 72  moveto (DRAFT) show
     grestore
   } bind

>> setpagedevice

Whenever you use &quot;showpage&quot;, this procedure will be called &quot;automatically&quot;.


Thomas D. Greer
Providing PostScript & PDF
Training, Development & Consulting
 
OK! I get that - and the fun continues. . . .

if stringwidth returns two values, how do I use them? Is the information stored in an array or is it just two numbers pushed on the stack?

Eddie
 
Two numbers on the stack. They don't really represent &quot;stringwidth&quot;, that's a misnomer. They represent offsets, in points, that showing the string would create to the currentpoint.

Does that make sense? Stringwidth pushes two numbers on the stack, first the distance that &quot;x&quot; would move, then the distance &quot;y&quot; would move. Unless you're dealing with kanjii fonts, &quot;y&quot; doesn't move. So stringwidth is almost invariably followed by &quot;pop&quot; to discard the useless y value, and preceded by &quot;dup&quot; since stringwidth consumes the string.

&quot;dup stringwidth pop&quot; leaves your original string plus it's &quot;width&quot; on the stack.

You can just it for example to right-justify a string.
If your right margin is say at 512, you could use this code snippet, assuming that &quot;y&quot; is previously defined:

Code:
(Right-justify this string) dup stringwidth pop
512 exch sub y moveto show

I noticed the forum removed my square brackets in the previous post, strange, but I think you got the point.

May I ask why you're embarking on PostScript? Just curious.



Thomas D. Greer
Providing PostScript & PDF
Training, Development & Consulting
 
Mr. Greer,
Thank you for your continued help, I think I've almost got it. I'm trying to learn (self-teach, really) PostScript to supplement a utility I'm developing. Suffice it to say that the program I'm writing needs a device-independent printing procedure, and it seems that PostScript is the way to go. I'm writing my utility using C++ and the programmatic approach to device-independent printing appeals to me. I want my end-user to have the option of .txt .ps and .html (eventually, I want to do .pdf, too, but from glancing at that manual, it looks pretty tough). I also want seamless printing from the program. There won't be any paragraphs, just lines of text in certain spots; once i know the basic manipulations, I should be set.

Thanks again
Eddie
 
One other thing,
I've noticed that drawing the stack makes life a lot easier in terms of understanding PostScript's &quot;backwards&quot; notation.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top