Page 1 of 1

Chart Printing from Web Page

Posted: Tue Apr 26, 2011 6:54 pm
by 9639571
I am trying to add a print function to my ASP.NET web page. I have added the asp.net button control and am able to print from the command below. The problem I am having is, that this sends the print job to the default printer of the server, not the client machine. We have various offices off site that are trying to print these charts, but they always come out at the printer located in the main office. How can I activate the print dialog box, to allow the client to select a local printer?


ORDSHPPERDAYCHART.Chart.Printer.Landscape = True
ORDSHPPERDAYCHART.Chart.Printer.Print()

Re: Chart Printing from Web Page

Posted: Wed Apr 27, 2011 9:19 am
by 10050769
Hello phil1995,

I recommend that use PrintPreview of Chart that allowed select the printer that you want as do in next lines of code:

Code: Select all

    protected void Button1_Click(object sender, EventArgs e)
    {
        WebChart1.Chart.Printer.Preview();
    }
Could you tell us if previous code works as you expect?

I hope will helps.

Thanks,

Re: Chart Printing from Web Page

Posted: Wed Apr 27, 2011 12:46 pm
by 9639571
I had already tried the code you provided. It works when I am testing on my local machine, but just prints to the server default printer (same as the .print) when it is published to the server.

I may be wrong, but I do not believe that the print preview will work on an asp.net web site.

Somehow, the print needs to occur on the client side, instead of the server side.

I can print the entire page with a bit of Java Script, but am not able to print the individual charts.

Re: Chart Printing from Web Page

Posted: Thu Apr 28, 2011 10:54 am
by 10050769
Hello phil1995,

When you use TeeChart.Net to asp.net and you create a Chart it is generated as image in the server so print Chart is not depending only of TeeChart methods because if you want that all user printing chart of your web, you only can print Chart with default print menu of browser or using different ways to print images of WebSide. You can take a look in this thread to find an example:
http://www.teechart.net/support/viewtop ... art#p31615
And also I have find many webs where explains how print image of web that I think can help you:
http://stackoverflow.com/questions/5692 ... sp-net-mvc
http://forums.asp.net/p/1463001/3369521.aspx
http://www.atalasoft.com/docs/dotimage/ ... mages.html

Thanks,

Re: Chart Printing from Web Page

Posted: Wed May 04, 2011 6:34 pm
by 9639571
I have a page with approximatley 5 charts on the ASP.NET web page. What I am trying to accomplish, is for the user to be able to press a print button beside a specific chart, and send that chart to the printer.

All of the suggestions offered so far, revolve around sending a print job for the entire web page. In my case, this would print the page and all 5 charts.

Is there a way to imitate the chart.print feature on an ASP.NET web page that will just send the individual chart to the print job?

As indicated earlier, this works just as expected, but will only send the print job to the default printer of the server (sometimes in a different country). I need to send it to the default printer of the client machine.

Re: Chart Printing from Web Page

Posted: Thu May 05, 2011 2:32 pm
by 10050769
Hello phil1995,

Sorry, I think I haven't explained well. I recommend you that take a look again in previous links where explain how you do to take an image, in this case WebChart, with Javascript and after print it. I think that it is the best way as you have now to print image in browsers.

Thanks,

Re: Chart Printing from Web Page

Posted: Thu May 05, 2011 2:56 pm
by 9639571
I also think I am not being clear about what I am after.

When using the methods from above, the print will come from a web page. This does not provide the quality of print I need. When I use the chart.printer.print, I get a high quality print, that is full page, and formatted slightly different (better) than the chart is displayed on the page. This is the quality of print I need. When I try to print directly from the web page, the chart is about 1/4 size, the quality is bad, there are headers and footers on the page and the orientation is wrong.


Is there a way to redirect the output of the chart.printer.print to a file so that I may pick that up with my Javascript? I know I can output the charts at time of creation, but seems like it would work better if I could somehow print to a file. That is of course, if there is no way to get it to go directly to the client printer.

Any suggestions?

Re: Chart Printing from Web Page

Posted: Fri May 06, 2011 2:49 pm
by 10050769
Hello phil1995,

Ok. I suggest that If you have remote printers available in a list at the server you could select them accordingly, or offer the client the possibility to select a printer from the list before printing via a button on the page.

eg.

Code: Select all

    protected void Button1_Click(object sender, EventArgs e)
    {
      foreach (string pstr in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
      {
        if (pstr == "\\\\YOURSERVER\\Your LaserInkjetEtcPrinter")  //check for your printername
        {
          WebChart1.Chart.Printer.PrintDocument.PrinterSettings.PrinterName = pstr;
          WebChart1.Chart.Printer.BeginPrint();
          WebChart1.Chart.Printer.Print(new Rectangle(0,0,400,300));  //need to size Chart
          WebChart1.Chart.Printer.EndPrint();
        }
      }

On the other hand, if you don't have access to remote printers and wish to save the Chart as an image file you could do that in this way, even returning the name of the file to the browser so that a clientside javascript process/button print it.

eg.

Code: Select all

protected void Button1_Click(object sender, EventArgs e)
    {
        //save chart
        WebChart1.Chart.Export.Image.JPEG.Save(@"C:\_server_temp_folder\myCodedChartName.jpg");

        //set a variable (here simply a label) on the page with the correct url to the file.
        Label3.Text = "http://myserver.mydomain.com/_server_temp_folder/myCodedChartName.jpg";

      }

Then you can write your own pageside javascript routine to output the image to a local printer.

Thanks,