Formatting and printing of text...

RandomCoder

Well-Known Member
Licensed User
Longtime User
I fear this is going to be long... but will try to be as concise as possible.

I’m capturing data that was intended to be printed. The data is sent one of two ways, either by hitting the “print screen” key or by requesting the machine to print. I have no control over the machines that are sending the data and no way of changing print drivers etc.

Data send using the “print key” is encoded using codepage 437. The other data is presumably sent using the same codepage but looks as though it has been sent via a print driver as it also contains special codes to change Font size, alignment, indenting etc.

I’ve written two programs, one to capture the sent data and save it to file, and another to ‘read’ the file so as to view/print the data. I’ve done this as there will be six machines connected to the PC and I want to try and ensure that all the data is captured and saved.

Q1. – Am I correct in thinking that B4PPC cannot be opened with arguments to load a file? I would like to trigger the ‘read’ program to load the file that has just been saved so that the operator can check the data is intact and that the order/batch numbers are correct (as these form part of the filename).
My way around this is going to be to open the ‘read’ and first check to see if an .ini file is present, this .ini file will hold the last saved file and will be deleted as the ‘read’ file opens. Is there a better way?

So I have all my data captured and this seems to be working very nicely :), and I’m also able to open and view the files, which after a little manipulation (i.e removal of the special printer codes) look reasonably similar to the originals. But now when I come to print all goes horribly wrong!
The formatting is all over the place, I’ve tried sending the raw file to the printer (not the same printer as connected to the machine) and the formatted string from the Textbox which looks great on screen but not so good on paper :(.

However, if I save the Textbox string to file (in this example I’ve called the file FormattedText.txt) and then open using Wordpad or Notepad it is displayed correctly but more importantly it also prints correctly :BangHead:.

Q2.- Why does the TextBox not print the same as it displays on screen? :confused:
I then decided that maybe I should use the RichTextBoxDesktop Library as this would also provide more control over the formatting.... ideally I’d like to reduce the font size for the table at the bottom of the results screen. But I still have the same problem Loading the string into the RichTextBox produces exactly the same result as I get when attempting to print. Loading the file fails as .txt files are not supported.

Any idea’s on where I should go from here?

Regards,
RandomCoder.
 

Attachments

  • PrintCapture (Unicode).sbp
    5.8 KB · Views: 191
  • ReadData.sbp
    2 KB · Views: 180
  • Print Results Capture.txt
    2.3 KB · Views: 242
  • Print Screen Capture (2).txt
    2 KB · Views: 232
  • FormattedText.txt
    2.9 KB · Views: 225

RandomCoder

Well-Known Member
Licensed User
Longtime User
After a nights sleep and a little more tinckering I've had a thought :sign0138:

Could my formatting problems simply be caused by the Font style not being honoured when I choose to print?
Is there a way to force the printer to use a selected Font? (I am refering to using the DesktopOnly library here.)

I'll have a play this morning at getting the text into a RichTextBox making sure that it gets entered as "Courier New" and see what happens :sign0156:

Regards,
RandomCoder
 

agraham

Expert
Licensed User
Longtime User
Bimetallic snap-action thermostat disc testing?

Could my formatting problems simply be caused by the Font style not being honoured when I choose to print?
Yes, the "formatting" assumes a fixed width font - just like an old-fashioned printer :)
Is there a way to force the printer to use a selected Font? (I am refering to using the DesktopOnly library here.)
DefaultPrinter.FontName = "Courier New". Trouble is you may have problems with the default printer margins being too wide to fit your page and also the formatting assumes landscape layout by the look of it. Using the Door library you can successfully print from your Textbox using the DesktopOnly Printer.

B4X:
   DefaultPrinter.New1
   DefaultPrinter.FontName = "Courier New"
   DefaultPrinter.FontSize = 10 ' this in fact the default
   Obj1.New1(False)
   Obj1.FromLibrary("Main.DefaultPrinter", "pd", B4PObject(2)) ' get the PrintDocument
   Obj1.Value = Obj1.GetProperty("DefaultPageSettings")
   Obj1.SetProperty("Landscape", True)
   Obj1.Value = Obj1.GetProperty("Margins")
   Obj1.SetProperty("Left", 0) ' hundreths of an inch
   Obj1.SetProperty("Right", 0) ' hundreths of an inch   
   DefaultPrinter.PrintString( TxtData.Text )
There are also "Top" and "Bottom" margin settings.

Am I correct in thinking that B4PPC cannot be opened with arguments to load a file?
I assume, from your apparent intended use, that you mean a Basic4ppc application rather than Basic4ppc itself. An application can receive an arbitrary number of arguments by means of the global array variable "args()". See Help->Main Help->Basics->Command Line Arguments.
 
Last edited:

RandomCoder

Well-Known Member
Licensed User
Longtime User
@AGraham,

You are a star!
I've been tolling over this all morning and have managed to get it to work using you RichTextBoxDesktop library.
As I don't think I've ever thanked you for all the great libraries you've produced I would like to extend my appreciation now :sign0188:

By using the richtext box I've been able to adjust the font size for the results table (if present) at the bottom of some pages.

I was just setting about writing an ini file that would be created as I shell my ReadData program which would then have used the file before deleting it. It's a good job I came back to the forum as I was blissfully unaware of the Args() parameter... this makes things alot simpler.

I do attempt to read the help before posting but sometimes things obviously escape my attention :sign0161:

Kind Regrads,
RandomCoder

PS "Bimetallic snap-action thermostat disc testing?" - new job and very much thrown in at the deep end. Still finding my feet but loving every minute!
 
Top