Solved

Printing to File without the filename prompt

Posted on 2003-12-05
3
630 Views
Last Modified: 2010-05-18
Greetings All.

I know that this question has been approached about 50 times acording to the search results.

With one of the results, Specifically
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_10156900.html

The problem is that this is for D4 and I use D6.

I would like to print to file as I need to convert a document to Postscript before I can send it to Hylafax for faxing.

If you need more info please ask.

Thanks in advance

RYan

0
Comment
Question by:SapphireIce
  • 2
3 Comments
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 500 total points
ID: 9887795
--> The problem is that this is for D4 and I use D6.

Well, since D5 (i tested it succesfully in d5 -d6 - d7) you must follow the above instructions...so create PrnPage.pas as follows...
unit PrnPage;
interface
var FileNameToPrintTo : Pointer;
implementation
begin
  FileNameToPrintTo := nil;
end.

...then copy it and Printers.pas to a new directory...
Now let's see the D5-D6-D7 code changes needed in Printers.pas:
First add to the uses clause PrnPage.
Then search for the TPrinter.BeginDoc procedure...it must be changed as follows:
procedure TPrinter.BeginDoc;
var
  DocInfo: TDocInfo;
begin
  CheckPrinting(False);
  SetState(psHandleDC);
  Canvas.Refresh;
  TPrinterCanvas(Canvas).UpdateFont;
  FPrinting := True;
  FAborted := False;
  FPageNumber := 1;
  FillChar(DocInfo, SizeOf(DocInfo), 0);
  with DocInfo do
  begin
    cbSize := SizeOf(DocInfo);
    lpszDocName := PChar(Title);
    lpszOutPut := FileNameToPrintTo; //this is the new added line
  end;
  SetAbortProc(DC, AbortProc);
  StartDoc(DC, DocInfo);
  StartPage(DC);
end;

Well, save all and close all.
Open Tools-Environment Options-Library...add to the library path the path of the new dir containing Printers.pas and PrnPage.pas then move it to the first position (it must be found the first by delphi to skip the original Printers.pas)...
Now Ok, close Delphi and reopen....
Then in a new project:

var
  Form1: TForm1;
{$IFNDEF WIN32}
const MAX_PATH = 144;
{$ENDIF}

implementation
uses Printers, PrnPage;
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  lpPrnFile : pChar;
begin
  GetMem(lpPrnFile, MAX_PATH +1);
  try
    StrPCopy(lpPrnFile, 'C:\TestIt.Prn');
    FileNameToPrintTo := @lpPrnFile^;
    with Printer do begin
      BeginDoc;
      Canvas.TextOut(10, 10, 'This is a Test Prn File');
      EndDoc;
    end;
    FileNameToPrintTo := nil;
  finally
    FreeMem(lpPrnFile, MAX_PATH +1);
  end;
end;

Rebuild All at the first Build to create the new Printers and PrnPage dcu.

And here you are....you're printing to a prn file without prompt...

F68 ;-)
0
 

Author Comment

by:SapphireIce
ID: 9894838
Yee Haa!

Thanks so much.

It works perfectly.

Have a great Christmas and New Year!

:-)

Regards

Ryan
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 9895766
Best wishes to you too :)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 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

20 Experts available now in Live!

Get 1:1 Help Now