printing a table

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

printing a table

Stefan Schmiedl
Hi there,

I want to print a table on the default printer in landscape mode.

As I have almost no experience with the windows api, I wonder, if
there is a way to get a PrinterCanvas in Dolphin for the default
printer, but in landscape mode, without requiring the user to
fiddle with the print dialog settings.

As for filling the table itself, I probably will have to use
Canvas>>formatText:in:flags: and Font properties a lot, right?

And gathering knowledge from Ian's Printer package, it seems like
the real printing can be done by moving a sheet-sized rectangle
over the canvas.

If this is totally wrong, I would appreciate a slight knock on
the piece of wood some folks call my head.

thanks,
s.

--
Stefan Schmiedl
EDV-Beratung, Programmierung, Schulung
Loreleystr. 5, 94315 Straubing, Germany
Tel. (0 94 21) 74 01 06
Public Key: http://xss.de/stefan.public

shhhh ... I can't hear my code!


Reply | Threaded
Open this post in threaded view
|

Re: printing a table

Louis Sumberg-2
I'm currently working on a similar thing and I don't have the answers ...
but I did add the following method to PrinterCanvas that returns the default
printer.

default
    "Answers a new instance of the receiver created with a non-owned hDC to
the default printer."

    | pd |
    pd := PrintDialog new.
    pd winStruct flags: (PD_RETURNDEFAULT | PD_RETURNIC).
    ^self withOwnedDC: pd showModal

Setting the printer orientation seems a bit more tricky.  As far as I can
see, one has to create a DEVMODE structure, which I just started to do, but
haven't gotten too far on.

Actually, if it's just the default printer for which you want to set the
orientation, there's a PageSet.dll from Microsoft.  It sounds like that'll
do the job for you -- unfortunately for me, I want to programmatically
change the orientation of any printer (e.g., p := PrinterCanvas choose. p
orientation: landscape) which is why I started fiddling with DEVMODE.

"Stefan Schmiedl" <[hidden email]> wrote in message
news:a2ught$13oqmf$[hidden email]...

> As I have almost no experience with the windows api, I wonder, if
> there is a way to get a PrinterCanvas in Dolphin for the default
> printer, but in landscape mode, without requiring the user to
> fiddle with the print dialog settings.


Reply | Threaded
Open this post in threaded view
|

Re: printing a table

Ian Bartholomew-6
Louis/Stefan,

> Setting the printer orientation seems a bit more tricky.  As far as I can
> see, one has to create a DEVMODE structure, which I just started to do,
> but haven't gotten too far on.

Yes, you are right about needing DEVMODE. I've been working on a replacement
for my printer goodie, one that uses a PrintDialog and PageDialog in the
same way as "normal" Windows apps. I got it working but there were some
problems caused my my keenness to avoid implementing DEVMODE in Dolphin. I
don't think there's a way round it, but it looks like a big job and keeps
getting put off.

I did wonder if there is an ActiveX component that could be pressed into
service - they seem to do most things these days. Anybody know?

Stefan's other problem is the actual printing. The example he mentioned, my
original goodie, uses banding to print the pages.  This only works for text
pages though, you have to specify the character position in the document
where you want each page to start.  If he wants to print tables, and the
tables include borders created by drawing lines rather than ASCIIArt, then
it will have to be done in a graphic format and I don't know how that is
done. It might be easier than text ... or it might not!.

Regards
    Ian


Reply | Threaded
Open this post in threaded view
|

Re: printing a table

Stefan Schmiedl
On Sun, 27 Jan 2002 09:32:35 -0000, Ian Bartholomew <[hidden email]> wrote:
>
> Yes, you are right about needing DEVMODE. I've been working on a replacement
> for my printer goodie, one that uses a PrintDialog and PageDialog in the
> same way as "normal" Windows apps. I got it working but there were some
> problems caused my my keenness to avoid implementing DEVMODE in Dolphin. I
> don't think there's a way round it, but it looks like a big job and keeps
> getting put off.

after a look at the delphi implementation of this stuff, i can only
call it messy.

