Solved

Printing to File without the filename prompt

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi XE10, MySQL Query 4 126
Best Firemonkey component pack 1 87
TEMBEDDEDWB how can i change its user agent ? 8 48
Convert MS Word document to a PDF file 9 63
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…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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

12 Experts available now in Live!

Get 1:1 Help Now