Solved

Printing to File without the filename prompt

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 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