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!

Determine orientation ?

Status
Not open for further replies.

tpercy

Programmer
Oct 3, 2002
19
US
Hello!

How can I determine orientation using postscript? My PPD file has no mention of orientation. I am trying to create the below conditional statement:

If landscape then use this form
else portrait use this form

I am confused on how I should go about this, do I need to get the pagesize or bounding box?

Much thanks for any help!

 
Orientation is basically a meaningless concept in PostScript.

Think of it this way: PostScript is device-independent. Orientation is a device-level choice or function (print from this tray, or that tray).

All PostScript cares about is marking things on a page. If the page is 8.5x11 vs 11x8.5, it doesn't care. They are just two different sizes, the concept of "orientation" doesn't come into play.

You can look for a DSC (Document Structuring Convention) comment, %%Orientation. Of course it won't be there in every case, or even the majority of cases.

This is a comment meant to be read by a Document Manager. This is a term Adobe uses for hardware or software that "pre-processes" the PostScript, reading DSC to setup parameters for the job prior to ripping.

Related DSC comments that might be helpful are:

%%PageOrientation
%%BoundingBox
%%PageBoundingBox

You can also look for setpagedevice dictionaries that contain the /PageSize entry, and try to interpret "orientation" from that.

Since you're posting in a PostScript programming forum, can I assume that when you mean "conditional expression" and "use this form", that you are referring to PostScript language operators, booleans, and form dictionaries?

In this case, and I'm working in the absence of any detail here, if you know how to programmatically change the Form Dictionary, you can certainly change the pagesize and rotation as well.

Let me know some more details about the job at hand, and I should be able to help more.

Thomas D. Greer
 
I am using /BeginPage and /Setpagedevice. I am placing text in all four corners of a page using initgraphics, moveto, show, grestore. My problem is that I don't know how to check page size or bounding box and I am not familiar with postscript. Below is the code I use for portrait size letter. For landscape I need to change the coordinates and add a rotate but how do I concat these together in the form of a conditional statement?

If portrait use the below code

<</BeginPage
{pop gsave initgraphics /Arial 12 selectfont
12 772 moveto (DEMO) show
560 772 moveto (DEMO) show
12 12 moveto (DEMO) show
560 12 moveto (DEMO) show grestore}
>>setpagedevice

else use different code


Thanks.
 
How are you getting this code into your PostScript programs?

What is generating the PostScript programs in the first place?

Could you post a link to a representative PostScript file?

A suggestion: why not print the word DEMO at a 45 degree angle in each corner? This way you wouldn't have to test... it's the same code regardless of orientation.


Thomas D. Greer
 
I don't have a Type1 Arial font on my system, so you'll have to experiment with the moveto values, but something like this is what I had in mind:

Code:
%!PS

<< /BeginPage
   { pop 
     gsave
       /Arial 12 selectfont
       12 760 moveto 45 rotate (DEMO) show -45 rotate
       584 780 moveto -45 rotate (DEMO) show 45 rotate
       180 rotate -612 -792 translate
       12 760 moveto 45 rotate (DEMO) show -45 rotate
       584 780 moveto -45 rotate (DEMO) show 45 rotate
     grestore
   }
>> setpagedevice

Thomas D. Greer
 
Thank you for your suggestions, but the requirements are for only letter size paper with the background text (same direction as text) in all four corners. I have placed the call to the postscript code in the PPD file. I am using a HP8000 printer.
Being I am not at work today I do not have a copy of the postscript file to post.

Thank you.
 
Ok. If you're always processing PostScript from the same source, we can look it over and find out what to base our code on. Likely, the code uses a setpagedevice dictionary with a /PageSize entry.

To get the value of this entry, you use &quot;currentpagedevice&quot;. So the placement of your code is critical. If your code runs BEFORE the source file sets the page size, that obviously does you no good.

&quot;currentpagedevice&quot; returns a copy of the current pagedevice dictionary. The idea is to pull out the PageSize array, compare it to a test value, and perform a conditional statement based on the result. Note, you shouldn't use &quot;initgraphics&quot;.

