Solved

Printing to File without the filename prompt

Posted on 2003-12-05
3
637 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
[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
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

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 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