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?
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 ?
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.
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..
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?
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.
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.