indexToPrint = this.twoPage.currentIndexL;
}
+ var aspectRatio = this.getPageWidth(indexToPrint) / this.getPageHeight(indexToPrint);
+
htmlStr = '<p style="text-align:center;"><b><a href="javascript:void(0);" onclick="window.frames[0].focus(); window.frames[0].print(); return false;">Click here to print this page</a></b></p>';
- htmlStr += '<iframe name ="printFrame" id="printFrame" src="/bookreader/GnuBookPrint.php?id='+this.bookId+'&server='+this.server+'&zip='+this.zip+'&index='+this.leafMap[indexToPrint]+'&format='+this.imageFormat+'" width="500px" height="400px"></iframe>';
+ htmlStr += '<iframe name ="printFrame" id="printFrame" src="/bookreader/GnuBookPrint.php?id='+this.bookId+'&server='+this.server+'&zip='+this.zip+'&index='+this.leafMap[indexToPrint]+'&format='+this.imageFormat+'&aspect=' + aspectRatio + '" width="500px" height="400px"></iframe>';
htmlStr += '<p style="text-align:center;"><a href="" onclick="gb.printPopup = null; $(this.parentNode.parentNode).remove(); return false">Close popup</a></p>';
this.printPopup.innerHTML = htmlStr;
$zip = $_REQUEST['zip'];
$index = $_REQUEST['index'];
$format = $_REQUEST['format'];
+$imgAspect = $_REQUEST['aspect'];
+
+/* We assume that the print aspect ratio is somewhat close to US Letter in portrait orientation */
+$paperAspect = 8.5/11;
+
+$rotate = "0";
+if ('jp2' == $format) {
+ // Rotation is possible
+ if ($imgAspect > $paperAspect) {
+ $rotate = "90";
+ $imgAspect = 1 / $imgAspect;
+ }
+}
$file = sprintf("%s_%s/%s_%04d.%s", $id, $format, $id, $index, $format);
+
+if ($imgAspect > $paperAspect) {
+ // wider than paper, fit width
+ $imgAttrs = "width='100%'";
+} else {
+ // taller than paper, fit height
+ $imgAttrs = "height='100%'";
+}
+
echo "<p style='text-align:center;'>";
-echo "<img src='http://{$server}/GnuBook/GnuBookImages.php?zip={$zip}&file={$file}&scale=1' height='100%'/>";
+echo "<img src='http://{$server}/GnuBook/GnuBookImages.php?zip={$zip}&file={$file}&scale=1&rotate=$rotate' " . $imgAttrs . " />";
echo "</p>";
?>
\ No newline at end of file