Evaluation Watermark Not Always Removed

This Forum is for the use of End Users requiring help and assistance for Tracker Software's PDF-XChange Printer Drivers only - Please do not post requests for older versions of PDF-XChange or the PDF-Tools/OFFice2PDF applications here

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

Post Reply
steve.thresher
User
Posts: 81
Joined: Wed Aug 26, 2009 8:42 am

Evaluation Watermark Not Always Removed

Post by steve.thresher »

We have an application that creates a sequence of PDF files by automating word to create a document and print to a PDF Xchange 4 printer. The majority of documents are correct but there will be the odd few that show the evaluation mode watermark in the top corners. e.g. the current print run I'm looking at contains 68 documents and on the first run document 21 showed the watermark, on the second run all documents were clear and on the third run, documents 17 and 37 showed the evaluation mode watermark.

The application is running on Windows Server 2012 R2.
The version of Word comes from Microsoft Office Professional Plus 2013.

The printer is created using the following code:

#import "progid:PXCComLib.CPXCControlEx" rename_namespace("PXC"), named_guids, exclude("IStream","ISequentialStream","_LARGE_INTEGER","_ULARGE_INTEGER","tagSTATSTG","_FILETIME")

class PDFXCHANGE
{
private:
PXC::IPXCPrinterPtr m_pPrinter;
PXC::IPXCControlExPtr m_pFactory;
_bstr_t m_name;

public:
PDFXCHANGE();
~PDFXCHANGE();
TXD_BOOL init(const TXD_STR *fspec);
const TXD_STR *getname();
TXD_VOID deinit();
};

TXD_BOOL PDFXCHANGE::init(const TXD_STR *fspec)
{
for (;;)
{
if (m_pFactory==NULL)
{
try
{
CLSID clsid;
if (SUCCEEDED(CLSIDFromProgID(L"PXCComLib.CPXCControlEx",&clsid)))
m_pFactory = PXC::IPXCControlExPtr(__uuidof(PXC::CPXCControlEx));
}
catch(_com_error &)
{
continue;
}
catch(...)
{
continue;
}
}

if (m_pFactory==NULL)
return(DXD_BOOL_FALSE);

if (m_pPrinter==NULL)
{
try
{
static WCHAR key[]=L"xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx";
static WCHAR devcode[]=L"PDFX3$Xxxxx$999999_Xxxxxxx#";

m_pPrinter = m_pFactory->Printer[L"", L"PDF-XChange 4.0", key, devcode];

// Diagnostic starts
// Log the key and dev code used for each document

TXD_STR log_fspec[LXI_FSPEC_FSPEC+1]={0};
fxk_sys_get_logs_folder(log_fspec);

if (!fxi_dir_exists(log_fspec))
fxk_sys_makedir(log_fspec);

fxd_str_cat(log_fspec,"PDF\\");
if (!fxi_dir_exists(log_fspec))
fxk_sys_makedir(log_fspec);

TXD_STR filename[LXI_FSPEC_SEG+1]={0};
fxi_fspec_getlseg(fspec,filename);

CXI_LFILE_TIMED file;
file.make(CXD_STR().catf("%str%%str%.TXT",log_fspec,filename).c_str());

file.write(CXD_STR().catf("Key : %wstr%",key).c_str());
file.write(CXD_STR().catf("DevCode: %wstr%",devcode).c_str());

file.close();
// Diagnostic ends


}
catch(_com_error &)
{
deinit();
continue;
}
catch(...)
{
deinit();
continue;
}
}

if (m_pPrinter==NULL)
return(DXD_BOOL_FALSE);

break;
}

m_pPrinter->ResetDefaults();
m_pPrinter->Option[L"Save.SaveType"] = L"Save";
m_pPrinter->Option[L"Save.ShowSaveDialog"] = L"No";
_bstr_t p=fspec;
m_pPrinter->Option[L"Save.File"] = (BSTR)p;
m_pPrinter->Option[L"Save.WhenExists"] = L"Overwrite";
m_pPrinter->Option[L"Save.RunApp"] = FALSE;
m_pPrinter->Option[L"Overlay.Enabled"] = FALSE;
m_pPrinter->Option[L"Compression.Graphics"] = TRUE;
m_pPrinter->Option[L"Compression.Text"] = TRUE;
m_pPrinter->Option[L"Fonts.EmbedAll"] = FALSE;
m_pPrinter->Option[L"Saver.ShowProgress"] = FALSE;
m_pPrinter->ApplyOptions(0);

return(DXD_BOOL_TRUE);
}

const TXD_STR *PDFXCHANGE::getname()
{
m_name=m_pPrinter->Name;

return(m_name);
}

Is there any way to determine if the new printer is licenced?

Any help would be very much appreciated.

Steve.
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: Evaluation Watermark Not Always Removed

