New topic: Sending text from a TextArea object to a Printer
<http://forums.realsoftware.com/viewtopic.php?t=45975> Page 1 of 1 [ 2 posts ] Previous topic | Next topic Author Message Stuart J Sykes Post subject: Sending text from a TextArea object to a PrinterPosted: Sun Nov 18, 2012 6:45 pm Joined: Fri Oct 26, 2012 6:24 am Posts: 14 I'm using this bit of code on a button for printing the contents of a TextArea1.Text object: Dim g as Graphics Dim p as PrinterSetup p=New PrinterSetup If p.PageSetupDialog then g=OpenPrinterDialog(p) If g<> Nil then g.TextSize = 10 g.TextFont = "System" g.DrawString TextArea1.Text, 18,20 End If End if It works ok as long as there's not more than a page (A4) of text stored in TextArea1.Text How do I get it to print out multiple pages Thanks in advance Top DaveS Post subject: Re: Sending text from a TextArea object to a PrinterPosted: Sun Nov 18, 2012 8:51 pm Joined: Sun Aug 05, 2007 10:46 am Posts: 4264 Location: San Diego, CA Let me check..... I believe I have a routine to do just that.... but you have to convert the TEXTAREA to STYLEDTEXT (not that you have to use colors etc.) but this is what my code requires (as the project I wrote it for DOES have colors, bold etc). G is the printer graphic area ST is the styled text XPOS,YPOS is where to start printing (0,0)=top of page wdth,hght is dimensions of desired print area (if you only want part of the page) force_fontsize (leave ZERO to use fontsize in styled text, otherwise will use what size you specifiy) measuer_only set to true if you just want to know how tall the print area will be I am going to leave it to you to play with it and get it to work in your project. FUNCTION Output_Styled_Text(g As graphics, st As StyledText, xpos As Integer, ypos As Integer, wdth As Integer, hght As Integer, force_fontsize As Integer = 0, measure_only As boolean = false) as integer Dim xleft As Integer Dim yTop As Integer Dim i As Integer Dim j As Integer Dim k As Integer Dim s As String Dim t As String Dim eol As Boolean Dim eol2 As Boolean Dim xx As Integer Dim v(-1) As String Dim has_eol As Boolean Dim flag As Boolean Dim h As Integer xleft=xpos yTop=ypos For j=0 To st.StyleRunCount-1 g.textfont=st.StyleRun(j).Font g.bold=st.StyleRun(j).Bold g.italic=st.StyleRun(j).Italic g.ForeColor=st.StyleRun(j).TextColor g.underline=st.StyleRun(j).Underline If force_fontsize=0 Then g.TextSize=st.StyleRun(j).Size Else g.textsize=force_fontsize End If s=st.StyleRun(j).Text t=ReplaceLineEndings(s,EndOfLine.unix) v=Split(t,EndOfLine.UNIX) has_eol=Right(t,1)=EndOfLine.UNIX has_eol=false s=t For k=0 To v.Ubound s=v(k) flag=True eol=(k<v.ubound Or has_eol) While s<>"" Or flag flag=False // xx=0 If xpos+g.StringWidth(s)>xleft+wdth Then For i=1 To Len(s) If InStr(" ,:;.?/\|",Mid(s,i,1))>0 Then ' found a breaking point If xpos+g.StringWidth(Left(s,i))<=xleft+wdth Then xx=i End If Next i If xx>0 Then t=Left(s,xx) s=Mid(s,xx+1) Else xx=-1 eol2=True End If Else t=s s="" xx=1 End If If xx>0 Then If Not measure_only Then //t=t+str(eol)+str(eol2)+":"+str(v.Ubound)+"/"+str(j) g.DrawString t,xpos,ypos End If xpos=xpos+g.StringWidth(t) h=ypos End If If eol Or eol2 Then ypos=ypos+g.TextHeight xpos=xleft eol2=False End If If ypos+g.textheight>ytop+hght Then Exit For ' clip the rest of the text Wend Next k If ypos+g.textheight>ytop+hght Then Exit For ' clip the rest of the text Next j Return h-yTop-g.TextHeight END FUNCTION _________________ Dave Sisemore MacPro, OSX Lion 10.7.4 RB2012r1 Note : I am not interested in any solutions that involve custom Plug-ins of any kind Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 2 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