>
> Stefan's other problem is the actual printing. The example he mentioned, my
> original goodie, uses banding to print the pages.  This only works for text
> pages though, you have to specify the character position in the document
> where you want each page to start.  If he wants to print tables, and the
> tables include borders created by drawing lines rather than ASCIIArt, then
> it will have to be done in a graphic format and I don't know how that is
> done. It might be easier than text ... or it might not!.

the data consists of ten-row chunks which I should be able to position quite
nicely.

hmmm.... come to think of it, can I make a "normal" view, which is usually
embedded within a shell view, render itself to my printing canvas?

thanks,
s.

--
Stefan Schmiedl
EDV-Beratung, Programmierung, Schulung
Loreleystr. 5, 94315 Straubing, Germany
Tel. (0 94 21) 74 01 06
Public Key: http://xss.de/stefan.public

shhhh ... I can't hear my code!


Reply | Threaded
Open this post in threaded view
|

Re: printing a table

Bill Schwab
Stefan,

> the data consists of ten-row chunks which I should be able to position
quite
> nicely.
>
> hmmm.... come to think of it, can I make a "normal" view, which is usually
> embedded within a shell view, render itself to my printing canvas?

Yes and no.  The resolution will be different, so you'll have to do a lot of
"looking at the canvas".  FWIW, I prefer to always draw in pixels,
converting from physical dimensions as I go.  One could use mapping modes,
but, I find that more difficult (or at least less intuitive) and besides,
the fixed integer conversions might overflow, especially on Win9x.  I find
it easier and safer to do the scaling myself.

Printing introduces the challenge of pagination.  Here too, doing your own
conversion to device coordinates (IMHO anyway) makes it easier to find view
port and clipping settings that work.

It's not easy, but, it can be done.

Have a good one,

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: printing a table

Ian Bartholomew-6
In reply to this post by Stefan Schmiedl
Stefan,

> hmmm.... come to think of it, can I make a "normal" view, which is usually
> embedded within a shell view, render itself to my printing canvas?

Bill is quite right in his answer in that copying an existing view across to
the PrinterCanvas is possible but can provide some interesting challenges.

However, the Windows RichTextEdit control already has built in support for
printing, it's the way that my Printer goodie works, so if you are willing
to only use the facilities that the control provides - text only [1] - then
it is a bit easier.  File the following into a workspace and evaluate it
all. The first bit writes a small table into a RichTextEdit (very clumsily
but that can be streamlined) and the second half is the printing loop
extracted from my goodie. You will still need the PrinterDialog [2] though,
I haven't found an easy way round that.

If you have a view already containing a RichTextEdit then you can just grab
that and print as below.

Regards
    Ian

[1]  I think I remember reading that the newer RichTextEdit controls have
added support for drawing tables and the like - as on a HTML page. It may
have been some other control though ....

[2] If you don't want your users to have to fiddle with the dialog perhaps
you could create a new Printer with the printer defaults set to the correct
format for your reports - landscape etc. You could then either tell the
users to select that printer in the dialog, they need do nothing else, or
omit the dialog and select the printer automatically using the snippet of
code that Louis posted earlier.  Just a thought.

textEdit := RichTextEdit new
    parentView: View desktop;
    create.

twoTab := String tab , String tab.

textEdit
    selectionFont: (Font name: 'Arial' pointSize: 14);
    selectionColor: Color blue;
    beBold;
    beUnderlined;
    selectionRange: (-1 to: -1);
    replaceSelection: String lineDelimiter , 'Date   ' , twoTab , 'Office' ,
twoTab , 'Takings' , String lineDelimiter , String lineDelimiter;

    selectionFont: (Font name: 'Arial' pointSize: 12);
    selectionColor: Color black;
    selectionRange: (-1 to: -1);
    replaceSelection: '10/1/2001' , twoTab , 'London' , twoTab , '£23.45' ,
String lineDelimiter;

    selectionFont: (Font name: 'Arial' pointSize: 12);
    selectionColor: Color black;
    selectionRange: (-1 to: -1);
    replaceSelection: '15/1/2001' , twoTab , 'Hastings' , twoTab , '£100.00'
, String lineDelimiter;

    selectionFont: (Font name: 'Arial' pointSize: 12);
    selectionColor: Color black;
    selectionRange: (-1 to: -1);
    replaceSelection: '20/1/2001' , twoTab , 'London' , twoTab , '£10.00' ,
