?
Solved

Printing to File without the filename prompt

Posted on 2003-12-05
3
Medium Priority
?
639 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 23

Accepted Solution

by:
Ferruccio Accalai earned 2000 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 23

Expert Comment

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

Featured Post

Independent Software Vendors: 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month9 days, 1 hour left to enroll

765 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