RB ignores my printer selection.
Hi,
Using RB14.08, Delphi 2009.
I'm using the following code to print from an archive file to a specific
printer (this is from a test application, rather than production code):
ArchiveReader1.AllowPrintToFile := false;
ArchiveReader1.DeviceType := 'Printer';
ArchiveReader1.ShowCancelDialog := false;
ArchiveReader1.ShowPrintDialog := false;
ArchiveReader1.ArchiveFileName := ExtractFilePath(TempFileName) + sr.Name;
ArchiveReader1.TextFileName := ExtractFilePath(TempFileName) +
ChangeFileExt(sr.Name, '.pdf');
ArchiveReader1.PDFSettings.FontEncoding := feUnicode;
ArchiveReader1.PDFSettings.EmbedFontOptions := [efUseSubset];
ArchiveReader1.PrinterSetup.PrinterName := edPrinterPath.Text;
ArchiveReader1.Print;
sr.name is simply the result of a FindNext call (we're iterating through
archive files and printing them).
However, it's ignoring my choice of printer and always sending the
document to the default printer instead. If I trace through the code I find:
1. The PrinterSetup.PrinterNames list *does* contain the name of the
printer I want to print to.
2. The PrinterSetup.PrinterName variable does get set to the correct
printer.
3. As soon as Print is called the PrinterName has reverted to the name
of the default printer and the print job is sent to that printer instead
of the one I selected.
4. If I change ShowPrintDialog to true then the print dialog shows with
the default printer selected (despite the fact that another one has been
set in the code). If I change this selection to be the desired printer
then in this case the print job *does* get sent to the correct printer.
Can someone please suggest why my printer selection is being ignored?
The printer is available, windows can print to it and it works if the
print dialog is displayed.
Thanks,
Steve Branley
Using RB14.08, Delphi 2009.
I'm using the following code to print from an archive file to a specific
printer (this is from a test application, rather than production code):
ArchiveReader1.AllowPrintToFile := false;
ArchiveReader1.DeviceType := 'Printer';
ArchiveReader1.ShowCancelDialog := false;
ArchiveReader1.ShowPrintDialog := false;
ArchiveReader1.ArchiveFileName := ExtractFilePath(TempFileName) + sr.Name;
ArchiveReader1.TextFileName := ExtractFilePath(TempFileName) +
ChangeFileExt(sr.Name, '.pdf');
ArchiveReader1.PDFSettings.FontEncoding := feUnicode;
ArchiveReader1.PDFSettings.EmbedFontOptions := [efUseSubset];
ArchiveReader1.PrinterSetup.PrinterName := edPrinterPath.Text;
ArchiveReader1.Print;
sr.name is simply the result of a FindNext call (we're iterating through
archive files and printing them).
However, it's ignoring my choice of printer and always sending the
document to the default printer instead. If I trace through the code I find:
1. The PrinterSetup.PrinterNames list *does* contain the name of the
printer I want to print to.
2. The PrinterSetup.PrinterName variable does get set to the correct
printer.
3. As soon as Print is called the PrinterName has reverted to the name
of the default printer and the print job is sent to that printer instead
of the one I selected.
4. If I change ShowPrintDialog to true then the print dialog shows with
the default printer selected (despite the fact that another one has been
set in the code). If I change this selection to be the desired printer
then in this case the print job *does* get sent to the correct printer.
Can someone please suggest why my printer selection is being ignored?
The printer is available, windows can print to it and it works if the
print dialog is displayed.
Thanks,
Steve Branley
This discussion has been closed.
Comments
When assigning the PrinterName, it is best to use the
PrinterSetup.PrinterNames property to do so. This way you can be
absolutely sure you are assigning a valid name (which needs to be exact).
Try something like the following as a test:
ArchiveReader1.PrinterSetup.PrinterName :=
ArchiveReader1.PrinterSetup.PrinterNames[1];
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Tried what you suggested, makes absolutely no difference. I set the
printer name and it still prints to the default printer. If I show the
print dialog the default printer is shown. If I change it to my desired
printer then it does behave as expected.
Steve
I'm sorry, I somehow didn't register that you were using an
ArchiveReader. The method of setting the PrinterSetup when using an
ArchiveReader is a bit different than with a report.
When using an ArchiveReader, you will want to use the
OnInitializePrinterSetup event to alter any PrinterSetup properties.
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com