Code:
currentpagedevice /PageSize get  %get the array value
[612 792] eq                     %compare to &quot;portrait&quot;
{ % if equal
  <</BeginPage
  {pop gsave /Arial 12 selectfont
  12 772 moveto (DEMO) show
  560 772 moveto (DEMO) show
  12 12 moveto (DEMO) show
  560 12 moveto (DEMO) show grestore}
  >>setpagedevice
}
{ %else, landscape
  % insert proper code here, it'll be
  % the same as above, just with differen moveto values
} ifelse

This code assumes that there is a /PageSize value, and that the value is either &quot;[612 792]&quot; or &quot;[792 612]&quot;.

Thomas D. Greer
 
Thank you for all your help.

I tried the above code, but it keeps defaulting to the ifelse. How do I know if there is an actual /PageSize value? If I look at the beginning of a .ps file the only values given are boundingbox values. For instance when printing a Word portrait I get boundingbox values of 13 13 599 779 and for a landscpe document I get 12 13 779 599.
Do you have any other suggestions?
Thanks.
 
To determine if a key exists in a dictionary, use the &quot;known&quot; operator:

Code:
currentpagedevice /PageSize known

That will return a boolean.

You don't really have access to comments like BoundingBox via your PostScript program, without resort to some fancy file i/o (making the program read itself!).

The comments are meant to be read and acted upon by external programs/processes.

I can't help you any further without seeing some sample programs.

Thomas D. Greer
 
The code below is the code I am using. How do I get or is there sample code that would print out the correct pagesize array? Then I could plug those numbers into the test array.
Since it is in the ppd file is it taking into account margins?
Thanks.

currentpagedevice /PageSize get
[612 792] eq
{ % if equal
<</BeginPage
{pop gsave /Arial 10 selectfont
12 772 moveto (DEMO) show
560 772 moveto (DEMO) show
12 12 moveto (DEMO) show
560 12 moveto (DEMO) show grestore}
>> setpagedevice
}
{ %else, landscape
<</BeginPage
{pop gsave /Arial 10 selectfont
599 12 moveto 90 rotate (DEMO) show grestore
gsave /Arial 10 selectfont
599 735 moveto 90 rotate (DEMO) show grestore
gsave /Arial 10 selectfont
19 12 moveto 90 rotate (DEMO) show grestore
gsave /Arial 10 selectfont
19 735 moveto 90 rotate (DEMO) show grestore}
>> setpagedevice
}ifelse

 
I'm sorry for not being clearer. I meant sample PostScript output. I'm still unsure if you are dealing with PostScript from a single source, or want your code to work with all PostScript generated by any application on your system.

Thomas D. Greer
 
I hope this is what you were talking about. This is the beginning of a .ps file.

