A friend of mine was trying to force a web browser to print in landscape for a specific XSL transformed XML page. I mulled this over while on my lunch break and put together this little proof-of-concept when I got back; while it doesn't do ANYTHING to the printer, it renders the page at a different 90 degree angle so when printed it appears to be landscape format:
First, a very simple XML data file (data.xml):
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="Style.xsl"?>
<data>
<quote>
<author>Socrates</author>
<text>I drank what?</text>
</quote>
<quote>
<author>Anonymous</author>
<text>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.</text>
</quote>
</data>
Second, an XSL file that will transform the XML into our landscape view (Style.xsl):
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<style>
div.page {
writing-mode: tb-rl;
height: 80%;
margin: 10% 0%;
}
div.page p {
margin-right: 80pt;
filter: progid:DXImageTransform.Microsoft.BasicImage(Rotation=1);
}
</style>
</head>
<body>
<div class="page">
<h2>Quotes</h2>
<xsl:apply-templates/>
</div>
</body>
</html>
</xsl:template>
<xsl:template match="quote">
<p>
<xsl:apply-templates select="author"/>
<xsl:apply-templates select="text"/>
</p>
</xsl:template><xsl:template match="author">
Author: <span style="color:darkgreen">
<xsl:value-of select="."/></span>
<br />
</xsl:template><xsl:template match="text">
Text: <span style="color:navy">
<xsl:value-of select="."/></span>
<br />
</xsl:template>
</xsl:stylesheet>
That's it. It's just a matter of having a DIV tag styled with the appropriate attributes. The "DXImageTransform.Microsoft.BasicImage . . ." is the critical bit of the style and, unfortunately, locks us into a browser with ActiveX support (basically just Internet Explorer). The full docs on this BasicImage approach are here: http://msdn.microsoft.com/library/default.asp?url=/workshop/author/filter/reference/filters/basicimage.asp
I've put these filters to good use on other projects, creating gradient backgrounds for tables (http://msdn.microsoft.com/library/default.asp?url=/workshop/author/filter/reference/filters/gradient.asp) and other clever UI stuff. Remember, it's Internet Explorer specific.