Post by Ivan - Tracker Software »

Do you create new instance of the printer for each document, or one for all of them.
Can you try to add some delay after sending document to print and removing printer's object ?
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.
steve.thresher
User
Posts: 81
Joined: Wed Aug 26, 2009 8:42 am

Re: Evaluation Watermark Not Always Removed

Post by steve.thresher »

A new instance of the printer is created for each document.

Where should I put the delay and how long should it be. I've already tried a 1 second delay but that still showed the problem.
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: Evaluation Watermark Not Always Removed

Post by Ivan - Tracker Software »

The best way is to listen for events from the printer, and release it only when OnFileSaved or OnFileSaved have been fired.

In V5 of the driver SDK you can use WaitForPrintEvent method instead of listening for the events by yourself.
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.
steve.thresher
User
Posts: 81
Joined: Wed Aug 26, 2009 8:42 am

Re: Evaluation Watermark Not Always Removed

Post by steve.thresher »

Is there any sample code available?
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: Evaluation Watermark Not Always Removed

Post by Ivan - Tracker Software »

Yes, the samples provided with the SDK do show how to handle events from the printer.
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.
steve.thresher
User
Posts: 81
Joined: Wed Aug 26, 2009 8:42 am

Re: Evaluation Watermark Not Always Removed

Post by steve.thresher »

Is there a way to monitor the events without using ATL. Our code is written in C/C++ with the basic Win32 API (not ATL or MFC).
steve.thresher
User
Posts: 81
Joined: Wed Aug 26, 2009 8:42 am

Re: Evaluation Watermark Not Always Removed

Post by steve.thresher »

I've implemented the event monitoring with ATL and wait for the OnFileSaved event to fire before releasing the printer which appears to have solved my problem. Are you able to explain what was going on before?




Sample code for anyone else that's interested:

#import "progid:PXCComLib.CPXCControlEx" rename_namespace("PXC"), named_guids, exclude("IStream","ISequentialStream","_LARGE_INTEGER","_ULARGE_INTEGER","tagSTATSTG","_FILETIME")

// Need this in pure C++ app to initialise ATL and stop exception errors
class CDummyModule : public CAtlDllModuleT<CDummyModule> {};
CDummyModule _Module;

class PDFXCHANGE : public IDispEventImpl<0, PDFXCHANGE, &__uuidof(PXC::_IPXCPrinterEvents), &PXC::LIBID_PXC, 1, 0>
{
private:
PXC::IPXCPrinterPtr m_pPrinter;
PXC::IPXCControlExPtr m_pFactory;

public:
BEGIN_SINK_MAP(PDFXCHANGE)
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) { return S_OK; }
HRESULT __stdcall OnStartPage(long JobID, long nPageNumber) { return S_OK; }
HRESULT __stdcall OnEndPage(long JobID, long nPageNumber) { return S_OK; }
HRESULT __stdcall OnEndDoc(long JobID, long bOK) { return S_OK; }

HRESULT __stdcall OnFileSaved(long JobID, BSTR lpszFileName) { return S_OK; }
{
CXO_WIN_CRITICAL_SCOPE thread_lock(m_critical_section);

m_file_saved=true;
return S_OK;
}

HRESULT __stdcall OnFileSent(long JobID, BSTR lpszFileName) { return S_OK; }
HRESULT __stdcall OnError(long JobID, long dwErrorCode) { return S_OK; }
HRESULT __stdcall OnDocSpooled(long JobID, BSTR lpszDocName, BSTR lpszAppName) { return S_OK; }

// Wait for this function to return true before releasing the m_pPrinter
TXD_BOOL is_file_saved() const
{
CXO_WIN_CRITICAL_SCOPE thread_lock(m_critical_section);

return(m_file_saved);
}

// Call this once m_pPrinter has been setup to start receiving events
DispEventAdvise(m_pPrinter);

// Call this before releasing m_pPrinter to stop receiving events
DispEventUnadvise(m_pPrinter);

// These pages may also help
https://www.pdf-xchange.com/knowled ... ng-and-ATL
http://stackoverflow.com/questions/5661 ... 02#5685702
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17824
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Evaluation Watermark Not Always Removed

Post by Tracker Supp-Stefan »

Hello steve.thresher,

Glad to hear it is working now, and thanks for the code!

As for why it was happening before - sometimes if you do not wait for the correct event - your program might release some components before the PDF creation process has completed - and most notably this is the loss of the license info resulting in the "DEMO" stamps being added.

Regards,
Stefan
steve.thresher
User
Posts: 81
Joined: Wed Aug 26, 2009 8:42 am

Re: Evaluation Watermark Not Always Removed

Post by steve.thresher »

That makes sense. Thanks very much for the quick answers.
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17824
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Evaluation Watermark Not Always Removed

Post by Tracker Supp-Stefan »

:)
Post Reply