I managed to come up with a solution that is not perfect, but allows users to get more details of the documents they're trying to see.
Two controls were added to the aspx page:
<div class="Controls">
<asp:Label ID="info" runat="server" Text=""></asp:Label>
<asp:Button ID="Return" runat="server" Text="Return" onclick="Return_Click" />
<asp:Button ID="Download" runat="server" Text="Download" onclick="Download_Click" />
<asp:Button ID="Stamp" runat="server" Text="Stamp" onclick="Stamp_Click" />
<asp:Button ID="Print" runat="server" Text="Print" onclick="Print_Click" />
<asp:Button ID="Zoom_In" runat="server" Text="-" onclick="ZoomIn_Click" />
<asp:Button ID="Zoom_Out" runat="server" Text="+" onclick="ZoomOut_Click" />
</div>
Also on the aspx page I modified the script that renders the tiff file to add the Size change percent:
<script type="text/javascript">
var html;
var cookie = c("TiffViewer");
var percent = '<%= Request.QueryString["ChangeSize"]%>';
var ImHeight = cookie["ImHeight"];
var ImWidth = cookie["ImWidth"];
for (var i = 1; i < +cookie["PageCount"] + 1; i++) {
$("#Pages").append("<a href='#page/" + (i - 1) + "'>" + i + "</a><br />");
if (ImHeight == 0 || ImWidth == 0) {
html = "<div class='slide' id='slide' overflow='scroll'><br /><b>Page {0}</b><br /><img id='p{1}' {2} /></div>";
$("#frames").append(String.format(html, i, i - 1, (i == (1) || i == (+cookie["PageCount"]) ? "src='Viewer.aspx?p=" + (i - 1) + "&" + "ChangeSize=" + percent + "'" : "")));
}
else {
var adjHeight = ImHeight / 2;
var adjWidth = ImWidth / 2;
html = "<div class='slide' id='slide' height='" + adjHeight.toString() + "'><br /><b>Page {0}</b><br /><img height='" + adjHeight.toString() + "' width='" + adjWidth.toString() + "' id='p{1}' {2} /></div>";
$("#frames").append(String.format(html, i, i - 1, (i == (1) || i == (+cookie["PageCount"]) ? "src='Viewer.aspx?p=" + (i - 1) + "&" + "ChangeSize=" + percent + "'" : "")));
}
}
</script>
On the code behind page I stored the values in cookies in the "using (var ia = new ImageAttributes())" section of code:
using (var ia = new ImageAttributes())
{
ia.SetColorMatrix(new ColorMatrix(gray_matrix));
ia.SetThreshold(0.8f, ColorAdjustType.Default);
//gr.DrawImage(b, new Rectangle(0, 0, (int)(b.Width * (1 + (percent / 100))), (int)(b.Height * (1 + (percent / 100)))), 0, 0, (int)(b.Width * (1 + (percent / 100))), (int)(b.Height * (1 + (percent / 100))), GraphicsUnit.Pixel, ia);
gr.DrawImage(b, new Rectangle(0, 0, (int)(b.Width * (1 + (percent / 100))), (int)(b.Height * (1 + (percent / 100)))), new Rectangle(0, 0, (int)(b.Width * (1 + (percent / 100))), (int)(b.Height * (1 + (percent / 100)))), GraphicsUnit.Pixel);
//gr.DrawImage(b, new Rectangle(0, 0, (int)(b.Width * (1 + (percent / 100))), (int)(b.Height * (1 + (percent / 100)))), new Rectangle(0, 0, b.Width, b.Height), GraphicsUnit.Pixel);
string myHeight;
string myWidth;
ImHeight = (int)(b.Height * (1 + (percent / 100)));
ImWidth = (int)(b.Width * (1 + (percent / 100)));
myHeight = ImHeight.ToString(); ;
myWidth = ImWidth.ToString(); ;
Response.Cookies["TiffViewer"]["ReturnURL"] = c["ReturnURL"];
Response.Cookies["TiffViewer"]["Key"] = c["Key"];
Response.Cookies["TiffViewer"]["ImHeight"] = myHeight;
Response.Cookies["TiffViewer"]["ImWidth"] = myWidth;
Response.Cookies["TiffViewer"]["PageCount"] = c["PageCount"];
}
For the two new controls I added the following click procedures:
protected void ZoomIn_Click(object sender, EventArgs e)
{
var c = Request.Cookies["TiffViewer"];
string key = c["Key"];
if (Cache[key] != null)
{
float chg = -10.0f;
float percent = 0.0f;
float.TryParse(Request.QueryString["ChangeSize"], out percent);
percent += chg;
int ImHeight = 0;
int.TryParse(c["ImHeight"], out ImHeight);
int ImWidth = 0;
int.TryParse(c["ImWidth"], out ImWidth);
string myHeight = "0";
string myWidth = "0";
if (ImHeight > 0 && ImWidth > 0)
{
ImHeight = (int)(ImHeight * (1 + (percent / 100)));
myHeight = ImHeight.ToString();
ImWidth = (int)(ImWidth * (1 + (percent / 100)));
myWidth = ImWidth.ToString();
}
Response.Cookies["TiffViewer"]["ReturnURL"] = c["ReturnURL"];
Response.Cookies["TiffViewer"]["Key"] = c["Key"];
Response.Cookies["TiffViewer"]["ImHeight"] = myHeight;
Response.Cookies["TiffViewer"]["ImWidth"] = myWidth;
Response.Cookies["TiffViewer"]["PageCount"] = c["PageCount"];
Response.Redirect("~/Viewer/Viewer.aspx?ChangeSize=" + percent.ToString());
}
}
protected void ZoomOut_Click(object sender, EventArgs e)
{
var c = Request.Cookies["TiffViewer"];
string key = c["Key"];
if (Cache[key] != null)
{
float chg = 10.0f;
float percent = 0.0f;
float.TryParse(Request.QueryString["ChangeSize"], out percent);
percent += chg;
int ImHeight = 0;
int.TryParse(c["ImHeight"], out ImHeight);
int ImWidth = 0;
int.TryParse(c["ImWidth"], out ImWidth);
string myHeight = "0";
string myWidth = "0";
if (ImHeight > 0 && ImWidth > 0)
{
ImHeight = (int)(ImHeight * (1 + (percent / 100)));
myHeight = ImHeight.ToString();
ImWidth = (int)(ImWidth * (1 + (percent / 100)));
myWidth = ImWidth.ToString();
}
Response.Cookies["TiffViewer"]["ReturnURL"] = c["ReturnURL"];
Response.Cookies["TiffViewer"]["Key"] = c["Key"];
Response.Cookies["TiffViewer"]["ImHeight"] = myHeight;
Response.Cookies["TiffViewer"]["ImWidth"] = myWidth;
Response.Cookies["TiffViewer"]["PageCount"] = c["PageCount"];
Response.Redirect("~/Viewer/Viewer.aspx?ChangeSize=" + percent.ToString());
}
}
Why is this code imperfect? In part because other parts of this code is designed to render the tiff the height of the window. So the tiff is never rendered taller, only wider by this code. So though this is inelegant it does let the users "zoom" to see the details of the documents better.