[英]Need help printing on a <td> 2 eval functions for an asp.net image object
[英]printing but need image name
我正在尝试打印带有多个帧的单个tiff文件。 但是,如果我使用javascript(window.print()),则会得到整个网页的打印内容,而不仅仅是tiff图像。
因此,我环顾了StackOverflow,发现了一些示例代码。 我试图实现它,但是问题是该代码适用于绝对图像URL:-如“ C:\\ img.jpeg”
我想知道是否有人可以向我展示如何将imgFax.ImageUrl转换为实际的图像名称? (否则,我得到一个错误:-“ System.Drawing.Image img中的”路径中的非法字符“ <--- = System.Drawing.Image.FromFile(imgFax.ImageUrl);代码)
如果有人可以给我看一些示例代码,那就太好了! 谢谢。
protected void PrintAll_Click(object sender, EventArgs e)
{
// number of frames
int number = _FaxPages.Count;
// for loop to iterate through each frame
for (int i = 0; i < number; i++)
{
// fax ID
string _FaxId = Page.Request["FaxId"];
//string _Frame = Page.Request["Frame"];
// current frame
_PageIndex = i;
// IMG URL
imgFax.ImageUrl = "ShowFax.ashx?n=" + _FaxId + "&f=" + _PageIndex + "&mw=750";
PrintDocument pd = new PrintDocument();
pd.PrintPage += PrintPage;
pd.Print();
}
}
private void PrintPage(object o, PrintPageEventArgs e)
{
System.Drawing.Image img = System.Drawing.Image.FromFile(imgFax.ImageUrl);
Point loc = new Point(100, 100);
e.Graphics.DrawImage(img, loc);
}
我不确定您是否可以通过PrintDocument在ASP中进行任何打印。 这是所有服务器端代码,而打印将在- 以及由客户端的浏览器完成。 我认为您将必须通过JavaScript来执行此操作,但不打印整个页面-您将不得不创建另一个仅显示要打印内容的页面,然后将用户重定向到该较小的页面(例如,弹出窗口),然后通过javascript自动打印。 我不是100%确信,但是我使用的所有银行网站似乎都遵循这一点,这在一般情况下很普遍。
例如,这是使用这种确切方法的文章: http : //www.dotnetcurry.com/ShowArticle.aspx?ID=92
只要记住您的小“打印页面”实际上应该显示您要打印的内容即可:)
关于打印图像的另一个不错的链接: http : //forums.asp.net/post/3369436.aspx
你可以在单一的TIFF图像分割成单独的文件,这表现在这里 ,那么你可以为每个图像的唯一网址:
static String[] SplitFile(String file_name)
{
System.Drawing.Image imageFile = System.Drawing.Image.FromFile(file_name);
System.Drawing.Imaging.FrameDimension frameDimensions = new System.Drawing.Imaging.FrameDimension(imageFile.FrameDimensionsList[0]);
int NumberOfFrames = imageFile.GetFrameCount(frameDimensions);
string[] paths = new string[NumberOfFrames];
for (int intFrame = 0; intFrame < NumberOfFrames; ++intFrame)
{
imageFile.SelectActiveFrame(frameDimensions, intFrame);
Bitmap bmp = new Bitmap(imageFile);
paths[intFrame] = System.IO.Path.GetDirectoryName(Application.ExecutablePath) + @"\" + intFrame.ToString() + ".tif";
bmp.Save(paths[intFrame], System.Drawing.Imaging.ImageFormat.Tiff);
bmp.Dispose();
}
imageFile.Dispose();
return paths;
}
恩,好吧。。我知道我已经回答了一些问题,但是我注意到您已将该问题标记为粗体。所以在这里是:您不能,没有办法。
您指向该图片的网址只是一个互联网链接。 它可能指向图像,网站或一些二进制数据。 远程Web服务器读取URL参数并决定如何处理。 根本没有文件名。 网页“ ShowFax.ashx”及其参数的唯一URL。
某些网页可能会为您返回一个特殊的标题,内容处置/附件,并且有时在该标题中可能会为您提供文件名。 这就是“下载”网页向浏览器提供信息的方式,因此它可以向用户显示“文件另存为...”窗口。 但是,事实可能并非如此。 您正在通过简单的URL读取图像的aspx控件中显示图像。 它全部由控件自动执行,因此,您甚至没有机会窥视标头-当然,除非您手动发送请求,捕获流,窥视,将其重定向回控件等,否则恕我直言。简单的打印任务,那仅仅是个开始!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.