Problems Setting the Default Printer

PDF-XChange Drivers API (only) V4/V5
This Forum is for the use of Software Developers requiring help and assistance for Tracker Software's PDF-XChange Printer Drivers SDK (only) - VERSION 4 & 5 - Please use the PDF-Tools SDK Forum for Library DLL assistance.

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan

Post Reply
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Problems Setting the Default Printer

Post by jeffp »

I'm having an issue with trying to set the PDF printer and then reset the Default Printer.

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;
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: Problems Setting the Default Printer

Post by Ivan - Tracker Software »

Please try to add

Code: Select all

FPDFInstance.RemoveOrphanPrinters('', FInitPrinterName);
before your

Code: Select all

ADisp := FPDFInstance.Printer['', FInitPrinterName, FRegKey, FDevCode];
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: Problems Setting the Default Printer

Post by jeffp »

Seem to help. What does it do?
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17818
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Problems Setting the Default Printer

Post by Tracker Supp-Stefan »

Hello Jeffp,

I would say it removes any orphaned instances of the printer, and as such helps in avoiding your printer getting named:
FileCenter System Device(1), FileCenter System Device(2) etc...
(When a printer with the name you want to create already exists the new instance will have a number in brackets as the last part of it's name)
and will allow your code to work with the static name you are assigning.

Best,
Stefan
Post Reply