Recent

Author Topic: Passing a filename for a Printer  (Read 3224 times)

J-G

  • Hero Member
  • *****
  • Posts: 953
Passing a filename for a Printer
« on: October 13, 2017, 03:52:10 pm »
My default 'Printer' is a .PDF creator and whilst I have no problem creating documents I have to manually specify the filename once the print-dialog appears.

I would prefer to generate the filename within the 'Print' routine so that it appears in the print-dialogue ready for minor adjustment should be appropriate.

TPrinter has a property .Filename which I can set either before or after 'Finally' - viz:
Code: Pascal  [Select][+][-]
  1. begin
  2.     with Printer do
  3.       try
  4.         BeginDoc;
  5.         [...]
  6.         FileName:=IntToStr(DataYear)+'-RAW.PDF';
  7.       finally
  8. //  could be here         FileName:=IntToStr(DataYear)+'-RAW.PDF';
  9.         EndDoc;
  10.       end;
  11. end;
  12.  

...but as yet it doesn't appear in the dialogue.

Am I asking too much? 
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: Passing a filename for a Printer
« Reply #1 on: October 13, 2017, 11:24:37 pm »
hello,
use the Title property (without .pdf) example :
Code: Pascal  [Select][+][-]
  1. begin
  2.     with Printer do
  3.       try
  4.         BeginDoc;
  5.         [...]
  6.         Title:=IntToStr(DataYear)+'-RAW';
  7.       finally
  8. //  could be here         FileName:=IntToStr(DataYear)+'-RAW.PDF';
  9.         EndDoc;
  10.       end;
  11. end;
  12.  

Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

J-G

  • Hero Member
  • *****
  • Posts: 953
Re: Passing a filename for a Printer
« Reply #2 on: October 14, 2017, 02:14:23 am »
use the Title property (without .pdf)
Fantastic JP - Thanks  -  works exactly as I hoped.

I ought to have looked deeper into the properties but 'Filename' was the most obvious (to my mind anyway!)

Why don't we have a 'smiley' with applause ? 
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

J-G

  • Hero Member
  • *****
  • Posts: 953
Re: Passing a filename for a Printer
« Reply #3 on: October 14, 2017, 09:58:44 am »
Maybe I spoke too soon  :(

Yes, it put the filename (Title) in the dialogue at my first test, but this morning I added the code to the rest of the 'Print' procedures and find that the first 'print' request shows a blank and subsequent requests show the previous filename  %)   
-  Like Ronnie Cobet on Mastermind answering the question before the one being asked  :D  (some of you may have seen that 2 Ronnies Sketch).

I have some commitments this morning so I'll investigate further shortly and report back.
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

J-G

  • Hero Member
  • *****
  • Posts: 953
Re: Passing a filename for a Printer
« Reply #4 on: October 14, 2017, 01:54:16 pm »
Sorted !

The 'Title' needs to be assigned 'outside' or 'prior' to the 'Try-Finally' block ...
Code: Pascal  [Select][+][-]
  1. begin
  2.     Printer.Title:= IntToStr(DataYear)+'-RAW';
  3.     with Printer do
  4.       try
  5.         BeginDoc;
  6.          [...]
  7.       finally
  8.         EndDoc;
  9.       end;
  10.   end;
  11.  
As it happens, in all of my [Print] routines the title will be known at this stage, but there could be a time when it might need to be evaluated during the print run. Does anyone have an opinion about how this might be achieved?
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

lstenberg

  • New member
  • *
  • Posts: 9
Re: Passing a filename for a Printer
« Reply #5 on: May 29, 2019, 05:31:14 pm »
Hi,
Tried out this last approach in a very similar context and on my Mint 19.04 box but it ended up with phony,arbitrarily extensions seemingly coming from the spooler. If I keep Printer.Title short ( a few characters) the default spooler extension seems to be: $USER_PDF-job_<job no>.pdf
« Last Edit: May 29, 2019, 11:36:27 pm by lstenberg »

J-G

  • Hero Member
  • *****
  • Posts: 953
Re: Passing a filename for a Printer
« Reply #6 on: May 30, 2019, 08:32:28 am »
Hi,
Tried out this last approach in a very similar context and on my Mint 19.04 box but it ended up with phony,arbitrarily extensions seemingly coming from the spooler. If I keep Printer.Title short ( a few characters) the default spooler extension seems to be: $USER_PDF-job_<job no>.pdf
Regrettably I can't suggest a solution since I only code for Windows - even though the thread doesn't mention that anywhere.
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

lstenberg

  • New member
  • *
  • Posts: 9
Re: Passing a filename for a Printer
« Reply #7 on: May 30, 2019, 10:45:45 am »
Hi J-G,
I tested my code on Win10 using CutePDF printer driver and then it works! The exact contents of Printer.Title is suggested for filename in the pop-up file menu. But if I use 'Microsoft Print to PDF' as PDF printer driver, Printer.Title is ignored and suggested filename is empty.

ps: Actually, my Win10 trials hints at a root cause for my other post on 'Multiple page PDF..' in this forum. See this.

J-G

  • Hero Member
  • *****
  • Posts: 953
Re: Passing a filename for a Printer
« Reply #8 on: May 31, 2019, 11:13:30 am »
Hi J-G,
I tested my code on Win10 using CutePDF printer driver and then it works! The exact contents of Printer.Title is suggested for filename in the pop-up file menu. But if I use 'Microsoft Print to PDF' as PDF printer driver, Printer.Title is ignored and suggested filename is empty.
Ah  -  I avoid M$ offerings whenever there is an alternative so have been using CutePDF for many years. Never had a problem with it.
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

lstenberg

  • New member
  • *
  • Posts: 9
Re: Passing a filename for a Printer
« Reply #9 on: May 31, 2019, 11:43:06 am »
Good strategy   ;D Thanks for relating to my problem  ::)

 

TinyPortal © 2005-2018