Implement a PrintToFile capability

Hi,

I'm looking at a way to implement a Print-To-File capability for my
application. Here are my wonderings:

- The TPrintDialog has the poPrintToFile option allowing to show the Print
To File check box. That's good for the user to be able to choose to do so
(good start).

- The TPrinter object does no support printing to files. DocInfo contains a
lpszOutput param but in the TPrinter.BeginDoc, it is always set to Nil. I'm
wondering if it would actually be very simple to implement a Print-To-File
function by simply having the DocInfo.lpszOutput be initialised for the call
to Windows's StartDoc and let the printer driver do the rest. Am I correct
here? I suggested to QC to add a TPrinter.OutputFilename property for that,
I hope I'm not wrong here.

- Also, I found that you can have a printer port set to "File:" so that the
printer prints to a file. When I tried that, it seemed to me that the
printer drivers was asking for a filename (the one I had was an ugly little
dialog with a simple Edit and OK, Cancel buttons, quite unappealing!!!) then
created successfully the file print-out (as postscript file, which I'm
after). My questions regarding this one: for the Print-To-File to work (as
described in my second point above), do I have to also have the printer port
set to "File:" or is this behaviour emulated with DocInfo.lpszOutput set to
a valid filename (what I mean is: if StartDoc has a DocInfo.lpszOutput
specified to a filename, would the print-out be redirected to the file even
if the printer port is set to "LPT1:" rather than "File:")? I'd guess that
both methods (set port to "File:" or have DocInfo.lpszOutput) are
independent ways of doing the same thing but I'm not sure. And in this case,
it means the VCL stops us from using the second because TPrinter does not
support the DocInfo.lpszOutput param.

Thanks for any clarifications.
David.
0
David
8/15/2008 5:53:09 PM
embarcadero.delphi.nativeapi 1236 articles. 1 followers. Follow

2 Replies
963 Views

Similar Articles

[PageSpeed] 48
Get it on Google Play
Get it on Apple App Store

"David TETARD" <No@Spam.com> wrote in message 
news:3353@forums.codegear.com...

> - The TPrinter object does no support printing to files. DocInfo contains
> a lpszOutput param but in the TPrinter.BeginDoc, it is always set to Nil.
> I'm wondering if it would actually be very simple to implement a
> Print-To-File function by simply having the DocInfo.lpszOutput be
> initialised for the call to Windows's StartDoc and let the printer driver
> do the rest.

Looks like it.  In which case, you could just call StartDoc() and related 
functions manually and not use TPrinter at all.


Gambit
0
Remy
8/15/2008 8:21:03 PM
David TETARD wrote:

> Hi,
> 
> I'm looking at a way to implement a Print-To-File capability for my
> application. Here are my wonderings:
> 
> - The TPrintDialog has the poPrintToFile option allowing to show the
> Print To File check box. That's good for the user to be able to
> choose to do so (good start).
> 
> - The TPrinter object does no support printing to files. DocInfo
> contains a lpszOutput param but in the TPrinter.BeginDoc, it is
> always set to Nil. I'm wondering if it would actually be very simple
> to implement a Print-To-File function by simply having the
> DocInfo.lpszOutput be initialised for the call to Windows's StartDoc
> and let the printer driver do the rest. Am I correct here? I
> suggested to QC to add a TPrinter.OutputFilename property for that, I
> hope I'm not wrong here.


You can work around the current limitation of TPrinter this way:

Procedure StartPrintToFile( filename: String );
var
  CTitle: array[0..31] of Char;
  DocInfo: TDocInfo;
begin
  With Printer Do Begin
    BeginDoc;
    { Abort job just started on API level. }
    EndPage( Canvas.handle );
    Windows.AbortDoc( Canvas.handle );

    { Restart it with a print file as destination. }
    StrPLCopy(CTitle, Title, SizeOf(CTitle) - 1);
    FillChar(DocInfo, SizeOf(DocInfo), 0);
    with DocInfo do
    begin
      cbSize := SizeOf(DocInfo);
      lpszDocName := CTitle;
      lpszOutput := PChar(filename);
    end;
    StartDoc(Canvas.handle, DocInfo);
    StartPage(Canvas.handle);
  End;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  StartPrintToFile('C:\temp\temp.prn');
  try
    Printer.Canvas.TextOut( 100, 100, 'Hello World.' );
  finally
    Printer.endDoc;
  end;    
