Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print a web page from Code

Status
Not open for further replies.

MaryNET

Programmer
Jan 6, 2007
33
US
Is it possible to send a web page (or a printable stylesheet in my case)
to the printer from code?
This is all on one .aspx page with no code behind.

I have this loop that sends each Invoice to the screen, one by one, but not printer:
<script runat="server">
while (dr.Read())
{
OrderRepeater.DataSource = GetOrders(Convert.ToInt32(dr["OrderID"]));
OrderRepeater.DataBind();
******** NEED SOME WAY TO PRINT EACH INVOICE HERE *************
}

The part that I want printed has no <html> or <body> tags:

</script>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="Server">
.....
all the content of the printable stylesheet
.....
<script language="javascript"> <<< added
window.print();
</script>
</asp:Content>

I added the window.print() at the bottom but it only prints the last Invoice
that was on the screen from loop.
This button in the above code prints the Invoice:
<asp:Button ID="Print" runat="server" Text="Print" OnClientClick="window.print();return false;" />

I know you can't call Client scripts (like window.print()) because of security reasons.
Is there a third party or ActiveX control that will let me print to the printer from code?
Any ideas appreciated. Thanks
 
your mixing technologies/concepts. web pages (aspx) produce html. the browser will read the entire stream as the webpage and display in the browser.

printing an invoice is a reporting functionality. this is better suited for a reporting engine. Crystal, MS Reporting Services, or another 3rd party reporting framework is better suited for this functionality.

there may be a webforms control adapter to assist with the displaying the report on a webpage, but that is independent of the report itself.

My systems use Crystal Reports for .Net to produce a pdf file. I then send the PDF to the browser and let the browser handle the rest. there are examples of this on the web.

if you continue in your current direction you will be using the technology in a very cumbersome way. it's like driving a nail with a screwdriver.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
thanks,
I'm trying to adapt a system that I didn't built.
I have used Crystal in the past to print Invoices, but
if I could get this work-around it would save a lot of
potential problems later.
 
if I could get this work-around it would save a lot of
potential problems later.
how would this reduce problems? I can only envision it creating problems.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Because this system has a lot of tables related to the Orders table and if I try and create a Crytal report by using the fields from those tables I'm probably going to miss something down the line.

The way they have it now is that you can print a range of Invoices at once but all the Invoices in that range appear in the brower, the you click "Print" to print them.

I will need to print over a 100 invoices and this might crash the browser, .. so I was hoping to print them individually at each loop.
 
Because this system has a lot of tables related to the Orders table and if I try and create a Crytal report by using the fields from those tables I'm probably going to miss something down the line.
you already have the query here [tt]GetOrders(Convert.ToInt32(dr["OrderID"]));[/tt] from there is a matter of populating a DataSet and passing that to a Crystal report. no need to recreate the queries.
I will need to print over a 100 invoices and this might crash the browser, .. so I was hoping to print them individually at each loop.
the looping (rendering html) occurs on the server, the printing would happen on the client. so this idea will not work.

the "reduction of problems" only applies to your current situation. in the future new requirements will most likely come. when that happens it may impact printing invoices. in which case you, or someone else, will need to remember that the invoice printing was hacked together with a work around. This will only create problems. Better to invest the time now to do it correctly.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top