_%-12345X@PJL JOB
@PJL SET RESOLUTION = 600
@PJL SET BITSPERPIXEL = 2
@PJL SET ECONOMODE = OFF
@PJL ENTER LANGUAGE = POSTSCRIPT
%!PS-Adobe-3.0
%%Title: Microsoft Word - Test.doc
%%Creator: Windows NT 4.0
%%CreationDate: 16:31 5/21/2003
%%Pages: (atend)
%%BoundingBox: 13 13 599 779
%%LanguageLevel: 2
%%DocumentNeededFonts: (atend)
%%DocumentSuppliedFonts: (atend)
%%EndComments
%%BeginProlog
%%BeginResource: procset NTPSOct95
/NTPSOct95 100 dict dup begin/bd{bind def}bind def/ld{load def}bd/ed{exch def}
bd/a{currentpoint}bd/c/curveto ld/d/dup ld/e/eofill ld/f/fill ld/tr/translate
ld/gr/grestore ld/gs/gsave ld/j/setlinejoin ld/L/lineto ld/M/moveto ld/n
/newpath ld/cp/closepath ld/rm/rmoveto ld/sl/setlinewidth ld/sd/setdash ld/g
/setgray ld/r/setrgbcolor ld/s/stroke ld/t/show ld/aw/awidthshow ld/im
/imagemask ld/MS{moveto show}bd/SF{findfont exch scalefont setfont}bd/SM{cmtx
setmatrix}bd/MF{findfont exch makefont setfont}bd/CM{/cmtx matrix currentmatrix
def}bd/B{M exch dup 0 rlt exch 0 exch rlt neg 0 rlt}bd/CB{B cp eoclip}bd/EA{1
index 0/G0 put 4 string 1 1 4 -1 roll{3 copy neg exch cvs dup 0 71 put cvn 3 -1
roll exch put}for pop}bd/rlt/rlineto ld/L2?/languagelevel where{pop
languagelevel 2 ge}{false}ifelse def end def
%%EndResource
%%EndProlog
%%BeginSetup
[{0
/languagelevel where{pop languagelevel 2 ge}{false}ifelse
{1 dict dup/JobTimeout 4 -1 roll put setuserparams}
{statusdict/setjobtimeout get exec}ifelse
}stopped cleartomark
[{120
/languagelevel where{pop languagelevel 2 ge}{false}ifelse
{1 dict dup/WaitTimeout 4 -1 roll put setuserparams}
{statusdict/waittimeout 3 -1 roll put}ifelse
}stopped cleartomark
/#copies 1 def
[{

 
Yes, that's what I need. However you stopped a little too soon! Notice the comment &quot;%%BeginSetup&quot;? We need to examine the entire setup section, though the %%EndSetup comment.

Thomas D. Greer
 
Sorry, here is the rest.

%%BeginFeature: *HPPaperPolicy PromptUser

<</DeferredMediaSelection true>> setpagedevice
%%EndFeature
} stopped cleartomark
[{
%%BeginFeature: *HPHalftone PrinterDefault

%%EndFeature
} stopped cleartomark
[{
%%BeginFeature: *HPCollate True
<</Collate true>> setpagedevice
%%EndFeature
} stopped cleartomark
[{
%%BeginFeature: *Smoothing True

<< /PostRenderingEnhance true /PostRenderingEnhanceDetails << /REValue 2 /Type 8 >>
>> setpagedevice
%%EndFeature
} stopped cleartomark
[{
%%BeginFeature: *PageSize Letter

<</PageSize [612 792] /ImagingBBox null>> setpagedevice
%%EndFeature
} stopped cleartomark
[{
%%BeginFeature: *StapleLocation 1parallel

userdict /HPStapleOption {(ONE)} put
%%EndFeature
} stopped cleartomark
[{
%%BeginFeature: *OutputBin Upper
<</Staple 0 /OutputType (TOP OUTPUT BIN)>> setpagedevice
%%EndFeature
} stopped cleartomark
[{
%%BeginFeature: *Duplex None

<</Duplex false>> setpagedevice
%%EndFeature
} stopped cleartomark
[{
%%BeginFeature: *HPwmFont HelveticaB

/Helvetica-Bold findfont dup length dict begin
{1 index /FID ne {def} {pop pop} ifelse} forall
/Encoding ISOLatin1Encoding def currentdict
end
/HPwmFont exch definefont pop
%%EndFeature
} stopped cleartomark
[{
%%BeginFeature: *HPwmTextStyle Medium
userdict /HPwmStyle .48 put
%%EndFeature
} stopped cleartomark
[{
%%BeginFeature: *HPwmTextAngle Deg45
userdict /HPwmAngle 45 put
%%EndFeature
} stopped cleartomark
[{
%%BeginFeature: *HPwmFontSize pt48
userdict /HPwmSize 48 put
%%EndFeature
} stopped cleartomark
[{
%%BeginFeature: *HPwmLocation True
userdict /HPwmLocation true put
%%EndFeature
} stopped cleartomark
[{
%%BeginFeature: *HPwmText None

%%EndFeature
} stopped cleartomark
[{
%%BeginFeature: *HPNup OneUp

% Copyright (c) Hewlett-Packard Co 1997
userdict begin
true setglobal /HPwm 5 dict dup begin /HPwmOn true def /HPwmOdd true def end def false setglobal

userdict /HPwmAngle known not {/HPwmAngle 45 def} if
userdict /HPwmSize known not {/HPwmSize 48 def} if
userdict /HPwmLocation known not {/HPwmLocation true def} if
userdict /HPwmStyle known not {/HPwmStyle .48 def} if
userdict /HPwmDuplex known not {/HPwmDuplex 0 def} if

/HPwmEOP {HPwmDuplex 0 eq {true}{HPwmDuplex 1 eq HPwmOdd eq dup not {erasepage}if
true setglobal /HPwmOdd HPwmOdd not def false setglobal}ifelse} bind def
end

<<
/EndPage {userdict begin
userdict /HPwmText known HPwm /HPwmOn get and
{initmatrix
0 setgray 1 setlinewidth true setstrokeadjust 0 setlinejoin 0 setlinecap [] 0 setdash
currentpagedevice /PageSize get aload pop 2 div exch 2 div exch translate
HPwmAngle rotate /HPwmFont userdict /HPppScale known {HPwmSize HPppScale mul}{HPwmSize}ifelse selectfont
HPwmText stringwidth 2 div neg exch 2 div neg exch
userdict /HPppScale known {HPwmSize HPppScale mul}{HPwmSize}ifelse .25 mul sub moveto
HPwmText false charpath userdict /HPwmStyle1 known
{gsave 1 setgray HPwmStyle1 HPwmStyle add setlinewidth stroke grestore} if
0 setgray HPwmStyle setlinewidth stroke
HPwmLocation not {true setglobal HPwm /HPwmOn false put false setglobal} if
} if
2 eq {pop false}{pop HPwm begin HPwmEOP end} ifelse
end } bind
>> setpagedevice
%%EndFeature
} stopped cleartomark
[{
%%BeginFeature: *HPScalePatterns Scale
/GDIBWPatternDict 18 dict def
/dtransform {GDIBWPatternDict /Width known {currentpagedevice /HWResolution get 0 get
150 div mul exch currentpagedevice /HWResolution get 0 get 150 div mul exch dtransform}{dtransform}ifelse} bind def
%%EndFeature
} stopped cleartomark
[{
%%BeginFeature: *Option2 False

%%EndFeature
} stopped cleartomark
[{
%%BeginFeature: *Option6 False

%%EndFeature
} stopped cleartomark
[{
%%BeginFeature: *Option3 False

%%EndFeature
} stopped cleartomark
[{
%%BeginFeature: *Option4 False

%%EndFeature
} stopped cleartomark
[{
%%BeginFeature: *Option5 False

%%EndFeature
} stopped cleartomark
[{
%%BeginFeature: *Option20 Standard

%%EndFeature
} stopped cleartomark
[{
%%BeginFeature: *Option21 MailboxModeMailbox

%%EndFeature
} stopped cleartomark
[{
%%BeginFeature: *VMOption 16-19MB

%%EndFeature
} stopped cleartomark
%%EndSetup
 
There it is!

Notice this section:
Code:
[{
%%BeginFeature: *PageSize Letter

  <</PageSize [612 792] /ImagingBBox null>> setpagedevice
%%EndFeature
} stopped cleartomark

If you can insert the code I gave you earlier, after this section, that will do what you want.

Notice that it makes a PageSize entry of [612 792]. That's portrait. [792 612] would be landscape.

Your PPD is writing this section. You need to edit the PPD to insert the needed code.

Thomas D. Greer
 
Hi tpercy,

You seem to know what your talking about am wondering if you can help me.

When am printing PDF's, portrait pages become landscape.
I've been trying to force the this in the example.ps file.
using:

<</Orientation 0>> setpagedevice

But unfortunately am having no luck! Any suggestions or code would be much appreiated.

Regards,
Mark

 
Hi tgreer,

You seem to know what your talking about am wondering if you can help me.

When am printing PDF's, portrait pages become landscape.
I've been trying to force the this in the example.ps file.
using:

<</Orientation 0>> setpagedevice

But unfortunately am having no luck! Any suggestions or code would be much appreiated.

Regards,
Mark

 
&quot;setpagedevice&quot; is an operator to pass instructions on to a particular output device. If your output device doesn't recognize the /Orientation entry, then nothing happens.

I don't understand the relationship between your problem PDFs and your &quot;example.ps&quot; file. Can you explain your setup in more detail?

Thomas D. Greer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top