views:

28

answers:

3

Enviroment: ASP.NET Framework 2.0

Is it possible to accomplish something like this:

I have this link <a href='printBarcode.aspx?code=HF54A'>Print Bar-code</a> and I want to print the response that the server sends for that link. Is that even possible? The response is text but it's not HTML, is some text that a special printer recognizes for printing bar-codes.

The idea is this: the user clicks on the link then the browser receives the response for that link and prompts to print it's content.

I'm happy to receive all suggestions and comments if you think you know of a better way to do this.

A: 

No, a browser has no functions for printing anything other than the content of a window. You can't take a response that is returned and send directly to a printer, the closest possible is to display the response in an iframe and ask for a printout of the iframe content. If the browser doesn't know how to visualize and print the response, you can't use the printing capability in the browser to print it.

If you want to send the response directly to a printer, you would have to run a component (flash/silverlight/Java) in the browser that could access the printer directly.

Guffa
A: 

You could return a page that is just the barcode text and auto popup the print dialog.

<script type="text/javascript">
window.print();
</script>

But I don't think this will work. I assume the browser will not send it to the printer in the correct format.

The problem is ASP.NET can't access a local printer in the server side code. To do some custom printing you would probably have to rely on Flash or Silverlight, if a plain print of the page doesn't work.

Krisc
A: 

You could put the text from the response into a [div id="textToPrint"] and call a javascript print(). If you can use a popup to open the link [a href='printBarcode.aspx?code=HF54A'] you can have a poopup page like:

[html] [body onLoad="print();"]

[div id="textToPrint"] YOUR TEXT FROM RESPONSE [/div]

[/body] [/html]

in this case the printer will print only your text...

Fabio Beoni