Evaluation Watermark Not Always Removed
Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan
-
- User
- Posts: 81
- Joined: Wed Aug 26, 2009 8:42 am
Evaluation Watermark Not Always Removed
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.
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.
- 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
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 ?
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.
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.
-
- User
- Posts: 81
- Joined: Wed Aug 26, 2009 8:42 am
Re: Evaluation Watermark Not Always Removed
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.
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.
- 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
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.
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.
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.
-
- User
- Posts: 81
- Joined: Wed Aug 26, 2009 8:42 am
Re: Evaluation Watermark Not Always Removed
Is there any sample code available?
- 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
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.
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.
-
- User
- Posts: 81
- Joined: Wed Aug 26, 2009 8:42 am
Re: Evaluation Watermark Not Always Removed
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).
-
- User
- Posts: 81
- Joined: Wed Aug 26, 2009 8:42 am
Re: Evaluation Watermark Not Always Removed
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
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
- Tracker Supp-Stefan
- Site Admin
- Posts: 17907
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
- Contact:
Re: Evaluation Watermark Not Always Removed
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
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
-
- User
- Posts: 81
- Joined: Wed Aug 26, 2009 8:42 am
Re: Evaluation Watermark Not Always Removed
That makes sense. Thanks very much for the quick answers.
- Tracker Supp-Stefan
- Site Admin
- Posts: 17907
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
- Contact: