简体   繁体   English

打印,但需要图像名称

[英]printing but need image name

I am trying to print a single tiff file with multiple frames. 我正在尝试打印带有多个帧的单个tiff文件。 However if I use javascript (window.print()) i get a print out of the entire webpage and not just the tiff image. 但是,如果我使用javascript(window.print()),则会得到整个网页的打印内容,而不仅仅是tiff图像。

So I looked around StackOverflow and found some sample code. 因此,我环顾了StackOverflow,发现了一些示例代码。 I was trying to implement it however the problem is the that the code works for an absolute image URL :- such as "C:\\img.jpeg" 我试图实现它,但是问题是该代码适用于绝对图像URL:-如“ C:\\ img.jpeg”

I am wondering if anyone can show me how to transform my imgFax.ImageUrl to an actual image name? 我想知道是否有人可以向我展示如何将imgFax.ImageUrl转换为实际的图像名称? (otherwise I get an error:- "Illegal character in path" <--- in my System.Drawing.Image img = System.Drawing.Image.FromFile(imgFax.ImageUrl); code) (否则,我得到一个错误:-“ System.Drawing.Image img中的”路径中的非法字符“ <--- = System.Drawing.Image.FromFile(imgFax.ImageUrl);代码)

If anyone can show me some sample code that would be amazing! 如果有人可以给我看一些示例代码,那就太好了! Thanks. 谢谢。

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); 
} 

I'm not sure whether you can at all do any printing in ASP via PrintDocument. 我不确定您是否可以通过PrintDocument在ASP中进行任何打印。 This is all server-side code, while the printing is to be done at - and by the client's browser. 这是所有服务器端代码,而打印将在- 以及由客户端的浏览器完成。 I think that you will have to do it via JavaScript, but to not print the entire page - you will have to create another page that will only present the contents to be printed, then redirect the user to that smaller page (for example in a popup window) and then auto-print it via javascript. 我认为您将必须通过JavaScript来执行此操作,但不打印整个页面-您将不得不创建另一个仅显示要打印内容的页面,然后将用户重定向到该较小的页面(例如,弹出窗口),然后通过javascript自动打印。 I;m not 100% sure, but all banking sites I use seem to follow that, and this is quite common in general.. 我不是100%确信,但是我使用的所有银行网站似乎都遵循这一点,这在一般情况下很普遍。

For example, here's an article with this exact approach: http://www.dotnetcurry.com/ShowArticle.aspx?ID=92 例如,这是使用这种确切方法的文章: http : //www.dotnetcurry.com/ShowArticle.aspx?ID=92

just remember that your small 'print-page' should actually display the things you want to print :) 只要记住您的小“打印页面”实际上应该显示您要打印的内容即可:)

another nice link on printing images: http://forums.asp.net/post/3369436.aspx 关于打印图像的另一个不错的链接: http : //forums.asp.net/post/3369436.aspx

You could split the single tiff image into separate files, as demonstrated here , then you could have a unique URL for each image: 你可以在单一的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;
}

Eh, ok.. I know I already answered something, but I've noticed that you've marked the question bold.. So here it is: YOU CANNOT, there is NO WAY. 恩,好吧。。我知道我已经回答了一些问题,但是我注意到您已将该问题标记为粗体。所以在这里是:您不能,没有办法。

Url that you have that points to the image is just an internet link. 您指向该图片的网址只是一个互联网链接。 It might point to the image, or to a website, or to some binary data. 它可能指向图像,网站或一些二进制数据。 The remote webserver reads the URL parameters and decides what to do with it. 远程Web服务器读取URL参数并决定如何处理。 There is no file name at all. 根本没有文件名。 Only URL of the webpage "ShowFax.ashx" and its parameters. 网页“ ShowFax.ashx”及其参数的唯一URL。

Some webpages may return you a special header, content-disposition/attachement, and in that header they may sometimes provide you with a filename. 某些网页可能会为您返回一个特殊的标题,内容处置/附件,并且有时在该标题中可能会为您提供文件名。 This is how "download" webpages provide the information to the browser so it may display a "Save file as.." window to the user. 这就是“下载”网页向浏览器提供信息的方式,因此它可以向用户显示“文件另存为...”窗口。 However, it probably is not the case. 但是,事实可能并非如此。 You are displaying the image in a aspx control that simply reads the image from an URL. 您正在通过简单的URL读取图像的aspx控件中显示图像。 It is all automated by the control, so you do not even have chance to peek the headers -- of course, unless you manually send the request, capture the stream, peek, redirect it back to the control, etc. IMHO, too much job for simple task of printing, and that would be only the beginning! 它全部由控件自动执行,因此,您甚至没有机会窥视标头-当然,除非您手动发送请求,捕获流,窥视,将其重定向回控件等,否则恕我直言。简单的打印任务,那仅仅是个开始!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM