39 Replies - 1310 Views - Last Post: 04 February 2012 - 09:17 AM
Topic Sponsor:
#31
Re: printing from textbox
Posted 30 January 2012 - 07:42 AM
i tried and it did not work well
#32
Re: printing from textbox
Posted 30 January 2012 - 08:07 AM
#33
Re: printing from textbox
Posted 30 January 2012 - 09:33 AM
at times either the text go off page (happeneds with the code i wrote too) or it cut few letters from some words and sometimes in print only the last line in my text but each letter in different line
#34
Re: printing from textbox
Posted 30 January 2012 - 10:51 AM
OK, you describing different problems there.
The code I wrote was to split your text into the array lines, based on a constant of how wide you wanted the line. That code did work and split according to your requirements.
What you're describing there sounds like a slightly different problem.
One question...
When you have the text going off the page, did you check the array lines held the data you expected (i.e. if each was to be 20 character, where they 20 characters). In other words, is the splitting function working correctly?
A couple of things to think about.
1. Are you using TrueType fonts or Fixed Fonts? If you're using true type fonts, then I would expect that this could happen because of the way the fonts are spaced, so certain letters are "wider" than others. That being the case, your splitting of the lines, won't work as you expect. You could try it with a fixed font (Courier for example) and see if that makes a difference (which I think it would), but that might not be what you want.
I'm sure I've seen examples of printing text accurately using VB6, so I'll have a dig around and see if anything comes up.
[EDIT] I've found a pretty good tutorial on printing in VB here. It also links to an option for printing from a RichTextBox, so that it handles the wordwrapping automatically for you including margins. The direct link for that code is here.)
The code I wrote was to split your text into the array lines, based on a constant of how wide you wanted the line. That code did work and split according to your requirements.
What you're describing there sounds like a slightly different problem.
One question...
When you have the text going off the page, did you check the array lines held the data you expected (i.e. if each was to be 20 character, where they 20 characters). In other words, is the splitting function working correctly?
A couple of things to think about.
1. Are you using TrueType fonts or Fixed Fonts? If you're using true type fonts, then I would expect that this could happen because of the way the fonts are spaced, so certain letters are "wider" than others. That being the case, your splitting of the lines, won't work as you expect. You could try it with a fixed font (Courier for example) and see if that makes a difference (which I think it would), but that might not be what you want.
I'm sure I've seen examples of printing text accurately using VB6, so I'll have a dig around and see if anything comes up.
[EDIT] I've found a pretty good tutorial on printing in VB here. It also links to an option for printing from a RichTextBox, so that it handles the wordwrapping automatically for you including margins. The direct link for that code is here.)
This post has been edited by maj3091: 30 January 2012 - 11:09 AM
#35
Re: printing from textbox
Posted 31 January 2012 - 01:18 PM
already know this tutorial and it didnt helped much.. but also i didnt check the fonttype
i just left it as it is... so i guess it was set to the type textboxes come with
#36
Re: printing from textbox
Posted 01 February 2012 - 03:44 PM
so these should be my targets right?
-i should set the font type to courier so all letters will be the same size and then splitting them by a fixed size i want.
-and then i need a code that prevent from splitting in the middle of a word.
-also a counter to know how many lines fit inside a page and start a new page if needed.
now how i can print a line in about 0.5cm from the page beggining and 0.5cm from page end?
and if needed how i can start printing from the right side of the page?
-i should set the font type to courier so all letters will be the same size and then splitting them by a fixed size i want.
-and then i need a code that prevent from splitting in the middle of a word.
-also a counter to know how many lines fit inside a page and start a new page if needed.
now how i can print a line in about 0.5cm from the page beggining and 0.5cm from page end?
and if needed how i can start printing from the right side of the page?
#37
Re: printing from textbox
Posted 01 February 2012 - 04:13 PM
By using Printer.CurrentX and Printer.CurrentY you can position your text anywhere on the page
I still think my original code for breaking up lines of text would work best, it just needs some tweaking. Then you wouldn't need to worry about your font because textwidth would take care of the line length.
I still think my original code for breaking up lines of text would work best, it just needs some tweaking. Then you wouldn't need to worry about your font because textwidth would take care of the line length.
#38
Re: printing from textbox
Posted 03 February 2012 - 06:08 AM
so after i set the scale mode lets say to cm then if CorrectX = 1 then it mean 1 cm?
also abit of help with the tweaking to the splitting code
in the end i'd like it to be on dll file to make things easier
also abit of help with the tweaking to the splitting code
in the end i'd like it to be on dll file to make things easier
This post has been edited by Neku: 03 February 2012 - 08:42 AM
#39
Re: printing from textbox
Posted 03 February 2012 - 04:38 PM
Here's a bit of code I knocked up this morning.
Essentially it churns through the text and prints each line as it goes.
It also takes into account any carriage returns and line feeds.
Essentially it churns through the text and prints each line as it goes.
It also takes into account any carriage returns and line feeds.
Public Sub Print_Text()
Dim lineToPrint As String
Dim nextWord As String
Dim textRemaining As String
Dim aschar As Integer
Dim countChars As Integer
Dim widthText As Single
Printer.ScaleMode = 6 'set scalemode to mm
Printer.CurrentY = 20 'start printing 20mm from top of page
textRemaining = Text1.text 'get text to print from text box
Do
Do
countChars = countChars + 1
If countChars > Len(textRemaining) Then Exit Do 'reached end of text
aschar = Asc(Mid$(textRemaining, countChars, 1))
Select Case aschar 'decide what to do depending on ascii value of character
Case 13
lineToPrint = lineToPrint & nextWord
textRemaining = Replace(textRemaining, nextWord & Chr(13) & Chr(10), "", 1, 1)
Printer.CurrentX = 15
Printer.Print lineToPrint
lineToPrint = ""
nextWord = ""
countChars = 0
If textRemaining = "" Then
Printer.CurrentX = 15
Printer.Print lineToPrint
Printer.EndDoc
Exit Sub
End If
Exit Do
Case 32
nextWord = nextWord & Mid$(textRemaining, countChars, 1)
Exit Do
Case Else
nextWord = nextWord & Mid$(textRemaining, countChars, 1)
End Select
Loop
widthText = Printer.TextWidth(lineToPrint & nextWord)
If widthText <> 0 Then
If widthText < 150 Then 'add word to linetoprint if it will be less that 150mm wide
lineToPrint = lineToPrint & nextWord
textRemaining = Replace(textRemaining, nextWord, "", 1, 1)
If textRemaining = "" Then
Printer.CurrentX = 15
Printer.Print lineToPrint
Exit Do
End If
nextWord = ""
countChars = 0
Else
Printer.CurrentX = 15
Printer.Print lineToPrint
lineToPrint = nextWord
textRemaining = Replace(textRemaining, nextWord, "", 1, 1)
nextWord = ""
countChars = 0
End If
End If
Loop
Printer.EndDoc
End Sub
#40
Re: printing from textbox
Posted 04 February 2012 - 09:17 AM
wow this code work perfectly!
via cutePDF it seems to handle extra pages too, does it do that also if i print to normal page? i did not find any line that start new page.
you defently gonna get credits for this!
all this site actually
you guys rock! 
now all is left is to make the title in the middle of the line xD
i guess i can do that
solved title problem xD
it does also handle extra pages! yay
great job! thank you very much!
you defently gonna get credits for this!
all this site actually
i guess i can do that
solved title problem xD
it does also handle extra pages! yay
great job! thank you very much!
This post has been edited by Neku: 04 February 2012 - 09:36 AM
|
|

New Topic/Question
Reply




MultiQuote






|