[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Custom design printing page

Posted on 2010-01-06
6
Medium Priority
?
766 Views
Last Modified: 2013-11-23
My question is the following:

I try to create a program, which should include a design page, for people to design their own print page. In short terms, the look of the page to be printed.

A couple of items that should be possible to add (through right mouse button or drag-and-drop) are:
- Header (logo).
- Title.
- Text.
- Footer (text or something else).

How can I do this?

Please help.
0
Comment
Question by:delphibeginner
  • 3
  • 2
6 Comments
 
LVL 7

Expert Comment

by:twinsoft
ID: 26189179
Hi, you should create the design form in your app by using a TImage component and draw on its canvas. Then you print this by assigning your canvas to the printer canvas and use begindoc and enddoc.

uses Printers;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
 Image1.Canvas.TextOut(1, 1, 'Demo Printing');
 Printer.PrinterIndex := Printer.Printers.IndexOf('PrinterName'); // Your printer name
 Printer.BeginDoc;
 Printer.Canvas.Assign(Image1.Canvas);
 Printer.EndDoc;
end;
0
 
LVL 1

Author Comment

by:delphibeginner
ID: 26189272
Thanks for the reply.

The items that should be possible to add to the form are not pre-set, for example, the title is a title from a "song" which is in a database, so everytime people want to print they select a "song" to print and it comes out the way they designed the print page.

Is this also possible with TImage?
0
 
LVL 7

Accepted Solution

by:
twinsoft earned 126 total points
ID: 26189344
Hi again, the code i sent you was just an example of how to print a canvas. Now, in order to design on to the canvas you have to write code in your app to create a designing enviroment (some thing like the paint application of windows) from where the users would design their own image and then print it. To do this you would have to use dragover/dragend and onmousedown/up events. For example drag a song title from a list (a dbgrid) and drop it on the image. Then code the onenddrag event of TImage to draw the title on the image at the point where the user droped it... This is a trivial task...

Good luck...
0
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.

 
LVL 1

Author Comment

by:delphibeginner
ID: 26289099
Thanks for the reply, sorry I took so long to respond.

I've been looking on the internet for samples to create a custom print page. I saw a sample (not for delphi) that you have a page, with a couple of buttons and text(labels) beneath the design page. I could click on a button or textlabel and drag it to the design page, the button remains below the design page but makes sort of a copy which I can place all around the design page.

Also what I would like but didn't found anything for it is: Clicking right mouse on the design page a click in the popup menu what I would like to add (text, picture, etc). Is there an example (delphi) for the 2 things I described here.

Many thanks.
0
 
LVL 2

Assisted Solution

by:BlueVD
BlueVD earned 124 total points
ID: 27373782
Hello,
The best solution I ever found for the printing problems in Delphi was to use... anything else but Delphi to print, specifically, I use Internet Explorer (or it's Delphi implementation, TWebBrowser);
You can easely create a HTML page right inside Delphi or use an existing HTML page and just insert the right values in it and then print the page.
You can learn HTML in minutes compared to advanced Delphi printing whitch might take days.

Here's a quick demo (note that I use the print with dialog function in this demo, but you can use any of them, jusr remember to include them in your app; note2: this is the full unit source so that you can copy-paste it in delphi and try it right out):

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, OleCtrls, SHDocVw, mshtml;
//*****************READ THIS!!!*****************
//SHDocVw is needed for TWebBrowser
//mshtml is needed for IHTMLDOcument and other HTML related functionality
//don't forget to include them!!!
//*************************************************

type
  TForm1 = class(TForm)
    wb1: TWebBrowser;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure wb1DocumentComplete(ASender: TObject; const pDisp: IDispatch;
      var URL: OleVariant);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

// print directly without printer dialog
procedure WBPrintNoDialog(WB: TWebBrowser) ;
var
   vIn, vOut: OleVariant;
begin
   WB.ControlInterface.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, vIn, vOut) ;
end;

//call the printer dialog
procedure WBPrintWithDialog(WB: TWebBrowser) ;
var
   vIn, vOut: OleVariant;
begin
   WB.ControlInterface.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER, vIn, vOut) ;
end;

// Print Preview
procedure WBPrintPreview(WB: TWebBrowser) ;
var
   vIn, vOut: OleVariant;
begin
   WB.ControlInterface.ExecWB(OLECMDID_PRINTPREVIEW, OLECMDEXECOPT_DONTPROMPTUSER, vIn, vOut) ;
end;

//Call page setup dialog
procedure WBPrintPageSetup(WB: TWebBrowser) ;
var
   vIn, vOut: OleVariant;
begin
   WB.ControlInterface.ExecWB(OLECMDID_PAGESETUP, OLECMDEXECOPT_PROMPTUSER, vIn, vOut) ;
end;

procedure TForm1.Button1Click(Sender: TObject);
var wnd:IHTMLBodyElement2;
begin
  wb1.Navigate('about:blank');
end;

procedure TForm1.wb1DocumentComplete(ASender: TObject; const pDisp: IDispatch;
  var URL: OleVariant);
var doc:IHTMLDocument2;
begin

  doc:=IHTMLDocument2(wb1.Document);
  doc.body.innerHTML:='<h2>Test print...</h2><img src="http://http://www.google.com/intl/en_ALL/images/logo.gif">';
  WBPrintWithDialog(wb1);
end;

end.


0
 
LVL 1

Author Closing Comment

by:delphibeginner
ID: 31673406
none
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month18 days, 22 hours left to enroll

834 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