Why oh Why can we not print text as text and not have to thru the rigamarole of using graphics to print some text.
Have sorted the printing using graphics but works on my printer but comes out wrong on my mates printer, I did this as a test and his printer does not recognise the spacing and puts the text bunched up in the top left corner of the page.
Just a simple print command as in the old basic would be nice.
Look like I will have find a different language to do the job for my mate.
We are both using windows 11 but different printers.
His is epsom my is canon and the only question is why force us to graphics when simple printing command would do.
I have writtten a print rountine but it seems you have to make allowances for all printers and how you do that I do not know.
To be Honest have been at it for to long and will just write it to text file and print it from a text editor.
âŠwhich will then send it as a graphic to the printer, the same as Xojo does.
Its been a long time since it was easy to chuck chr(65) down a pipe to LPT1: or CON1: and get an output that way.
Printing text isnât massively hard, so if anyone else finds this post and finds printing text hard, there is an example project with Xojo called âPrinting Textâ
what it contains is like this (amended here to remove reliance on screen controls):
//added by me
Var OurText as string
OurText = "whatever text you want to print. This can be long and contain endofline chars"
//added by me
Var ps As New PrinterSetup
If ps.ShowPageSetupDialog Then
Var page As Graphics
page = OpenPrinterDialog(ps)
If page <> Nil Then
' Draw text on page 1 with 1 inch left/top margin
Var leftMargin As Double = ps.HorizontalResolution
Var topMargin As Double = ps.VerticalResolution
page.FontSize = 12 // bigger = bigger letters
' To print multiple pages, you need to parse each line and print it
' if it will fit on the page. If it will not fit, then
' you call NextPage so that your text will start printing at the top
' of the next page.
' First, split the text into multiple paragraphs
Var paragraphs() As String = OurText.ReplaceLineEndings(EndOfLine).Split(EndOfLine)
Var pageTextHeight As Double = topMargin
Var newpageTextHeight As Double
For i As Integer = 0 To paragraphs.LastIndex
newpageTextHeight = pageTextHeight + page.TextHeight(paragraphs(i), ps.Width - leftMargin * 2)
If newPageTextHeight > ps.Height - topMargin * 2 Then
' String does not fit on page, so move to next page
page.NextPage
pageTextHeight = topMargin
newpageTextHeight = pageTextHeight + page.TextHeight(paragraphs(i), ps.Width - leftMargin * 2)
End If
' If string fits on page, then draw it
page.DrawText(paragraphs(i), leftMargin, pageTextHeight, ps.Width - leftMargin * 2)
' Keep a cumulative count of the pageheight as strings are added to it
pageTextHeight = newpageTextHeight ' Adjust page text height
pageTextHeight = pageTextHeight + topMargin / 8 ' 1/8 inch between paragraphs
Next
End If
End If
Hi jeff thanks for the reply and the info will give it a try on my system the send it to my Mate and see what happens.
Had problems getting my head round the showpage setup and the commands you can get back so as to change the length and width, so willread the program you have supplied and will try and learn from it.
Please am getting old so brain not as useful as it used to beâŠ( am 71)
You may have to scale the FontSize based on ps.HorizontalResolution. At 72 dpi, a font size of 12 works well. At 300 dpi, you need a font size of 50 to produce the same output.
LOL. Xojo DOES NOT send it as âa graphicâ Try your example printing to a PDF printer and you will see that is TEXT, not a picture.
That is NOT what Ian is talking about, on the oposite side, VB6 was not writing directly to a port, it was doing the same as Xojo BUT 2 decades ago VB6 had nother layer to simplify the printing to the user:
Try your example printing to a PDF printer and you will see that is TEXT, not a picture.
That has just added another layer to the process.
The PDF file is a set of printer control language instructions, including position , font instructions, and sometimes even embedded fonts, not just âABCâ and they still have to be drawn using graphics at the printer end sometimes.
Hi Everybody, First off I appreciate all the comments and Thanks to Jeff Tullin for taking the time to write that code which has solved the problem I was having.
I must say that my question seems to have stirred up some different opinions which is allways a good thing.
As for PDF I am having enough problems printing text never mind getting involved with PDF stuff.
Pleasse except my thanks and keep up the good work.
Sorry you missunderstood my comment, I know the way to print too PDF what I meant was getting involved with using Xojo to create PDF reports.
I Have been using the Print to PDF to save using up my paper and ink (Am using Win 11).
Thanks, Jeff. I am in the process now of getting text on PDF/Printed and stumbled on this post after also studied the Xojo project example. It works great except that I do not understand why the text is being pushed to a next page at the end of a paragraph. Is there a way to avoid this?