Solved

Printing in Delphi..

Posted on 2002-07-08
2
265 Views
Last Modified: 2010-04-04
Does anybody know or has an example on how to print something graphical in delphi? Please help me! TNX
0
Comment
Question by:ssdjgru1
2 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7137274
you've a canvas on the printer-object,
there you can draw your graphic as you need

meikl ;-)
0
 
LVL 7

Accepted Solution

by:
Cynna earned 200 total points
ID: 7137299
ssdjgru1,

If you have something drawn on a TPicture or TBitmap you can print it using following code (based on code posted on http://www.efg2.com/Lab/Library/Delphi/Printing/index.html):

COPY/PASTE:
----------------

procedure PrintBitmap(Bitmap:  TBitmap;
                      TopOfPagePercent, LeftMarginPercent, PrintedImageWidthPercent: Integer);
var
    BitmapHeader      :  pBitmapInfo;
    BitmapImage       :  POINTER;
    HeaderSize        :  DWORD;
    ImageSize         :  DWORD;
    FromLeftMargin    :  INTEGER;
    PrintedImageWidth :  INTEGER;
    FromTopOfPage     :  INTEGER;
    PrintedImageHeight:  INTEGER;

begin
 try
    Printer.BeginDoc; // Uses printers
    FromTopOfPage      := MulDiv(Printer.PageHeight, TopOfPagePercent  ,100);
    FromLeftMargin     := MulDiv(Printer.PageWidth , LeftMarginPercent ,100);
    PrintedImageWidth  := MulDiv(Printer.PageWidth , PrintedImageWidthPercent ,100);
    // Maintain aspect ratio
    PrintedImageHeight := Bitmap.Height*PrintedImageWidth div Bitmap.Width;
    GetDIBSizes(Bitmap.Handle, HeaderSize, ImageSize);
    GetMem(BitmapHeader, HeaderSize);
    GetMem(BitmapImage,  ImageSize);
    GetDIB(Bitmap.Handle, Bitmap.Palette, BitmapHeader^, BitmapImage^);
    StretchDIBits(Printer.Canvas.Handle,
                  FromLeftMargin, FromTopOfPage,          // Destination Origin
                  PrintedImageWidth, PrintedImageHeight,  // Destination Width & Height
                  0, 0,                                   // Source Origin
                  Bitmap.Width, Bitmap.Height,            // Source Width & Height
                  BitmapImage,
                  TBitmapInfo(BitmapHeader^),
                  DIB_RGB_COLORS,
                  SRCCOPY)
 finally
    FreeMem(BitmapHeader);
    FreeMem(BitmapImage);
    Printer.EndDoc;
 end;
end;




DEMO:
--------

(place Image1, Button1 on the form)

procedure TForm1.Button1Click(Sender: TObject);
begin
  Image1.Picture.LoadFromFile('C:\Program Files\Common Files\Borland Shared\Images\Splash\256Color\handshak.bmp');
  PrintBitmap(Image1.Picture.Bitmap, 1, 1, 80);
end;
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to convert wav to mp3 in delphi 9 200
Delphi cmd execution 6 60
Magic Software info 18 130
How to renew a Delphi rad-studio licence? 5 64
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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

770 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