?
Solved

*Copying* a file direct to printer

Posted on 1998-06-03
5
Medium Priority
?
240 Views
Last Modified: 2010-04-06
Hi

I am using D1 with WFW 3.11.

I need to be able to copy files that have been saved as "Print to File", directly to the Printer.

On my form I have an OpenDialog and a PrintDialog, and the user can select multiple files.  Originally I adapted the CopyFile routine from the FMXUtils unit and set the destination to LPT1.  That worked fine.  However the main user of the ap has asked that the program be changed to allow access to different printers.

The PrintDialog gives me the "long" name of the selected printer which I can access from the TPrinter object, but my question is, what do I set the destination name to in the CopyFile routine?
0
Comment
Question by:jdthedj
[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
  • 2
5 Comments
 

Accepted Solution

by:
jhun earned 400 total points
ID: 1349984
Here is a code fragment that should help you. (This works only under windows 16 bit !)

unit Esc1;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{ add the printers unit }
uses
   Printers;

{$R *.DFM}

{ declare the "PASSTHROUGH" structure }
type TPrnBuffRec = record
  BuffLength : word;
  Buffer : array [0..255] of char;
end;


procedure TForm1.Button1Click(Sender: TObject);
var
  Buff : TPrnBuffRec;
  TestInt : integer;
  s : string;
begin

{ Test to see if the "PASSTHROUGH" escape is supported }
  TestInt := PASSTHROUGH;
  if Escape(Printer.Handle,
            QUERYESCSUPPORT,
            sizeof(TestInt),
            @TestInt,
            nil) > 0 then begin

  { Start the printout }
    Printer.BeginDoc;

  { Make a string to passthrough }
    s := ' A Test String ';

  { Copy the string to the buffer }
    StrPCopy(Buff.Buffer, s);

  { Set the buffer length }
    Buff.BuffLength := StrLen(Buff.Buffer);

  { Make the escape}
    Escape(Printer.Canvas.Handle,
           PASSTHROUGH,
           0,
           @Buff,
           nil);

  { End the printout }
    Printer.EndDoc;
  end;
end;

end.

The printer is selected by the printerindex property !
0
 
LVL 3

Author Comment

by:jdthedj
ID: 1349985
Hi JHun - thanks for the reply.  It doesn't seem to want to work for me, but I can see the general principle behind it.  Also, the environment in which it will need to work is Windows 95/98/NT as well as 3.11.  The files to be sent to the printer are plotter files - not text files.

I was wondering if there was any way of copying the file to the printer canvas in Delphi (by reading in chunks of it at a time).
0
 
LVL 2

Expert Comment

by:kjteng
ID: 1349986
The old dos command: "copy/b xxx.prn lpt1" may be useful for you. To call copy command in your code, use shellExecute as follows:

 strPcopy( p, ' /c copy/b  prnfile.prn lpt1');
 w:= ShellExecute( handle, 'open',
                   'command.com',
                   p,
                   'c:\',
                   sw_showminimized);

{assuming that you have command.com in c:\ and p is declared as a pchar or zerobased array. }

This may not work for 32 bits delphi. I think the equivalent API in d2/d3 is createProcess. Please check the API help if necessary.

BTW, have I tried copyfile('c:\a.prn', 'lpt1'), it does not seems to work on my pc/printer. Any idea of the reason?

0
 

Expert Comment

by:jhun
ID: 1349987
>Hi JHun - thanks for the reply.  It doesn't seem to want to >work for me, but I can see the general principle behind it.  
>Also, the environment in which it will need to work is Windows >95/98/NT as well as 3.11.  The files to be sent to the printer >are plotter files - not text files.
Each envirement has to be programmed separadly ! The code for windows 95 is different. Also microsoft has announced that passtrough support is obsolete.


>I was wondering if there was any way of copying the file to the >printer canvas in Delphi (by reading in chunks of it at a time).
When you print to the canvas you get the printerreset etc. also send to the printer, but that code already included in your file.

Gr. John
0
 
LVL 3

Author Comment

by:jdthedj
ID: 1349988
Thanks for the replies guys.  With a bit of fiddling using the abovementioned CopyFile routine I have overcome the WIN95 problem.  I was able to map the printers (on the network) to LPT1.  For WINNT there is a file called Print.exe which has a parameter for a network printer, so it looks as though I have got the job done.

JHun - although your answer didn't actually solve my problem it answered another problem I had so I am giving you the points.

KJTeng - I don't know why you couldn't get the CopyFile routine to work for you.  Maybe it's because I am printing graphics files, not test files.

Thanks again for all the help to both of you.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month12 days, 10 hours left to enroll

777 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