PrintDriver V4 event handling

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
Dmitry_Ko
User
Posts: 9
Joined: Wed Mar 26, 2008 12:12 pm

PrintDriver V4 event handling

Post by Dmitry_Ko »

Hello.
Can you tell me how to handle print events, such as OnStartDoc, OnStartPage and so on.
I try in this way:
-Implement _IPXCPrinterEvents interface
-Ask IConnectionPointContainer at PXCComLib::IPXCControlEx object
-Make Advise
-Send document on print trough application
-Wait for ivents

Please tell me what is wrong.
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Post by Ivan - Tracker Software »

Do you use ATL ?
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.
Dmitry_Ko
User
Posts: 9
Joined: Wed Mar 26, 2008 12:12 pm

Post by Dmitry_Ko »

Ivan - Tracker Software wrote:Do you use ATL ?
Yes.
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Post by Ivan - Tracker Software »

In this case what you need to do:
1. add into your stdafx.h

Code: Select all

#import "progid:PXCComLib.CPXCControlEx" rename_namespace("PXC"), named_guids
2. declare a class like this (or you can use existing class):

Code: Select all

class MyPXCHandler : public IDispEventImpl<0, MyPXCHandler, &__uuidof(PXC::_IPXCPrinterEvents), &PXC::LIBID_PXC, 1, 0>
{
public:
    MyPXCHandler()
    {
        m_pFactory = NULL;
        m_pPrinter = NULL;
    }
    ~MyPXCHandler()
    {
        Finish();
    }
public:
    HRESULT Prepare()
    {
        if (m_pPrinter != NULL)
            return S_OK;
        if (m_pFactory == NULL)
        {
            m_pFactory = PXC::IPXCControlExPtr(__uuidof(PXC::CPXCControlEx));
            if (m_pFactory == NULL)
            {
                // handle error here
                return E_FAIL;
            }
        }
        m_pPrinter = m_pFactory->Printer[L"", L"PDF-XChange 4.0 Sample", L"<YOUR REG KEY HERE>", L"<YOUR DEV CODE HERE>"];
        if (m_pPrinter == NULL)
            return E_FAILE;
        return DispEventAdvise(m_pPrinter);
    }
    HRESULT Finish()
    {
        if (m_pPrinter != NULL)
        {
                m_pPrinter->RestoreDefaultPrinter();
                DispEventUnadvise(m_pPrinter);
                m_pPrinter.Release();
        }
        if (m_pFactory != NULL)
        {
                m_pFactory.Release();
        }
    }
public:
        BEGIN_SINK_MAP(CMainDlg)
                SINK_ENTRY_EX(0, __uuidof(PXC::_IPXCPrinterEvents), 1, OnStartDoc)
                SINK_ENTRY_EX(0, __uuidof(PXC::_IPXCPrinterEvents), 2, OnStartPage)
                SINK_ENTRY_EX(0, __uuidof(PXC::_IPXCPrinterEvents), 3, OnEndPage)
                SINK_ENTRY_EX(0, __uuidof(PXC::_IPXCPrinterEvents), 4, OnEndDoc)
                SINK_ENTRY_EX(0, __uuidof(PXC::_IPXCPrinterEvents), 5, OnFileSaved)
                SINK_ENTRY_EX(0, __uuidof(PXC::_IPXCPrinterEvents), 6, OnFileSent)
                SINK_ENTRY_EX(0, __uuidof(PXC::_IPXCPrinterEvents), 7, OnError)
                SINK_ENTRY_EX(0, __uuidof(PXC::_IPXCPrinterEvents), 8, OnDocSpooled)
        END_SINK_MAP()
public:
	HRESULT __stdcall OnStartDoc(long JobID, BSTR lpszDocName, BSTR lpszAppName);
    HRESULT __stdcall OnStartPage(long JobID, long nPageNumber)
    {
        // add your handling here
        return S_OK;
    }
    HRESULT __stdcall OnEndPage(long JobID, long nPageNumber)
    {
        // add your handling here
        return S_OK;
    }
    HRESULT __stdcall OnEndDoc(long JobID, long bOK)
    {
        // add your handling here
        return S_OK;
    }
    HRESULT __stdcall OnFileSaved(long JobID, BSTR lpszFileName)
    {
        // add your handling here
        return S_OK;
    }
    HRESULT __stdcall OnFileSent(long JobID, BSTR lpszFileName)
    {
        // add your handling here
        return S_OK;
    }
    HRESULT __stdcall OnError(long JobID, long dwErrorCode)
    {
        // add your handling here
        return S_OK;
    }
    HRESULT __stdcall OnDocSpooled(long JobID, BSTR lpszDocName, BSTR lpszAppName)
    {
        // add your handling here
        return S_OK;
    }
public:
    PXC::IPXCPrinterPtr	m_pPrinter;
    PXC::IPXCControlExPtr	m_pFactory;
};
HTH
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.
Dmitry_Ko
User
Posts: 9
Joined: Wed Mar 26, 2008 12:12 pm

Post by Dmitry_Ko »

Thanks a lot.
User avatar
John - Tracker Supp
Site Admin
Posts: 5219
Joined: Tue Jun 29, 2004 10:34 am
Location: United Kingdom
Contact:

Post by John - Tracker Supp »

Pleasure.
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
Dmitry_Ko
User
Posts: 9
Joined: Wed Mar 26, 2008 12:12 pm

Post by Dmitry_Ko »

Hello!
There is one problem:
I print document through Internet Explorer (programmatically) and call RestoreDefaultPrinter while handling OnStartDoc event.
Then when the document is printed and displayed the printer's progress bar still visible with "Saving PDF... 100% done" and my program hangs on DispEventUnadvise, somewhere deep in ntdll.dll.
If in function HRESULT Finish() I make Sleep(1000) all work right, if I call RestoreDefaultPrinter as you write all work right too.
So, why the deadlock occurs?
Dmitry_Ko
User
Posts: 9
Joined: Wed Mar 26, 2008 12:12 pm

Post by Dmitry_Ko »

Maybe deadlock occures because of running Acrobat after saving...
Because if I set Option "Save.RunnApp" to "false" there is no deadlocks....
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Post by Ivan - Tracker Software »

Can you try to call Finish from OnDocSpooled, but not from OnDocStart ? OnDocSpooled is synchronous event while OnDocStart isn't.
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.
Dmitry_Ko
User
Posts: 9
Joined: Wed Mar 26, 2008 12:12 pm

Post by Dmitry_Ko »

Ivan - Tracker Software wrote:Can you try to call Finish from OnDocSpooled, but not from OnDocStart ? OnDocSpooled is synchronous event while OnDocStart isn't.
I didn't call Finish() from OnStartDoc event, I've called RestoreDefaultPrinter() only from OnDocStart. Finish() was called after OnFileSaved event being processed.
But if I call Finish() in OnDocSpooled event handling, as you say, then the programm hangs on m_pPrinter.Release() call.

Actually I wasn't right in previous post when say that program hangs on DispEventUnadvise, it was hanging on m_pPrinter.Release().

Do you speak russian?:)
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Post by Ivan - Tracker Software »

Yes, I speak russian -- I'm from Ukraine.
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.
Dmitry_Ko
User
Posts: 9
Joined: Wed Mar 26, 2008 12:12 pm

Post by Dmitry_Ko »

Ivan - Tracker Software wrote:Yes, I speak russian -- I'm from Ukraine.
I'm from Odessa :)
Can I spaek russian in this forum?
What about above problem?
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Post by Ivan - Tracker Software »

свяжитесь со мной через ICQ: 10181962
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.
Post Reply