Solved

Accessing default printer font

Posted on 1998-09-28
2
411 Views
Last Modified: 2013-12-02
This seems a bit silly, but I can't get it to work.

How do I print using the default printer font? Whenever I print using Delphi, it switches to the default windows printer font, or the font I set it to in the printer.canvas.font method, etc. Even when I use the assignprn(textfile) method, it switches the font... All I want is a dump in the default printer font.

The reason? The default font uses the old PC-8 character set. I'm trying to use an old piece of code that has boxes around the text for a report. Setting the printer.font and printer.charset doesn't seem to work. I can set the charset to ansi, but not to the old IBM PC-8 characterset, even though the printer has that set.
0
Comment
Question by:oneeye
2 Comments
 
LVL 5

Accepted Solution

by:
ronit051397 earned 50 total points
ID: 1340997
This is from Borland documents
http://www.inprise.com/devsupport/delphi/qanda/808.html

Question:

Instead of printing graphics, how can I get TPrinter to use the default resident font in the printer?

            Answer:

            Use the Windows API function GetStockObject() to retrieve the
            device default font handle, and assign it to Printer.Font.Handle.

            Example:

            uses Printers;

            procedure TForm1.Button1Click(Sender: TObject);
            var
              tm : TTextMetric;
              i : integer;
            begin
              if PrintDialog1.Execute then begin
                Printer.BeginDoc;
                Printer.Canvas.Font.Handle := GetStockObject(DEVICE_DEFAULT_FONT);
                GetTextMetrics(Printer.Canvas.Handle, tm);
                for i := 1 to 10 do begin
                  Printer.Canvas.TextOut(100,
                                         i * tm.tmHeight +
                                         tm.tmExternalLeading,
                                         'Test');
                end;
                Printer.EndDoc;
              end;
            end;


0
 

Author Comment

by:oneeye
ID: 1340998
Ah, very good. One place I forgot to check.

I am much obliged.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

708 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

17 Experts available now in Live!

Get 1:1 Help Now