[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Printing in Delphi..

Posted on 2002-07-08
2
Medium Priority
?
279 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 800 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

649 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