Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««1234»»»

Printing in .NET Expand / Collapse
Author
Message
Posted Wednesday, March 01, 2006 7:05 PM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Wednesday, February 05, 2014 8:30 AM
Points: 769, Visits: 191

Hi Min and jkli,

  I always like helping others out.  I have received enough support throughout my life that I like handing out some assistance myself every once in a while.

Post #262561
Posted Thursday, March 02, 2006 10:43 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, April 07, 2011 9:14 PM
Points: 10, Visits: 22

Hi Jereme

Thanks for the update for my printing.

Thanks again for your contirbution!

Howard

Post #262997
Posted Friday, March 03, 2006 5:22 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, January 30, 2014 10:08 PM
Points: 1,038, Visits: 444

Nice to see a wide variety of articles on the site

Having said that, two comments.

1. The comment earlier about "no default printer" when the user had a network printer - if ASP.NET is running under a service account it will not have network printers already established - only local printers (LPT, USB, TCP, LPR, etc) printers are, by default, available to service apps.  You'll need to do one of the following

a) call the windows API to connect to a network printer when your app starts
b) change the printer to print to LPTx and then issue a NET USE LPTx: \\computer\printer when your app starts
c) run the service under a user account that you have logged on to and set up some printers
d) Install the "Print services for Unix" on the computer that is hosting the printer (and then set the service to automatically start!) - you can then set up a TCP printer port printing to that computer - the wizard for this part will say that it cannot detect the type of network card for the printer - don't worry, choose generic   Then configure the port, change it to LPR and enter in the printer's share name.  Then the printer will be a local printer rather than a network printer and it will be available to all users on the machine - including service accounts

The above has come in very useful when configuring terminal server environments - ensuring all users get all printers without messy scripts and ensuring that permissions on printers and PCs not in the domain do not get in the way (TCP printers don't have any permissions - no shared print queue).

Second point....  hahahaha
I'm not a big .NET programmer but know my way around C# pretty well (I use delphi 99% of the time) - If I had a similar requirement I would probably format my text using RTF and print it using the RichText control?  If I needed HTML syntax then I guess I could spawn explorer - wouldn't this be a lot easier???

Full marks though for sharing the code and working out the nitty gritty stuff!




Post #263035
Posted Friday, March 03, 2006 10:19 AM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Wednesday, February 05, 2014 8:30 AM
Points: 769, Visits: 191

Hi Ian, thanks for your comments they really add value to this thread.  You have some idea's in there which I didn't think of.

As far as setting up the printers to the asp.net account can use them, I used an account with administrative rights (not the asp.net domain service account) and set up the printers and asp.net was able to see them fine.  This is on a Windows 2000 box, other OS's might not respond so well.  After reading your post I am not sure why my method works, I will have to think on that some more.

I tried spawning an Internet Explorer window, if that is what you are referring to, but it had a few major formatting problems.  In particular, it would cut of the right hand side of the text when it was formatted with a table.  There were a few other security problems and annoyances as well which caused me to dump the idea.

As to using the RichText control, that is a great idea.  I didn't know that asp.net had a native RichText control.  Don't forget that I am working in a web environment with this code.  If it was a simple vb.net application I can think of many better ways for printing nicely formatted text but when I am dealing with web pages which need to print on the server, not client, side I was unable to think of a better solution.  If you know of a way to use a native (or free) RichText control for printing text, where you can control the color of each character, on the server side then please share.

Post #263176
Posted Friday, March 03, 2006 9:47 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, January 30, 2014 10:08 PM
Points: 1,038, Visits: 444

Hi.

I believe there would be an ActiveX control that you could spawn hidden (needn't have a parent window) - The RTF control is standard with Windows.  I have used it in a windowless environment to do similar printing - but I haven't tried using it from .NET though...

As for the printers for the ASP.NET account - are they network printers or local printers attached to the machine or "local printers" in that they are printing to a local printer port but happen to be on the network?

Cheers!




Post #263286
Posted Saturday, March 04, 2006 5:26 PM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Wednesday, February 05, 2014 8:30 AM
Points: 769, Visits: 191

I will be a little annoyed with myself if the RichText box idea proves to work in a webpage environment.  That was a lot of work if something better already exists

The printers I use print to local ports which are UNC paths to the print server.  The print server then sends the job off to the IP port.

Post #263313
Posted Sunday, March 05, 2006 9:48 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, January 30, 2014 10:08 PM
Points: 1,038, Visits: 444

Well part of me hopes it works and part now doesn't hahaha - in any case, it sounds like you had a good time developing




Post #263357
Posted Monday, March 06, 2006 10:30 AM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Wednesday, February 05, 2014 8:30 AM
Points: 769, Visits: 191
Hey, all of me hopes it works.  True i did have fun with it but my code is far from perfect.
Post #263554
Posted Saturday, May 20, 2006 11:43 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, January 19, 2009 6:24 AM
Points: 1, Visits: 10
Hi!

This is one of the very rare GOOD code samples for printing I've come accross - good work!!

But, I have problems modifying the code.... for example, if I want to add alignment option to the paragraph (center or justified), it looks nearly imposible to insert into code

Do you have any ideas how can this be done?

Thanks!
Post #281583
Posted Monday, May 22, 2006 10:30 AM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Wednesday, February 05, 2014 8:30 AM
Points: 769, Visits: 191

Hi Veljko,
  Bummer by first reply got erased.  Oh well here goes again.  I like your idea, it is a good challenge and one which I didn't think of at the time of development.

For reference e is being passed as (ByVal e As Printing.PrintPageEventArgs)

What I would suggest trying is finding the width of the printable area using something like:
e.MarginBounds.Width
Then you will have to find the width of the string you are printing by collecting the entire string instead of merely one word.  Use the width of the collected string and the width of the printable area to calculate the new starting location.  Once you have that you can print out the string.

Remember:
If you want to keep the character level formatting then you will still have to loop through the collected string printing one character at a time.
Also, don't forget that you can't measure the entire collected string to find out the string width because of the character level formatting.  Instead you will have to collect the widths of each character as you gather the string, then use the some of these widths as your total string width.

Hope this helps,
Jereme

Post #281837
« Prev Topic | Next Topic »

Add to briefcase ««1234»»»

Permissions Expand / Collapse