Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Printing in .NET


Printing in .NET

Author
Message
jereme.guenther@gmail.com
jereme.guenther@gmail.com
Right there with Babe
Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)

Group: General Forum Members
Points: 787 Visits: 194
Comments posted to this topic are about the content posted at http://www.sqlservercentral.com/columnists/jGuenther/printinginnet.asp
jereme.guenther@gmail.com
jereme.guenther@gmail.com
Right there with Babe
Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)

Group: General Forum Members
Points: 787 Visits: 194
I have noticed a major flaw in this code. It prints great when using the Tahoma font, but anything else seems to really mess it up.
jereme.guenther@gmail.com
jereme.guenther@gmail.com
Right there with Babe
Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)

Group: General Forum Members
Points: 787 Visits: 194

Ok, I have found the problem. Apparently Microsoft has a bug in their e.Graphics.MeasureString function. To remidy this re-organize the primary if block like this:

If Asc(smallArray(0, x).Chars(0)) < 30 Then ' make sure to dispose of odd char's in the array

' See if any characters will fit.

ElseIf characters_fitted > 0 And xmin < (e.MarginBounds.Right - 5) Then

Notice that I switched the if and elseif lines, that is because I was occasionally printing out a graphical representation for the char(0).


jereme.guenther@gmail.com
jereme.guenther@gmail.com
Right there with Babe
Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)

Group: General Forum Members
Points: 787 Visits: 194

Another update, I have perfected the variable character spacing problem when the font size and type changed. Add the following line somewhere above The 'Static i As Integer' line:

' Prepare the fixed spacing for each character
Dim fixedSpace As SizeF = e.Graphics.MeasureString("W", the_font)

Then replace the following line:
' Increase the location where we can start.
xmin += CInt(text_size.Width) - 4

with:
' Increase the location where we can start.
xmin += CInt(text_size.Width) - (fixedSpace.Width * 0.25)


ALZDBA
ALZDBA
SSCrazy Eights
SSCrazy Eights (8.1K reputation)SSCrazy Eights (8.1K reputation)SSCrazy Eights (8.1K reputation)SSCrazy Eights (8.1K reputation)SSCrazy Eights (8.1K reputation)SSCrazy Eights (8.1K reputation)SSCrazy Eights (8.1K reputation)SSCrazy Eights (8.1K reputation)

Group: General Forum Members
Points: 8125 Visits: 8849
Do you know of a simple way of making a screen-shot (winforms) with .Net code, using the framework (not extra referring to the gdi32.dll ) ?

Johan


Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere w00t

- How to post Performance Problems
- How to post data/code to get the best help


- How to prevent a sore throat after hours of presenting ppt ?


press F1 for solution, press shift+F1 for urgent solution :-D


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me Alien but most of the time this is me Hehe
Howard Rybko
Howard Rybko
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

Group: General Forum Members
Points: 14 Visits: 22

Hi Jereme

Thanks for this nice piece of work!

I have tried to get it to work in ASP.NET 1.1 (vb) but get a run time error "No printers installed."

I do have a deault printer but it is a network printer and not on LPT1.

Any ideas?

Many Thanks

Howard Rybko


jereme.guenther@gmail.com
jereme.guenther@gmail.com
Right there with Babe
Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)

Group: General Forum Members
Points: 787 Visits: 194
Hi Howard, that is my fault for not giving you all the code to properly initialize the class. Try the following:

' Create object, passing in text
Dim MyPrintObject As New TextPrint("<B>this will be bold</B>" + vbCrLf + "<ST=400>this will start at 400 pixels", "MyPrinterName")

Also modify the printing class itself to accept two parameters:

' New constructor
Public Sub New(ByVal Text As String, ByVal pName As String)
' Sets the file stream
MyBase.New()
varStart = 0
strText = Text
MyBase.PrinterSettings.PrinterName = pName ' This is the key line for setting the printer
MySplitLine = strText.Split(vbCrLf)
End Sub

I too use exclusively network printers not local LPT1 ports.


jereme.guenther@gmail.com
jereme.guenther@gmail.com
Right there with Babe
Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)

Group: General Forum Members
Points: 787 Visits: 194

Hi alzdba,

I have never tried taking a screen shot in .net. Here is a link on how to do it but I does appear that you will need to use API functions.

http://www.developerfusion.co.uk/show/4630/


Min-263369
Min-263369
Forum Newbie
Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)

Group: General Forum Members
Points: 8 Visits: 1
I've not tried your code, but I just want to say thank you for sharing your hardwork with everyone. It's very generous of you.
jkli
jkli
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
Points: 12 Visits: 12
Thanks for sharing. It is very generous of you.



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search