Question about virtual printer's default settings

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

Victorvon
User
Posts: 14
Joined: Mon Aug 30, 2004 8:45 pm

Question about virtual printer's default settings

Post by Victorvon »

Hi, it looks like calling virtual printer's ResetDefaults method will revert virtual printer to factory defaults, not currnet pre-installed PDF-XChange printer's current settings? If that is the case then how can I force virtual printer to pick up current settings of the pre-installed printer?

In our application we override some virtual printer settings but would like to allow our users to change other settings (like enabling/disabling graph compression or print resolution) via chainging pre-installed printer's settings.

Victor Von
User avatar
John - Tracker Supp
Site Admin
Posts: 5219
Joined: Tue Jun 29, 2004 10:34 am
Location: United Kingdom

Re: Question about virtual printer's default settings

Post by John - Tracker Supp »

Hi Victor,

I regret its not possible to provide a 'hybrid' combination of the factory defaults, the end user's configuration and allow you to modify in your code specific settings in this way ...

You can use the function ReStorePrinterOptions/StorePrinterOptions in the IPXCPrinter interface, Using ReStorePrinterOptions a developer can use previously stored profile settings as a means by which the end user can store different job settings and export these to a file - but this would require your end users to physically export any modified setup to a file for you to retrieve and use - not the same as importing the current setup from the end users device setup.

So for now - other than you providing you own end user interface for the end user to maintain - i can see no easy way to offer this.

Sorry could not help more
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com
Victorvon
User
Posts: 14
Joined: Mon Aug 30, 2004 8:45 pm

Re: Question about virtual printer's default settings

Post by Victorvon »

Fair enough, in this case I would like to submit this as a feature request. Thanks.

Victor
User avatar
John - Tracker Supp
Site Admin
Posts: 5219
Joined: Tue Jun 29, 2004 10:34 am
Location: United Kingdom

Re: Question about virtual printer's default settings

Post by John - Tracker Supp »

Submission received - will look at for V5 release later this spring/summer.

Thanks
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com
Victorvon
User
Posts: 14
Joined: Mon Aug 30, 2004 8:45 pm

Re: Question about virtual printer's default settings

Post by Victorvon »

Did some experiment over the weekend and end up with more questions, the idea is to prompt the user with "printing preferences" dialog then save user's input using StorePrinterOptions as you mentioned in your post (please refer to code segment below).

Code: Select all

QString const PdfXc40Impl::m_gProgID = QLatin1String("PXCComLib.CPXCControlEx");

// Returns PDF printer name.
QString PdfXc40Impl::GetPrinterName() const
{
  return QLatin1String("PDF-XChange for StyleADVISOR");
}

bool PdfXc40Impl::PreparePrinter()
{
  try
  {
    if (!m_v4Factory.CreateDispatch(m_gProgID.toStdString().c_str()))
    {
      return false;
    }
    // Create virtual PDF printer.
    m_v4Printer.AttachDispatch(m_v4Factory.get_Printer(NULL, this->GetPrinterName().toStdString().c_str(), NULL, NULL).pdispVal);

    // Now open the virtual printer we just created.
    HANDLE hPrinter;
    ::OpenPrinter((LPSTR)(this->GetPrinterName().toStdString().c_str()), &hPrinter, NULL);
    if (hPrinter)
    {
      ScopeGuard printerGuard = MakeGuard(::ClosePrinter, hPrinter);
      // Get DEVMODE from pre-installed default printer
      LPDEVMODE pDevMode = CZAPdfDriverProxy::GetInstance()->GetDevMode();
      ASSERT(NULL != pDevMode);
      // Allow the user to change printing preferences.
      ::DocumentProperties(NULL, hPrinter, (LPSTR)(this->GetPrinterName().toStdString().c_str()), pDevMode, NULL, DM_IN_BUFFER|DM_IN_PROMPT);
    }

    // Store printer options for next print session.
    IStream* streamPtr = NULL;
    HRESULT hr = ::CreateStreamOnHGlobal(NULL, TRUE, &streamPtr); 
    if (S_OK == hr)
    {
      ASSERT(NULL != streamPtr);
      m_v4Printer.StorePrinterOptions(streamPtr);
      HGLOBAL	hMem = NULL;
      hr = ::GetHGlobalFromStream(streamPtr, &hMem);
      if (S_OK == hr)
      {
        LPVOID pImage = ::GlobalLock(hMem);
        SIZE_T size = ::GlobalSize(hMem);
        try
        {
          CFile pprFile(_T("C:\\Generated_SA8.PPR"), CFile::modeCreate|CFile::modeWrite|CFile::typeBinary);
          pprFile.Write(pImage, size);
          pprFile.Close();
        }
        catch (CFileException* e)
        {
        }
        ::GlobalUnlock(hMem);
      }
      streamPtr->Release();
    }

    return true;
  }
  catch (...)
  {
    return false;
  }
}

