print - portrait or landscape

X

xdzgor

Hi

we have an intranet site with a print function. We generate a "print
friendly" version of a page, and the user can click a "print" button,
which causes the javascript "print()" function to be called.

Is it possible to allow the user to select whether the printout should
be in portrait or landscape? I have seen examples on the web which set
landscape - but this appears to be a global setting (so it will always
be landscape). We would like to allow the user to check a checkbox or
something - so they can decide at runtime if they print in portrait or
landscape.

I know the windows print dialog allows the selection og portrait or
landscape - but we'd like the user to be able to make this selection
on the web page.

BTW, as this is an intranet site, the customer has decided the browser
will always be internet explorer 6 or 7 (if this makes the task easier
or harder I have no idea).

Thanks,
Peter
 
E

Evertjan.

xdzgor wrote on 24 aug 2009 in comp.lang.javascript:
Is it possible to allow the user to select whether the printout should
be in portrait or landscape?

No.
Not with clientside Javascript in the browser.

This has been told so many times in this NG!
 
X

xdzgor

xdzgor wrote on 24 aug 2009 in comp.lang.javascript:


No.
Not with clientside Javascript in the browser.

This has been told so many times in this NG!

OK - sorry, I'll see if I can find those posts. The info I have found
does seem to suggest it is indeed possible to set the print format to
landscape though (via css) - so maybe I can "fudge" it somehow with
different pages utilising different css for portrait or landscape.

/Peter
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]>,
xdzgor wrote on 24 aug 2009 in comp.lang.javascript:


No.
Not with clientside Javascript in the browser.

This has been told so many times in this NG!

In that case it should be in the FAQ, which has not been updated for
over six weeks.
 
E

Evertjan.

Dr J R Stockton wrote on 25 aug 2009 in comp.lang.javascript:
In comp.lang.javascript message <[email protected]>,


In that case it should be in the FAQ, which has not been updated for
over six weeks.

No, the number of frequently asked things that are not possible would
outnumber the miriad of things that are possible with Javascript.

While the Q is FA, it is also off topic, even for the FAQ,
since things that are not possible are automagically outside
the realm of Javascript.

Feel free to disagree, John.
 
T

Thomas 'PointedEars' Lahn

xdzgor said:
we have an intranet site with a print function. We generate a "print
friendly" version of a page,

Not necessary. Print stylesheets are widely supported nowadays.
and the user can click a "print" button, which causes the javascript
"print()" function to be called.

Is it possible to allow the user to select whether the printout should
be in portrait or landscape? I have seen examples on the web which set
landscape - but this appears to be a global setting (so it will always
be landscape). We would like to allow the user to check a checkbox or
something - so they can decide at runtime if they print in portrait or
landscape.

You can try using client-side scripting to toggle the `size' property as
defined in the current working draft for the CSS3 Paged Media module, of a
stylesheet for the `print' media type.¹ For example:

document.styleSheets[0].cssRules[0].cssRules[0].style.size = "A4 "
+ (condition ? "landscape" : "portrait");

if the first stylesheet (index 0) referred to by the document starts like

@media print {
@page {
size: A4 portrait;
}
}

However, whether the user agent and ultimately the printer driver invoked by
it honors that declaration and the property change is another matter.

Also, print() is _not_ a "javascript function"; it is a method of Window
host objects (as provided by a language-independent AOM/DOM API), and a
Window object happened to be in the scope chain in said cases. Use
window.print() instead.


PointedEars
___________
¹ <http://www.w3.org/TR/css3-page/#size>
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]>
Dr J R Stockton wrote on 25 aug 2009 in comp.lang.javascript:


No, the number of frequently asked things that are not possible would
outnumber the miriad of things that are possible with Javascript.

While the Q is FA, it is also off topic, even for the FAQ,
since things that are not possible are automagically outside
the realm of Javascript.

Feel free to disagree, John.


The FAQ is supposed to be useful for the readers of the group, both by
helping those who actually have a common question and by saving the
regulars from seeing, and maybe answering, such questions repeatedly. A
newcomer, even one who reads the FAQ first, can understand the ambit of
the group, but cannot be expected to know what is not possible within
that ambit.

There could be a section "What cannot be done in JavaScript" (with a
subsection "What cannot be done in Web JavaScript") for one-line
answers. For this case, the subsection might contain "Setting print
format directly (use a Print stylesheet / @media rules)".