String lineDelimiter.

printer := PrinterCanvas choose.
pageRect := 0 @ 0 corner: printer extent / printer resolution.
printRect := pageRect topLeft + (200@200/printer resolution) corner:
pageRect bottomRight - (200@200/printer resolution).

pageRect := (pageRect scaleBy: 1440) truncated.
printRect := (printRect scaleBy: 1440) truncated.

(formatrange := FORMATRANGE new)
    hdc: printer handle;
    hdcTarget: printer handle;
    rcPage: (RECT fromRectangle: pageRect).

firstChar := 0.

printer startDoc.
[firstChar < textEdit textLength] whileTrue: [
    printer startPage.
    formatrange
        rc: (RECT fromRectangle: printRect);
        cpMin: firstChar;
        cpMax: -1.

        firstChar := textEdit sendMessage: 1081 wParam: 1 lpParam:
formatrange.
    printer endPage].
printer endDoc.

textEdit sendMessage: 1081 wParam: 0 lpParam: nil


Reply | Threaded
Open this post in threaded view
|

Re: printing a table

Dmitry Zamotkin-3
In reply to this post by Stefan Schmiedl
Hello Stefan,


> I want to print a table on the default printer in landscape mode.
>
> As I have almost no experience with the windows api, I wonder, if
> there is a way to get a PrinterCanvas in Dolphin for the default
> printer, but in landscape mode, without requiring the user to
> fiddle with the print dialog settings.
>
> As for filling the table itself, I probably will have to use
> Canvas>>formatText:in:flags: and Font properties a lot, right?
>
> And gathering knowledge from Ian's Printer package, it seems like
> the real printing can be done by moving a sheet-sized rectangle
> over the canvas.

How about to try my package for printing from Internet Explorer? HTML
generation of table is pretty simple, and printing become an easy:

(ExplorerControlSite url: tempHtmlPageUrl) print. "where tempHtmlPageUrl is
local temporary filename with file:/// prefix"

I post this package here at  30 Oct 2001 09:47:54. If you cant get it I'll
send by email or repost here.

Dmitry Zamotkin


Reply | Threaded
Open this post in threaded view
|

Re: printing a table

Stefan Schmiedl
In reply to this post by Ian Bartholomew-6
On Sun, 27 Jan 2002 22:19:39 -0000,
Ian Bartholomew <[hidden email]> wrote:
>
> [1]  I think I remember reading that the newer RichTextEdit controls have
> added support for drawing tables and the like - as on a HTML page. It may
> have been some other control though ....

I think, I will have to insist on some guiding lines, too ... I saw somewhere
on the net that rtf 1.5 has tabular abilities, but I have seen no methods
in dolphin referring to this.

btw: what do you mean by "newer RichTextEdit controls"? It makes me wonder,
where they come from ... dolphin or some windows library? if the latter,
what happens if my app tries to run on a machine with "older" versions?

>
> [2] If you don't want your users to have to fiddle with the dialog perhaps
> you could create a new Printer with the printer defaults set to the correct
> format for your reports - landscape etc. You could then either tell the

nice try, ian. but the printer driver for the hp laserjet 4p on the client's
machine has no option to switch to landscape mode. I *can* switch via the
extended properties of the print dialog, however ... so it will be that way.

> users to select that printer in the dialog, they need do nothing else, or
> omit the dialog and select the printer automatically using the snippet of
> code that Louis posted earlier.  Just a thought.

I did not try the sample code, but where does it specifiy that the office
colum is left aligned and the takings colum right aligned? richtext was
not an option after I could not find a way to do this.

>
> textEdit := RichTextEdit new
>     parentView: View desktop;
>     create.
>
> twoTab := String tab , String tab.
>
> textEdit
>     selectionFont: (Font name: 'Arial' pointSize: 14);
>     selectionColor: Color blue;
>     beBold;
>     beUnderlined;
>     selectionRange: (-1 to: -1);
>     replaceSelection: String lineDelimiter , 'Date   ' , twoTab , 'Office' ,
> twoTab , 'Takings' , String lineDelimiter , String lineDelimiter;
>
>     selectionFont: (Font name: 'Arial' pointSize: 12);
>     selectionColor: Color black;
>     selectionRange: (-1 to: -1);
>     replaceSelection: '10/1/2001' , twoTab , 'London' , twoTab , '£23.45' ,
> String lineDelimiter;
>


