I have installed the Driver under the name "FileCenter System Device". In my code, once I obtain the Printer object and check its Name property is says "FileCenter System Device (1)". Not sure why it adds the "(1)". If I then call SetAsDefaultPrinter, it seems to set the printer, but if I make a windows call to get the default printer at this time, it comes back blank or "". This is because it's the name without the "(1)" that is in my Printers and Devices list.
I have been having some issues with SetAsDefaultPrinter not working so I wanted to write some code to confirm that the Default Printer was set to FPrinter.Name before continuing with the print job. But everytime I check the Default Printer after a call to SetAsDefaultPrinter I get a empty string as the answer.
Also, if I try to set the default printer myself to the name it was installed under (that is, without the "(1)"), the printing doesn't work. It throws up the saveas dialog asking for a name, probably because it's expecting the printer with the "(1)" in the name.
See code below.
Code: Select all
procedure TPDFDriver.InitDriver;
var
ADisp: OleVariant;
begin
try
FPDFInstance := CoCPXCControlEx.Create;
if (FPDFInstance <> nil) then
begin
ADisp := FPDFInstance.Printer['', FInitPrinterName, FRegKey, FDevCode];
FPDFPrinter := IDispatch(ADisp) as CPXCPrinter;
FEventSink := TEventSink.Create(Self);
InterfaceConnect(FPDFPrinter, _IPXCPrinterEvents, FEventSink, FConnectionToken);
FConnected := True;
end;
except end;
end;
function TPDFDriver.InitializePrinter(AFileName: String; APDFMode: Cardinal;
ACompression: Boolean = True; AEmbedFonts: Boolean = True): Boolean;
var
i: Integer;
begin
Result := False;
try
FPDFPrinter.Option['Save.File'] := AFileName;
FPDFPrinter.Option['Save.SaveType'] := 'Save';
FPDFPrinter.Option['Save.RunApp'] := False;
FPDFPrinter.Option['Save.WhenExists'] := 'Overwrite';
if (APDFMode > 0) then
FPDFPrinter.Option['General.Specification'] := -1 //PDF/A-1b
else
FPDFPrinter.Option['General.Specification'] := 0;
if (Trim(AFileName) = '') then
FPDFPrinter.Option['Save.ShowSaveDialog'] := 'Yes'
else
FPDFPrinter.Option['Save.ShowSaveDialog'] := 'No';
//COMPRESSION
if ACompression then
begin
FPDFPrinter.Option['Compression.Graphics'] := 'Yes';
FPDFPrinter.Option['Compression.Text'] := 'Yes';
FPDFPrinter.Option['Compression.ASCII'] := 'No';
FPDFPrinter.Option['Compression.Color.Enabled'] := 'Yes';
FPDFPrinter.Option['Compression.Color.Method'] := 'Auto';
FPDFPrinter.Option['Compression.Indexed.Enabled'] := 'Yes';
FPDFPrinter.Option['Compression.Indexed.Method'] := 'Auto';
FPDFPrinter.Option['Compression.Mono.Enabled'] := 'Yes';
FPDFPrinter.Option['Compression.Mono.Method'] := 'Auto';
end else
begin
FPDFPrinter.Option['Compression.Graphics'] := 'No';
FPDFPrinter.Option['Compression.Text'] := 'No';
end;
//EMBED FONTS
FPDFPrinter.Option['Fonts.EmbedAll'] := AEmbedFonts;
FPDFPrinter.Option['Saver.ShowProgress'] := False;
FPDFPrinter.ApplyOptions(0);
FPDFPrinter.SetAsDefaultPrinter;
Result := True;
except end;
end;