Pretty printing library

agraham

Expert
Licensed User
Longtime User
Finding myself unexpectedly released from jury duty for a couple of days I knocked up this desktop only library. I am rather pleased with it (he said modestly). It is compiled for .NET 2.0 but the source is provided and should compile without change under .NET 1.1.

It uses a RichTextBox to provide nicely laid out printed pages with choice of colour, font and alignment. Page setup, preview and print are provided and pagination is automatic. I am still looking to see if manual page breaks can be provided. The printing is based on some code I found in MSDN.

In normal use I envisaged that the RichTextBox would be made invisible and just used to build the document - the example enclosed keeps it visible. If you want to add events use my ControlEvents library and the ControlRef property of the RichTextBoxDesktop.

It is a work in progress and ultimately I will provide a help file. Please try it and post any suggestions for improvement.

EDIT :- Version 1.6 posted with CutSelectionToClipboard and CopySelectionToClipboard methods added. Help file updated.

EDIT :- Version 1.7 posted. Has WordWrap and Scrollbars properties added and a dummy library for the device. Help file updated. Sources for merging posted in separate zip file.

EDIT:- Version 1.8 allows user formatting and editing of text. See post #67.
 

Attachments

  • RichTextBoxDesktop1.8.zip
    35.2 KB · Views: 350
Last edited:

Cableguy

Expert
Licensed User
Longtime User
Nice,Very Nice
 

agraham

Expert
Licensed User
Longtime User
I don't think that I can take this library any further. This version 1.1 adds vertical offset for sub and superscripts, hanging indent at paragraph start, right and left (or both) indented text and bullets, tabs and new page.

The control background colour may be set, and the plain text and rtf formatted text obtained.

Text and bitmaps may be pasted from the clipboard.

Help file to follow once I get motivated to do it.

Pre 5.80 B4PPC will see some capitalised objects in the library - ignore them. 5.80 won't show them. Thanks Erel!

EDIT: Forgot the source. It is now included in the zip file.
 

Attachments

  • RichTextDesktop1.1.zip
    9.3 KB · Views: 164
Last edited:

giannimaione

Well-Known Member
Licensed User
Longtime User
Good work

Good work or :sign0098:
 

Softselect

Member
Licensed User
Hi Agraham,
This library came as a blessing to me, just what i needed great work:sign0060:

I have a question:
how can I get the program to print without the printer selection screen coming up, I am using a program as a print spooler and i dont want any user intervention. (The print server has no keyboard or screen)
It must print to default printer and it is mainly text

Thanks
Friedrich
 

Attachments

  • TranSpoolPrint1v0.sbp
    4.8 KB · Views: 108
  • spool.txt
    160 bytes · Views: 103

agraham

Expert
Licensed User
Longtime User
If it's just text and you don't need the fancy stuff layout stuff you could try the Printer object in the DesktopOnly library.

You raise an interesting problem that I will investigate tomorrow (I have another day off jury duty :) ) to see if I can trigger printing somehow.
 

giannimaione

Well-Known Member
Licensed User
Longtime User
Hi Agraham,
is it possible to control PrintPreview methods?
example: maximaze form ; select value of Zoom ;

sorry for my bad english
 

agraham

Expert
Licensed User
Longtime User
how can I get the program to print without the printer selection screen coming up,
I will post a version that will let you do this do this later today.

is it possible to control PrintPreview methods?
example: maximaze form ; select value of Zoom
I can give you Top and Left (position on screen), Height and Width (size) and WindowState (normal, minimised & maximised) later today. I can't easily do anymore as this dialog is designed for user interaction not program control.
 

agraham

Expert
Licensed User
Longtime User
Here it is. Version 1.2 with updated help and sample file - throw all previous versions away!

Top, Left, Height, Width and WindowState properties for Print Preview.

RichTextBoxDesktop.Print now prints immediately. New method RichTextBoxDesktop.PrintDiallog displays the print dialog.

New property RichTextBoxDesktop.PageSetupMetric to help deal with the Page Setup dialog metric "feature". See the Overview in the help file.