It may not be appropriate to specify the orientation. A page whose
content is appropriate for portrait A4 should be printed portrait on an
A4 printer; but landscape might be preferred on an A3 printer. Loading
square paper could remove the problem.



The OP is using an intranet, where the browser will always be Internet
Explorer 6 or 7 (what about IE 8 etc.?). Therefore, ISTM that he will
really be using JScript. Web page
<http://msdn.microsoft.com/en-us/library/system.drawing.printing.pageset
tings.landscape(VS.71).aspx> contains

NET Framework Class Library
...
[JScript]
public function get Landscape() : Boolean;
public function set Landscape( Boolean);

which rather suggests that the OP may be able to do it. Possibly an HTA
would be needed.


<FAQENTRY> To say explicitly in FAQ 1.2 end that, in JScript, more
routines are accessible.
 
T

Thomas 'PointedEars' Lahn

Dr said:
The OP is using an intranet, where the browser will always be Internet
Explorer 6 or 7 (what about IE 8 etc.?). Therefore, ISTM that he will
really be using JScript.

He may also be using VBScript. The programming language really does not
matter; the APIs accessible with it are.
Web page
<http://msdn.microsoft.com/en-us/library/system.drawing.printing.pageset
tings.landscape(VS.71).aspx> contains

NET Framework Class Library
...
[JScript]
public function get Landscape() : Boolean;
public function set Landscape( Boolean);

which rather suggests that the OP may be able to do it. Possibly an HTA
would be needed.


<FAQENTRY> To say explicitly in FAQ 1.2 end that, in JScript, more
routines are accessible.

That would be wrong. It is _not_ a language feature.


PointedEars
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]>, Wed,
26 Aug 2009 20:09:34 said:
He may also be using VBScript.

One would not expect him to have asked in a JavaScript newsgroup if he
was using VBscript. However, in his circumstances, VBscript should be
available.

The programming language really does not
matter; the APIs accessible with it are.

Agreed, pedantically. But, in practice, a user is interested in what
may be used within a <script type="text/javascript"> section, regardless
of whether it is ECMA, DOM, API, or whatever.

Web page
<http://msdn.microsoft.com/en-us/library/system.drawing.printing.pageset
tings.landscape(VS.71).aspx> contains

NET Framework Class Library
...
[JScript]
public function get Landscape() : Boolean;
public function set Landscape( Boolean);

which rather suggests that the OP may be able to do it. Possibly an HTA
would be needed.

And the above shows that relevant APIs are accessible to JScript. The
part of the page which I indicated by ellipsis does not include
"VBScript", though it includes "Visual Basic".

That would be wrong. It is _not_ a language feature.

You show an incorrect attitude. The purposes of the FAQ include being
helpful to those who consult it; and those who need to be sent away
should be sent away helpfully. It could be differently phrased; the "in
JScript" could be replaced by "when using JScript". However, while ECMA
define the JavaScript language and not what it interacts with (e.g.
"alert" is not a substring of the ECMA standards), it is Microsoft which
is authoritative for JScript, and they take a broader view.
 
T

Thomas 'PointedEars' Lahn

Dr said:
Thomas 'PointedEars' Lahn posted:

You show an incorrect attitude.

That I would prefer the FAQ to be correct, instead of incorrect and outright
misleading, is an incorrect attitude? How fortunate then that it is not you
who sets the standards by which people's attitudes should be judged.
The purposes of the FAQ include being helpful to those who consult it;
and those who need to be sent away should be sent away helpfully. It
could be differently phrased; the "in JScript" could be replaced by "when
using JScript". However, while ECMA define the JavaScript language and
not what it interacts with (e.g. "alert" is not a substring of the ECMA
standards), it is Microsoft which is authoritative for JScript, and they
take a broader view.

Nothing that you said changes the fact that this statement would be wrong.
It *is* _not_ a language feature. A correct wording would be "In .NET
applications, more routines are accessible, for example using JScript .NET."

However, that in a different environments different features are available
is pretty much self-evident. And with regard to browser scripting it is of
little practical value. So I doubt whether any of this should be part of
the FAQ at all.

Is this even a *frequently* *asked* question to begin with? I have read it
recently in the SVN Book and found it to be true: FAQ authors tend to not
list the questions that are asked frequently, but questions that they wish
people would ask.¹ The current cljs FAQ includes several such questions
and shouldn't.


PointedEars
___________
¹ <http://svnbook.red-bean.com/en/1.5/svn.foreword.html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top