Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-06

Printing a formatted page

6 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Dave Coventry

Is there any way of setting up a page in RTF, say, and reformatting so that it can be drawn on TPrinter.Canvas?

Currently I'm measuring the positions of lines and text in millimetres and scaling them up so that I can use Printer1.Canvas.Moveto(470,625) and Printer1.Canvas.LineTo(880,625).

Reply by email

Dave Coventry
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote
What do you mean by RTF?

RTF = Rich Text Format

Could you explain better what you are trying to do?

I want my app to generate printed forms and letters.

Currently I have to measure the page I want to print and use the Canvas draw commands to draw the page. If anything changes I have to measure the page again and input the data in terms of lineto, moveto and textout methods.

What I'm hoping to do is to format the page using OpenOffice and then convert this to moveto, lineto, textout, etc.

PCL uses similar methods, penup, pendown, etc; maybe I could format the page and output it to PCL and then convert the PCL to TPrinter.Canvas functions? Maybe even Postscript? I used to have the old Adobe "Postscript Cookbook". If I could just find it again...

Reply by email

Zaher Dirkey
to Dave Coventry

You need like as MetaFile in Delphi, did you try TPostScriptCanvas in "pscanvas" unit, i am not test it in fact.

Dave Coventry wrote 27 lines
On Sun, Jun 22, 2008 at 5:30 PM, Felipe Monteiro de Carvalho wrote: > What do you mean by RTF? RTF = Rich Text Format > Could you explain better what you are trying to do? I want my app to generate printed forms and letters. Currently I have to measure the page I want to print and use the Canvas draw commands to draw the page. If anything changes I have to measure the page again and input the data in terms of lineto, moveto and textout methods. What I'm hoping to do is to format the page using OpenOffice and then convert this to moveto, lineto, textout, etc. PCL uses similar methods, penup, pendown, etc; maybe I could format the page and output it to PCL and then convert the PCL to TPrinter.Canvas functions? Maybe even Postscript? I used to have the old Adobe "Postscript Cookbook". If I could just find it again... _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
Zaher Dirkey

Reply by email

Felipe Monteiro de Carvalho
to Dave Coventry: On Sun, Jun 22, 2008 at 5:30 PM, Felipe Monteiro de Carvalho RTF = Rich Text Format I…
Dave Coventry wrote
Currently I have to measure the page I want to print and use the Canvas draw commands to draw the page. If anything changes I have to measure the page again and input the data in terms of lineto, moveto and textout methods.

What do you need? Just the size of the paper?

If you are using "normal" paper, you can let LCL calculate the size by simply giving the paper name to it:

uses Printers;
Printer.papersize.papername := 'A4';
PaperWorkRect := Printer.PaperSize.PaperRect.WorkRect; // This holds
the printable area of the paper

Printer.PaperSize.PaperRect.PhysicalRect holds the entire paper, including areas that the printer won't be able to print to.

Example of printing using this:

Printer.BeginDoc;
Printer.Canvas.TextOut(PaperWorkRect.Left, PaperWorkRect.Top, 'TextOut');
Printer.EndDoc;

You can use TPrinterDialog to let the user choose the paper. Printer.papersize.papername will be automatically updated.

I am writing about this in the Lazarus book.

What I'm hoping to do is to format the page using OpenOffice and then convert this to moveto, lineto, textout, etc.

You will have a lot of difficulty to communicate with OpenOffice.

PCL uses similar methods, penup, pendown, etc; maybe I could format the page and output it to PCL and then convert the PCL to TPrinter.Canvas functions?

What is PCL?

Maybe even Postscript? I used to have the old Adobe "Postscript Cookbook". If I could just find it again...

I am building a CNC Machine, and I also need to read data from an external software. I analised Postscript and I arrived to the conclusion that it is too complex to build a Postscript interpreter (Postscript is a full programming language!).

We have decided now to build a PDF reading library for Free Pascal. We should start working on it in a few months.

Felipe Monteiro de Carvalho

Reply by email

Dave Coventry
to Felipe Monteiro de Carvalho

On Sun, Jun 22, 2008 at 7:24 PM, Felipe Monteiro de Carvalho

What do you need? Just the size of the paper?

The whole lot.
I want to write a letter to someone who's name is in a database. So It's got to say:
Dear $Title $Firstname $Surname, Re yours of the inst. $Date etc, ect. (I'm just using Perl variables to show the structure of the letter - obviously in Pascal you don't preface variables with $)

Also to print out Invioces and Reciepts.

It's actually for Student registration, letters of acceptance, Courses taken, price of each course, etc...

If you are using "normal" paper, you can let LCL calculate the size >by simply giving the paper name to it:

Mostly just A4 pages.

You will have a lot of difficulty to communicate with OpenOffice.

Yes, I realise that. I've had a look at the format of OpenOffice documents and I think it would not be trivial to convert such a document into a format that I could use to print a page with TPrinter.Canvas. That's why I was thinking of Postscript and PCL.

What is PCL?

PCL = Printer Control Language (IIRC)
It used to be the language to control old style plottters (with up to eight pens!), and I think it was an IBM standard.

I am building a CNC Machine, and I also need to read data from an external software. I analised Postscript and I arrived to the conclusion that it is too complex to build a Postscript interpreter (Postscript is a full programming language!).

Yeah, I know! I did a lot of work in Postscript some years ago, but I don't remember enough about it to confidently try and convert a PS file. The problem is that it uses a lot of recursion and popping and pushing functions onto a stack so that it becomes quite complicated to read.

However, a lot of people have done a lot of stuff with PS, so I was hoping there was something out there I could use...

We have decided now to build a PDF reading library for Free Pascal. We should start working on it in a few months.

Good luck!

Reply by email