void PdfXc40Impl::ShutdownPrinter()
{
  m_v4Printer.ReleaseDispatch();
  m_v4Factory.ReleaseDispatch();
}
The first problem I have is that trying to change printing preferences by ::DocumentProperties just doesn't work, all changed dialog properties have absolute no effect on generated PDF file.

I originally thought I can probably get printer options from pre-installed default printer by calling ::DocumentProperties on default printer and then merge the DEVMODE info I got from the call to virtual printer by calling ::DocumentProperties on virtual printer with DM_IN_BUFFER, but this didn't work either.

The other problem is that StorePrinterOptions did save something but it seems that the options are totally missed from the generated file. I've attached two .PPR files for comparison: SA8.ppr was generated by "Printing Preferences" dialog and Generated_SA8.ppr was generated from the code segment.

BTW, ReStorePrinterOptions works as designed.

Victor
You do not have the required permissions to view the files attached to this post.
Victorvon
User
Posts: 14
Joined: Mon Aug 30, 2004 8:45 pm

Re: Question about virtual printer's default settings

Post by Victorvon »

Forgot to mention: I'm running PDF-XChange v4 build 165 on Vista Business SP2.

Victor
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3550
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada

Re: Question about virtual printer's default settings

Post by Ivan - Tracker Software »

Settings for the PDF-XChange driver are not stored in the DEVMODE (there are several reasons why, but the most important is because there is insufficient space within the DEVMODE – even if it theoretically can be 64 KB in size, there are some applications which cannot address large DEVMODE and in reality the limit is approx 8-10 KB).

Therefore most settings are stored within the registry under the path:

HKEY_CURRENT_USER\Software\Tracker Software\PDF-XChange 4.0\Drivers\<Printer Name>\Profiles\<Profile name>

where, <Printer Name> is the name of the printer for which the settings are stored; <Profile name> - name of the profile.

A Printer, created via the SDK, always uses the profile called Current, and Current is the name of default profile for the end-user’s printer device - though it can be changed later by the user.

So, if a user uses the Current profile as their default profile, to copy parameters of the end-user printer to the newly created SDK printer, you will need to copy (recursively) all items from

HKEY_CURRENT_USER\Software\Tracker Software\PDF-XChange 4.0\Drivers\PDF-XChange 4.0\Profiles\Current

To

HKEY_CURRENT_USER\Software\Tracker Software\PDF-XChange 4.0\Drivers\PrinterName\Profiles\Current

Where the PrinterName, is the value of the Name property of the newly created IPXCPrinter.
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.
Victorvon
User
Posts: 14
Joined: Mon Aug 30, 2004 8:45 pm

Re: Question about virtual printer's default settings

Post by Victorvon »

I've copied the profile successfully but it doesn't have any effect on generated PDF file at all. So the question is when does virtual printer pick up the values in the profile? Before the creation of the virtual printer or before DC created from virtual printer?

I also notice that if I call virtual printer's ApplyOptions method after copying profile the registry did reflect the changes from ApplyOptions but it also wiped out the copied values, I just can't make sense of it. Any thought?

Victor
User avatar
Paul - Tracker Supp
Site Admin
Posts: 6901
Joined: Wed Mar 25, 2009 10:37 pm
Location: Chemainus, Canada

Re: Question about virtual printer's default settings

Post by Paul - Tracker Supp »

Hi Victorvon

it looks like there is indeed a problem here that we have identified. Officially we don't support moving settings from end-user printers to the printer created temporarily by an SDK however Ivan will make some changes/improvements in this regard in the next builds.

hth
Best regards

Paul O'Rorke
Tracker Support North America
http://www.tracker-software.com