SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Printing in .NET


Printing in .NET

Author
Message
saeed-254117
saeed-254117
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 12
Thanks for your nice code and idea.
jereme.guenther@gmail.com
jereme.guenther@gmail.com
SSC Eights!
SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)

Group: General Forum Members
Points: 973 Visits: 194
No problem, it is a start. Let us know if you develop any new cool addons or if you clean it up a bit.
saeed-254117
saeed-254117
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 12
Hi,
I have two request:
1 ) Could you explain me more about the following comment you have already explained and let me know which line should be repleaced. ( The message below the star line)

2) I would like to print the characters from right to left because of my native language ( arabic ), could you please give me a hand to solve it.
thanks in advance
***********************************************
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
SSC Eights!
SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)

Group: General Forum Members
Points: 973 Visits: 194

Sure saeed,

1) If you will look at the code in the article you can use the following exerpt to identify the correct location for changing the code. The code you quoted is what you are suppose to change it to.
' See if any characters will fit.
If characters_fitted > 0 Then
' start accumulating the print location
varWord(varWord.GetUpperBound(0) - 1) = layout_rect

' ************Draw the word when finished.************
...
'' Draw a rectangle around the text (for debugging).
...
' Increase the location where we can start.
xmin += CInt(text_size.Width) - 4
ReDim Preserve varWord(varWord.GetUpperBound(0) + 1)
ElseIf Asc(smallArray(0, x).Chars(0)) < 30 Then ' make sure to dispose of odd char's in the array

2) I assume from your post that you also read right to left so you need the entire printing process reversed. This is much simpler than reading left to right but printing right to left. I haven't actually tested this but the solution should be as simple as replacing the red code with the green:
' ************Draw the word when finished.************
If Asc(smallArray(0, x).Chars(0)) = 32 Or x = smallArray.GetUpperBound(1) - 1 Then
Dim z As Integer
For z = x - (varWord.GetUpperBound(0) - 1) To x
' Get the font for measurement.
the_font = New Font(fntPrintFont.Name, fntPrintFont.Size, CInt(smallArray(1, z)), fntPrintFont.Unit)
' actually print the character on the page.
e.Graphics.DrawString(smallArray(0, z), _
the_font, Brushes.Black, _
varWord((z - x) + (varWord.GetUpperBound(0) - 1)), string_format)


' ************Draw the word when finished.************
If Asc(smallArray(0, x).Chars(0)) = 32 Or x = smallArray.GetUpperBound(1) - 1 Then
Dim z As Integer
For z = x - (varWord.GetUpperBound(0) - 1) To x
' Get the font for measurement.
the_font = New Font(fntPrintFont.Name, fntPrintFont.Size, CInt(smallArray(1, z)), fntPrintFont.Unit)
' actually print the character on the page.
e.Graphics.DrawString(smallArray(0, z), _
the_font, Brushes.Black, _
e.MarginBounds.Right - varWord((z - x) + (varWord.GetUpperBound(0) - 1)), string_format)

One thing that does have me confused though. If your native language reads right to left then why isn't the input string being put in right to left which would cause it to be printed out correctly?


Colin Hobby
Colin Hobby
SSC Rookie
SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)

Group: General Forum Members
Points: 28 Visits: 3

How can I make certain lines of text italics, i am using this class in a WinForm, and it works really great as far as the actual printing goes. But I dont know how to format the text. for example If I want to have a Headline in a bigger font, do I instantiate another myPrintObject ?


jereme.guenther@gmail.com
jereme.guenther@gmail.com
SSC Eights!
SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)

Group: General Forum Members
Points: 973 Visits: 194

Text formatting is taken care of in the checkBold method. I know the name doesn't really fit it, but that is what happens when you are a little green when writting the code and don't properly plan it.

For italics you would add something like this (not tested):
ElseIf Mid(varString, varPlace, 3) = "<I>" Then
printStyle = FontStyle.Italic
varPlace += 2
ElseIf Mid(varString, varPlace, 4) = "</I>" Then
printStyle = FontStyle.Regular
varPlace += 3

The font size would be taken care of in the same place. I would use a tag such as <SIZE=?> </SIZE>. A change like this will require you to understand the code fairly well and make a few changes to the main print method to implement it.

Unfortunately, the project this code belongs to has been put on hold for awhile so I have been unable to complete it.


Colin Hobby
Colin Hobby
SSC Rookie
SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)

Group: General Forum Members
Points: 28 Visits: 3

Jereme,
Thanks for the italics code, I added it to the checkbold method, and it does print italics, however it does not print every letter in the string. It skips the first 2 char, prints the 3rd,skips the 4th,prints the 5th and 6th, skips 7th, print 8th,skip 9th. prints 10, skips 11, prints 12, skips 13,prints 14,skips 15+16, prints 17-21, skips 22 prints 22-25 etc..


jereme.guenther@gmail.com
jereme.guenther@gmail.com
SSC Eights!
SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)

Group: General Forum Members
Points: 973 Visits: 194

What is the string that you are trying to print? I mean the full string including the formatting tags like <I>.

What do you mean by "not printing every letter"? Is it not printing the actual character, or is it simply printing the character without italics?


kmsultan
kmsultan
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 1

Jereme,

Thanks for the great effort. I tried your code, and it works. My problem however is that I'm trying to print an HTML document in .net programmatically! I've tried a few tutorials, but they all seem to be centered around sending text to the printer.

Have you come across examples where html docs can be sent to the printer easily? I'm sure there must be an easy way, but I haven't come across it yet.

By the way, I tried to read my html as a string, and then use your class to print it, however all I got to print was the actual html code and not the rendered html document.

Appreciate your help.


jereme.guenther@gmail.com
jereme.guenther@gmail.com
SSC Eights!
SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)

Group: General Forum Members
Points: 973 Visits: 194

Hey kmsultan, I am a little confused about the question. If you are the one creating the webpage which needs to be printed then you should have the data itself and can properly format it another way. If you are going for clientside printing you can use the javascript print feature, which will have the user select a printer to print to.

If you really need to print using the HTML code itself then you will probubly need to look at using an HTML parsing engine like gecko (which firefox uses). I have never attempted that before and would seriously look at your options before starting something this major.

Jereme


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