This needs .NET 2.0
 

Attachments

  • RichTextBoxDesktop1.2.zip
    21.9 KB · Views: 57

Softselect

Member
Licensed User
Hi Agraham,
Well done, you make it all look so simple:sign0188:
So far its working perfect for me, it is as if you read my mind with this lib, i was panicing how i was going to do nice printing, customers and friends always say plain text is good enough until it is what you give the, then its a problem.
Thanks for your effort and responce to my request
Friedrich:)
 

Softselect

Member
Licensed User
Hi Agraham,
I have a problem repeating my program (attched), when i print with your lib, delete the file and want to scan the drive for the next file (spool function)
nothing happens, could you please help, i seem to be stuck here. Brain freeze
This needs to happen without user intervension as the print server doesnt have a screen or keyboard
Thank you
Friedrich:)
 

Attachments

  • TranSpoolPrint1v1.sbp
    7.7 KB · Views: 31
  • spool.txt
    154 bytes · Views: 31

giannimaione

Well-Known Member
Licensed User
Longtime User
Well done,
good, good, very good...

:):sign0188:
 

agraham

Expert
Licensed User
Longtime User
could you please help, i seem to be stuck here.
Several things wrong I am afraid

The first problem is that you have a "Return" statement in App_Start. This is terminating the progam by exiting from App_Start.

Secondly (after removing the return) at the end of App_Start you are doing a recursive call (calling itself), this is not necessary and will cause a stack failure. App_Start is only for initialisation and your code should run off the end of App_Start. If a form is displayed your program will not end but will be there ready to respond to events. If no form is displayed your program will end on leaving App_Start.

Your delay routine is bad practice as it is using processor time unnecessarily by running in a loop. This starves other programs of processor cycles. You should be using a timer which takes no processor time when it is not executing code. Your code should look something like this

B4X:
Sub Globals
   'Declare the global variables here.
End Sub

Sub App_Start
   ' do initialisation here
   Form1.Show
   Timer1.enable ' timer set to appropriate delay
End Sub

Sub TimerTick
   ' check for file
   If file Then
      print it
      delete it
   End If
End Sub
This has no means of stopping the program - but maybe you don't need to in a print server with no screen or keyboard.
 

markbarrett_1

Member
Licensed User
Longtime User
PageSetup under program control

Hi,

Nice library....

Anyways is there a way to programatically set or save what the user selects for printing using the pagesetup method. For example in my database reports, I always will want landscape, but most printers default to portrait. Also the margins are too much as well. It would be nice if I can set them under program control rather than have the users always having to select landscape etc etc.

Thanks.

Cheers.

M
 

agraham

Expert
Licensed User
Longtime User
Version 1.3 with Landscape, LeftMargin, RightMargin, TopMargin and BottomMargin properties. They may be set without displaying the print setup and should be honoured when printed. They may also be read back from the PrintSetup dialog after displaying it if the users' choices are required. Note that margins are always expressed as hundreths of an inch - even on metric systems. This explained in the help.
 

Attachments

  • RichTextDesktop1.3.zip
    19.5 KB · Views: 25

markbarrett_1

Member
Licensed User
Longtime User
Hi,

Version 1.3 with Landscape, LeftMargin, RightMargin, TopMargin and BottomMargin properties.

Thanks....I'll check it out tomorrow...Its getting late here and I should go to bed.

In the control I notice you can paste a bitmap image. I presume it paste's the bitmap where the current cursor is on the page? Also what is the simpliest way of getting a bitmap to the paste buffer. I have bitmaps in my database and having them printed out would be awesome.

Thanks gain.

Cheers.

M
 

agraham

Expert
Licensed User
Longtime User
Also what is the simpliest way of getting a bitmap to the paste buffer.
I tried adding a function to the library using the .NET Clipboard object but as it it is a wrapped COM component it wants to run in an STA environemt - which B4PPC isn't. I hit this same snag trying to wrap the WebBrowser so there are some things not easily done in a B4PPC library - and I mainly do easy ;)
 
Top