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 Thursday, June 22, 2006 4:52 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, March 2, 2009 8:35 AM
Points: 2, Visits: 12
Thanks for your nice code and idea.
Post #289294
Posted Thursday, June 22, 2006 11:48 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 5, 2014 8:30 AM
Points: 769, Visits: 191
No problem, it is a start.  Let us know if you develop any new cool addons or if you clean it up a bit.
Post #289440
Posted Saturday, June 24, 2006 12:39 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, March 2, 2009 8:35 AM
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).
**********************************************************







Post #289905
Posted Monday, June 26, 2006 11:02 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 5, 2014 8:30 AM
Points: 769, Visits: 191

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?

Post #290141
Posted Friday, November 10, 2006 1:33 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, November 23, 2010 4:07 PM
Points: 10, 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 ?

Post #322083
Posted Friday, November 10, 2006 1:55 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 5, 2014 8:30 AM
Points: 769, Visits: 191

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.

Post #322088
Posted Monday, November 13, 2006 9:04 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, November 23, 2010 4:07 PM
Points: 10, 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..

   

Post #322350
Posted Monday, November 13, 2006 12:44 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 5, 2014 8:30 AM
Points: 769, Visits: 191

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?

Post #322401
Posted Wednesday, November 15, 2006 10:51 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, December 18, 2006 10:13 AM
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.

 

Post #323165
Posted Wednesday, November 15, 2006 11:54 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 5, 2014 8:30 AM
Points: 769, Visits: 191

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

Post #323206
« Prev Topic | Next Topic »

Add to briefcase «««1234»»

Permissions Expand / Collapse