Solved

printing files

Posted on 2000-02-17
3
133 Views
Last Modified: 2010-04-04
How can i print file on printer that runs under win95 or winnt,how to print text at all on printer.(textualfile,bmp)
is there some parametars that are good to know when printing.I would like an example.I know this answer will give you only 15 points,but please help.I am just an ordinary begginer.Thank you very much.
                   M@rko
0
Comment
Question by:marko_svaljek
3 Comments
 
LVL 5

Accepted Solution

by:
TheNeil earned 10 total points
ID: 2532035
To print a standard text file try doing the following:

Printer.BeginDoc;
lh := Printer.Canvas.TextHeight('Aj');
max_lines := Printer.PageHeight DIV lh;
iCount := 0;

AssignFile(data_in, <filename>);
Reset(data_in);
WHILE NOT(EOF(data_in))
DO
BEGIN
  READLN(data_in, text_str);
  Printer.Canvas.TextOut(0, lh * iCount, text_str);
  iCount := iCount + 1;
  IF iCount > max_lines
  THEN
  BEGIN
    iCount := 0;
    Printer.NewPage;
  END;
END;
Printer.EndDoc;
CloseFile(data_in);

What this will do is simply load lines of text from your text file and send them to the printer. Delphi handles all of the printer side of things for you.

Be warned, this example doesn't do anything like text wrapping or the like but does show you how to easily get text onto the printed page, how to position text on the page, how to create a print job, and how to print over several pages.

If you need any more then just ask.

The Neil

PS Make sure that you add the Printers unit to your USES list
0
 
LVL 6

Expert Comment

by:edey
ID: 2532230
or

with TRichedit.create(application) do
begin
//set dimensions
     LoadFromFile(file_name);
     print(some_caption);
     free;
end;


and you can use the TPrinter object to set page size & margins (or have the user do it with a TPrinterSetup dialog)


GL
Mike
0
 

Author Comment

by:marko_svaljek
ID: 2535844
Thank you very much!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now