This page is "browser friendly". Make your browser window as wide as you want it. The text will flow nicely for you. It is easier to read in a narrow window. With most browsers, pressing plus, minus or zero while the control key (ctrl) is held down will change the texts size. (Enlarge, reduce, restore to default, respectively.) (This is more fully explained, and there's another tip, at my Power Browsing page.)
I'm going to try to sketch the CORE of the Lazarus code needed to print out 3 pages of ink-on-paper.
Obviously, this would need a some "fleshing out", but I hope it will get you started. With what's on this page, you should get three pages of hardcopy for one button click. (Well, two, if you count the "OK" on the printer dialog.)
The "application" is going to have one button.
"Behind the scenes", unseen by the user, there will also be a printer dialog on the form.
When you press that, three pages will be printed, with a line of text on each.
What I know mostly came from the "official" page on producing hardcopy with Lazarus. (An more extensive discussion by me is available, too.)
You need to install the "official" printer support package, Printer4Lazarus. (Details at the pages cited a moment ago. As are details of many of the things I will refer to in this.
Any application using that must have "Printers" added to its "uses" clause.
In theory, the heart of all you then need is...
Printer.DocBegin; Printer.Canvas.TextOut(10,20,'First page'); Printer.DocEnd; Printer.DocBegin; Printer.Canvas.TextOut(10,20,'Second page'); Printer.DocEnd; Printer.DocBegin; Printer.Canvas.TextOut(10,20,'Third page'); Printer.DocEnd;
A fine theory.
Do it that way, and you are presuming that the font will be what you want, by default. So much better to establish a font on purpose, don't you think?
Printer.Canvas.Font.Name:="Courier New";//should be a font on your system Printer.Canvas.Font.Color:=clBlack;//"clBlack" is pre-defined in Lazarus Printer.Canvas.Font.Size:=12;//units: "Points"
I THINK that if you do this once, just before the first TextOut, that it will carry over into the next BeginDoc/EndDoc block. It might be "better", on several grounds, to do it after each BeginDoc. (You'd make a parameter-less subroutine ("DoItAgain"?), and provide other ways to keep that informed as to your wants.)
It isn't supposed to be necessary, but I have found that at run time, the "simple" answer above often triggers a "SIGSEGV" error... whatever that may be! that may not happen on your present system... but what about next week, when Microsoft has changed your operating system again? And do you want to write something only for your present system? Will you never upgrade?
So.. the following takes us away from the "simple" demo this was supposed to be, but probably necessarily.
To print a single page:
if PrintDialog1.execute then begin with Printer do try BeginDoc; Canvas.Font.Name := 'Courier New'; Canvas.Font.Size := 12; Canvas.Font.Color := clBlack; Canvas.TextOut(10,20,'First page'); finally EndDoc;
The good news is...
This gives the user a chance to abort a print job for those times when "Print it" was invoked by mistake. And...
It seems that one PrintDialog1.execute is enough. It is early days... I'm only the one-eyed king, trying to be helpful... it SEEMS that the following "works". (The only difference between this and the previous is the material in blue.)
procedure TForm1.Button1Click(Sender: TObject); begin if PrintDialog1.execute then begin with Printer do try BeginDoc; Canvas.Font.Name := 'Courier New'; Canvas.Font.Size := 12; Canvas.Font.Color := clBlack; Canvas.TextOut(10,20,'First page'); EndDoc;
BeginDoc; Canvas.TextOut(10,20,'Second page'); EndDoc; BeginDoc; Canvas.TextOut(10,20,'Third page'); //NO EndDoc; here... there's one to come in the "finally" clause.
finally EndDoc; end;//of try/finally end;//of if... execute.. then... end;//Button1Click
So! That's it! So why have I been ten days working on something not a lot more complex? Sigh.
For further discourses about printing, see my more detailed page about generating hardcopy. (This is the one I mentioned before.) There are more "onward" links there, too.
Search across all my sites with the Google search...
To search THIS site.... (Go to my other sites, below, and use their search buttons if you want to search them.)
|search engine by freefind|
The search engine merely looks for the words you type, so....
* Spell them properly.
* Don't bother with "How do I get rich?" That will merely return pages with "how", "do", "I"....
Please also note that I have two other sites, and that this search will not include them. They have their own search buttons.
My SheepdogSoftware.co.uk site.
My site at Arunet.
To email this page's editor, Tom Boyd.... Editor's email address. Suggestions welcomed! Please cite "lt3Nhardc-multpg-intro.htm".
Page has been tested for compliance with INDUSTRY (not MS-only) standards, using the free, publicly accessible validator at validator.w3.org. Mostly passes.
If this page causes a script to run, why? Because of things like Google panels, and the code for the search button. Why do I mention scripts? Be sure you know all you need to about spyware.
....... P a g e . . . E n d s .....