Solved

*Copying* a file direct to printer

Posted on 1998-06-03
5
227 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
  • 2
  • 2
5 Comments
 

Accepted Solution

by:
jhun earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
>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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

17 Experts available now in Live!

Get 1:1 Help Now