Reply | Threaded
Open this post in threaded view
|

Re: printing a table

Ian Bartholomew-6
Stefan,

> I think, I will have to insist on some guiding lines, too ... I saw
> somewhere on the net that rtf 1.5 has tabular abilities, but I have seen
> no methods in dolphin referring to this.
>
> btw: what do you mean by "newer RichTextEdit controls"? It makes me
> wonder, where they come from ... dolphin or some windows library? if the
> latter, what happens if my app tries to run on a machine with "older"
> versions?

The RichTextEdit control is supplied in a dll as part of Windows and Dolphin
just contains methods to interface with the dll.   MS occasionally provide
updated versions which contain new facilities but which, usually, are
backward compatible [1].  To use the extra facilities from within Dolphin
you would have to add extra interface methods to access them.  If you did
this then you would obviously have to provide some mechanism to allow for
machines that didn't have the updated control installed.

The rtf 1.5 you mention above sounds like a specification for the formatting
of rtf documents. I don't think that the RichTextEdit dll will necessarily
support everything defined in the specification, at least not straight away.

> nice try, ian. but the printer driver for the hp laserjet 4p on the
> client's machine has no option to switch to landscape mode. I *can*
> switch via the extended properties of the print dialog, however ... so
> it will be that way.

Oh well, it was only a thought...

> I did not try the sample code, but where does it specifiy that the office
> colum is left aligned and the takings colum right aligned? richtext was
> not an option after I could not find a way to do this.

It just uses the tab stops to left align all the columns.  There are a few
ways to right align fields but you will probably need a fixed width font to
make it work.

If you only want to right align the currency fields then the easiest way is
probably to use my CurrencyToText goodie.  If you want to be able to right
align all types of  field then you can do it by hand using String>>sprintf,
Stream padTo:with: or writing a Smalltalk method to manually pad the left
hand side with spaces and/or whatever.

Regards
    Ian

[1] RichTextEdit is actually a good example. I (think) the latest version
(provided with Win2000 and XP) is 3.0, but for compatibility the basic
Dolphin image doesn't expect anything more than RichEdit 1.0.  However,
rather than providing three separate RichEdit dll's MS transparently emulate
1.0 using the functions provided within the 3.0 dll.  This has caused some
problems for Dolphin in the past where the emulation does not exactly match
the function of the original 1.0 dll.


Reply | Threaded
Open this post in threaded view
|

Re: printing a table

Stefan Schmiedl
On Tue, 29 Jan 2002 10:51:32 -0000,
Ian Bartholomew <[hidden email]> wrote:
>
>> I did not try the sample code, but where does it specifiy that the office
>> colum is left aligned and the takings colum right aligned? richtext was
>> not an option after I could not find a way to do this.
>
> It just uses the tab stops to left align all the columns.  There are a few
> ways to right align fields but you will probably need a fixed width font to
> make it work.

I did it the hard way, manually, while sitting with my laptop in
my customer's office. just like in some japanese restaurants, where
your food is prepared right at your table ... :-)
it was impressive, actually, for both of us, how smooth it went.
especially when I finished 5 minutes before my parking meter ran out
of time :-)

I will post some code later tonight, if I don't fall asleep in front
of the computer again.

> [1] RichTextEdit is actually a good example. I (think) the latest version
> (provided with Win2000 and XP) is 3.0, but for compatibility the basic
> Dolphin image doesn't expect anything more than RichEdit 1.0.  However,
> rather than providing three separate RichEdit dll's MS transparently emulate
> 1.0 using the functions provided within the 3.0 dll.  This has caused some
> problems for Dolphin in the past where the emulation does not exactly match
> the function of the original 1.0 dll.

and this why i prefer to avoid external libs as much as possible on windows.
much messier there than on other os'es.

thanks,
s.
--
Stefan Schmiedl
EDV-Beratung, Programmierung, Schulung
Loreleystr. 5, 94315 Straubing, Germany
Tel. (0 94 21) 74 01 06
Public Key: http://xss.de/stefan.public

shhhh ... I can't hear my code!