end;


-- 
Peter Below (TeamB)  
Don't be a vampire (http://slash7.com/pages/vampires), 
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com
0
Peter
8/16/2008 11:40:55 AM
Reply:

Similar Artilces:

Is there Delphi implementation (For Older Delphi also) of zlib 1.2.4
Hello, Does anyone have zlib 1.2.4 version of Delphi, with new Objects, maybe pZLibEx (http://www.dellapasqua.com/delphizlib/) port with compiled Objects? -TP- > {quote:title=Tommi Prami wrote:}{quote} > Hello, > > Does anyone have zlib 1.2.4 version of Delphi, with new Objects, maybe > pZLibEx (http://www.dellapasqua.com/delphizlib/) port with compiled Objects? > > -TP- \zlib-1.2.4\contrib\delphi\zlib.pas On 4.4.2010 13:43, Ralf Stocker wrote: >> {quote:title=Tommi Prami wrote:}{quote} >> Hello, >> >> Does anyone have zl...

SAML implementation in Delphi
Hi All, how to implement SAML Authentication in a Client-Server Delphi application ? is there any component for this in Delphi..? Hi All, Could anyone please reply about How to implement the SAML in web based Delphi application? Are there any components available for that to implement? Thanks in advance, Srividya. ...

Delphi and Delphi for .Net
It seems that Delphi for .Net is slower than Delphi Win32 native applicaiton. I would like to know is it true all .Net application is slower than Win32 native applicaiton or it is Delphi for .Net only. Your information is great appreciated, Inung On 2011-06-21 18:20:17 +0100, Inung Huang said: > It seems that Delphi for .Net is slower than Delphi Win32 native applicaiton. > I would like to know is it true all .Net application is slower than > Win32 native applicaiton or it is Delphi for .Net only. If you are only running the code in the application once then, yes, yo...

DBTools API: Looking for Delphi implementation
I'm trying to implement the DBTool-function DB_Info in my application. But I'm not so familiar with C/C++ to translate the C-header files without getting access violations. My question: Is there anyone who has experience with Delphi and the DBTools/DBInit function? Most of the information available from DB_Info is available by querying SYS.SYSINFO and by using database property functions. In ASA 6.0.3 and above, the sa_table_page_usage stored procedure can be used to get page usage information. Martin Neumann wrote in message ... >I'm trying to implement the D...

Delphi MultiMap implementation based on TDictionary?
Hi guys. Delphi 2009 here so I can not use nice collection classes from http://code.google.com/p/delphi-coll/wiki/CollectionDetails . For quite some time I've used TDictionary<string, TMyClass> and it was ok for my needs, but now I need to store many values for the same key. I would like to avoid to write everything from scratch so I thought I will wrap TDictionary in my own class or inherit from TDictionary. Hoever both approaches seems to fail because I can not write my own enumerator. To write an enumerator I would need to have an access to Dictionary.FItems which is pri...

Foobar2000 Tagz
Hi, I'm wondering if something like this has been implemented in Delphi/Pascal? Or maybe there is a wrapper for some Tagz C/C++ library? Thanks. ...

how to implement delphi style selection in richedit?
Hi, In delphi code editor, you can start rectangular selection via mouse by holding Ctrl+Alt pressed. Like in this snapshot: http://i56.tinypic.com/wjwdus.png What is the way of doing same thing with TRichEdit? Thank you. "Mehmet Fide" <off@b.net> wrote in message news:379486@forums.embarcadero.com... > What is the way of doing same thing with TRichEdit? RichEdit controls do not support that. The code editor uses a third-party custom control (TSynEdit), not a RichEdit. -- Remy Lebeau (TeamB) ...

Google Protocol Buffers implementation in Delphi
Google Protocol Buffers implementation in Delphi David J Butler's new masterpiece http://fundementals.sourceforge.net/dl.html ...

Will Delphi implement "Future"
Hi, Just saw this page: http://wiki.oxygenelanguage.com/en/Futures "Futures are a new language concept designed to facilitate Parallel Computing and developing applications that scale well on multi-core and multi-CPU systems. A future is a strongly typed variable that represents a value that might or might not have been calculated yet, but is guaranteed to be (made) available when needed. Consider the following snippet of pseudo code that calculates the Sum of values in a binary tree: method ThreeNode.Sum: Int32; begin var l: Int32 := Left.Sum; var r: Int32 := Ri...

Is iOS printing implemented in Delphi XE5? [Edit]
Delphi XE4 has a empty FMX.Printers.iOS.pas implementation, is this solved in the new version? Edited by: Martijn Van der Kooij on Sep 12, 2013 12:13 AM I asked this question before as well, here is what I found out.. Only support at the moment, is to get what you want to print into an image and then use the Sharesheet -> print functionality. There are demo's of this on youtube for ios and android. So very limited printing support available, no sign or comment (I asked them) from FMX Fastreports for a report printing component for Firemonkey mobile. ...

Implement DispInterface in Delphi. Converting an VBA example.
I have an VBA example of a dispinterface (EventsForm.frm) that I need to implement in Delphi. The Excel events form has "Implements ILog". and the following code. I am assuming the "Me" is the excel form that has implemented ILog. I've tried several thing in Delphi but with no success. I have both M-DesktopClient (on MainForm) and DumpWin (on EventsForm) working from the type libraries. Private Sub Form_Load() MainForm.m_DesktopClient.BindLog Me End Sub Some excerpts of the files are bellow. Thanks for any help Wayne === from EventFo...

Comet being implemented within the Delphi IW tools
Delphi Sports Fans, There is considerable discussion on the Web regarding Comet, which is the server side complement to Ajax. This capability is seemingly being implemented in the various web based frameworks. I for one would like to see this capability implemented within the Delphi world, specifically within Intraweb. I just wondering if this is a pipe dream. Anyone have any thoughts on the subject? Regards, Monte Carver Yeah, given exponential growth of web/browser technology these days, especially pushed by GOOG, Comet (and ajax for that matter) has a shortened life...

Missing implementation of TFileTypeItem.Assign in Delphi XE3
Hi Shouldn't TFileTypeItem have an implementation of the Assign method? I get an "Cannot assign a TFileTypeItem to a TFileTypeItem" in the designer when using inheried forms containing a TPlatformFileSaveDialog component. Regards, Svend Hi, I'm also having this problem, anybody ever faced this ? Thanks in advance. NF > {quote:title=Svend Meyland Nicolaisen wrote:}{quote} > Hi > > Shouldn't TFileTypeItem have an implementation of the Assign method? I get an "Cannot assign a TFileTypeItem to a TFileTypeItem" in the designer wh...

How to implement IEnumerable<T> in Delphi 2009?
e.g. TCollectionBase<T> = class(TInterfacedObject, IEnumerable<T>) // IEnumerable<T> inherits from IEnumerable //... end; Thanks! Baoquan Zuo wrote: > e.g. > > TCollectionBase<T> = class(TInterfacedObject, IEnumerable<T>) // IEnumerable<T> inherits from IEnumerable > //... > end; Which part of the task is giving you trouble? Take the list of methods that the interface provides, and then implement them. -- Rob Rob Kennedy wrote: > Baoquan Zuo wrote: > > e.g. > > > > TCollectionBase<T&...

Web resources about - Implement a PrintToFile capability - embarcadero.delphi.nativeapi

GNOME 3.8 Is Moving Along On Its New Features
Phoronix is the leading technology website for Linux hardware reviews, open-source news, Linux benchmarks, open-source benchmarks, distribution ...

Resources last updated: 12/7/2015 8:38:27 PM