I'm changing the way to print a PDF in my software (vs ...another software) and I'm using now virtual printer.
My software runs in terminal server.
First, I'm using like this:
Code: Select all
// Global var
var
PDFPFactory: CPXCControlEx = nil;
PDFPrinter: CPXCPrinter = nil;
function MyPrinterName: string;
begin
Result := 'PDF-XCHANGE_' + UserName + '_' + IntToStr( Application.Handle );
end;
procedure PDFInit;
begin
if not Assigned( PDFPFactory ) then
PDFPFactory := CoCPXCControlEx.Create;
if not Assigned( PDFPrinter ) then
begin
prnt := PDFPFactory.Printer[ '', MyPrinterName, SPdfXTools_Key, SPdfX_CodeDev];
PDFPrinter:= IDispatch(prnt) as CPXCPrinter;
Printer.Refresh;
end;
end;
procedure PDFDone;
begin
if not Assigned( PDFPFactory ) then Exit;
PDFPFactory.RemoveOrphanPrinters( '', MyPrinterName);
PDFPrinter := nil;
PDFPFactory := nil;
Printer.Refresh
end;
procedure PDFSetOptions;
begin
PDFPrinter.Option['Save.File'] := MyFile;
// ... other options
end;
1. Call PDFInit one time in session, call PDFSetOptions and Print Process at each print, then call PDFDone at the end of program.
2. Call PDFInit, then PDFSetOptions, then Print Process, then PDFDone, each Time User prints.
Advantage of the 1 is the speed when there are lots of print process, BUT other users see all the virtual printers of all users... not very clean
Advantage of the 2 is that the virtual printer appear only when a user prints, so list of printers on TSE is (almost) always clean.
Before, I was using (... Don't know if I can tell here), and only one virtual printer was installed on TSE visible by all user. At the moment of printing I set options in registry, in (HKEYCURRENTUSER section), then I started the print process. No Virtual extra-virtual printer visible by user, and speed was great because the only thing to do was to write in the registry before printing.
Is there a 3rd way: using virtual PDF XChange printer like I said just above ?
Is my code is the right one? (it is correct it runs perfectly with several users actually, but is it the good solution with your product ?)
Thank you in advance
Serge