Intercepting the data stream coming out from the document converter

 

The data stream generated by the Document Converter products can be intercepted for processing other than the default saving to a file or sending by e-mail. The data stream can be sent to a remote location without being saved to the local hard drive, or sent to an application that needs to do some specific processing with the stream before saving it to file.

 

This method needs special license.  Please, contact our Sales Department for more information

 

To intercept the data stream, the below steps should be followed:

  1. Create a Custom Dynamic Link Library(DLL) in C++ following the framework described below.

  2. Copy the Custom DLL to the %windir%\system or %windir%\system32 directory.

  3. Set the SendToCreator option in the FileNameOptionsEx method or function call.

  4. Set the PageProcessor parameter using SetPageProcessor or PageProcessor property. This parameter should be set to the name of the custom DLL and only when logged in as Administrator.

 

Dynamic Link Library (DLL) Framework

// *************** File name: custompp.def ******************
LIBRARY custompp
DESCRIPTION ' Custom Page Processor DLL' 
EXPORTS
PPInit
PPStartDoc
PPEndDoc
PPStartPage
PPEndPage
PPStartObject
PPEndObject
PPWriteBuffer
// *************** End of: custompp.def ******************
 
// *************** File name: custompp.h ******************
typedef LPVOID DOCHANDLE;
typedef DOCHANDLE* LPDOCHANDLE;
int PPInit();
int PPStartDoc(LPDOCHANDLE phDoc, DWORD dwFlags);
int PPEndDoc(DOCHANDLE hDoc);
int PPStartPage(DOCHANDLE hDoc);
int PPEndPage(DOCHANDLE hDoc);
int PPStartObject(DOCHANDLE hDoc);
int PPEndObject(DOCHANDLE hDoc);
int PPWriteBuffer(DOCHANDLE hDoc, LPBYTE pData, DWORD dwSize);
// *************** End of: custompp.h ******************
 
// *************** File name: custompp.c ******************
#include "Windows.h"
#include "custompp.h"
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
    {
    // standard DLL entry point
    return TRUE;
    }
 
 
int PPInit()
    {
    // called when the DLL is initialized, and before the call to StartDoc
    return 0;
    }
 
 
int PPStartDoc(LPDOCHANDLE phDoc, DWORD dwFlags)
    {
    // called when a new document is started
    // dwFlags is 1 if the user requested the document to be printed to a physical printer
    if(!phDoc)
    return -1;
 
    // create a new DOCX file
    *phDoc =(LPDOCHANDLE)CreateFile("c:\\test.docx", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
    if(*phDoc)
        MessageBox(0, "StartDoc", "Success", 0);
    else
        MessageBox(0, "StartDoc", "Failure", 0);
    return 0;
    }
 
 
int PPEndDoc(DOCHANDLE hDoc)
    {
    // document printing has ended
    if(!hDoc)
        return -1;
    // close the destination DOCX file
    CloseHandle((HANDLE)hDoc);
    return 0;
    }
 
 
int PPStartPage(DOCHANDLE hDoc)
    {
    // a new page is started
    if(!hDoc)
        return -1;
    return 0;
    }
 
 
int PPEndPage(DOCHANDLE hDoc)
    {
    // page ended printing
    if(!hDoc)
        return -1;
    return 0;
    }
 
int PPStartObject(DOCHANDLE hDoc)
    {
    // a new DOCX object is being started
    // each document and page can contain a number of DOCX objects
    if(!hDoc)
        return -1;
    return 0;
    }
 
int PPEndObject(DOCHANDLE hDoc)
    {
    // finished outputting a DOCX object
    if(!hDoc)
        return -1;
    return 0;
    }
 
int PPWriteBuffer(DOCHANDLE hDoc, LPBYTE pData, DWORD dwSize)
    {
    // block of data data sent from document converter
    // dwSize is the number of output bytes
    DWORD dwWritten = 0;
    if(!hDoc)
        return -1;
    // simply write data to file
    if(WriteFile((HANDLE)hDoc, pData, dwSize, &dwWritten, NULL)== FALSE)
        return -1;
    return 0;
    }

 

Using the Custom DLL

Module Module1
 
    <Flags()>
    Public Enum acFileNameOptions As Integer
        NoPrompt = &H1
        UseFileName = &H2
        EmbedFonts = &H10
        BroadcastMessages = &H20
    End Enum
 
 
    Sub Main()
        ' Constants for Activation codes
        Const strLicenseTo As String = "DOCX Converter Developer Evaluation"
        Const strActivationCode As String = "07EFCDAB010001002EE718DAABD90353AA8141F60B6762C695F4D5BA97F516CBE3EB407DC717EC1D28DE39A61F1ACE26924C99AFB190"
        Const AMYUNIPRINTERNAME As String = "Amyuni DOCX Converter"
 
        ' Declare a new cdintfex object if it does not exist in the form.
        Dim DOCX As New CDIntfEx.CDIntfEx
 
        ' Get a reference to the installed printer.
        ' This will fail if the printer name passed to the DriverInit method is 
        ' not found in the printer’s folder
        DOCX.DriverInit(AMYUNIPRINTERNAME)
 
        ' The SetDefaultPrinter function sets the system default printer to the one
        ' initialized by the DriverInit functions.
        DOCX.SetDefaultPrinter()
 
        ' Set Printer options
        DOCX.FileNameOptionsEx = acFileNameOptions.SendToCreator
 
        ' Set Custom Dll
        DOCX.PageProcessor = "custompp.dll"
 
        ' The EnablePrinter() method needs to be called right before each print job. 
        ' Calling the EnablePrinter() method will start a 20 second time-out value
        DOCX.EnablePrinter(strLicenseTo, strActivationCode)
 
        ' Print a sample document
        Dim fileName As String = "C:\temp\test.txt"
 
        ' The BatchConvert method converts a number of files to DOCX.
        DOCX.BatchConvert(fileName)
 
        ' The RestoreDefaultPrinter function resets the system default printer 
        ' to the printer that was the default before the call to SetDefaultPrinter.
        DOCX.RestoreDefaultPrinter()
 
        ' This function will simply detach from an existing printer because the handle was created using DriverInit
        DOCX.DriverEnd()
 
        ' Destroy DOCX object
        DOCX = Nothing
    End Sub
End Module
using Microsoft.Office.Interop.Word;
using System;
 
namespace DataSteamConverter_CS
{
    class Program
    {
        [Flags]
        public enum acFileNameOptions
        {
            NoPrompt = 0x00000001,
            UseFileName = 0x00000002,
            EmbedFonts = 0x00000010,
            BroadcastMessages = 0x00000020,
        }
 
        static void Main(string[] args)
        {
            // Constants for Activation codes
            const string strLicenseTo = "DOCX Converter Developer Evaluation";
            const string strActivationCode = "07EFCDAB010001002EE718DAABD90353AA8141F60B6762C695F4D5BA97F516CBE3EB407DC717EC1D28DE39A61F1ACE26924C99AFB190";
            const string AMYUNIPRINTERNAME = "Amyuni DOCX Converter";
 
            // Declare a new cdintfex object if it does not exist in the form.
            CDIntfEx.CDIntfEx DOCX = new CDIntfEx.CDIntfEx();
 
            // Get a reference to the installed printer.
            // This will fail if the printer name passed to the DriverInit method is 
            // not found in the printer’s folder
            DOCX.DriverInit(AMYUNIPRINTERNAME);
 
            // The SetDefaultPrinter function sets the system default printer to the one
            // initialized by the DriverInit functions.
            DOCX.SetDefaultPrinter();
 
            // Set Printer options
            DOCX.FileNameOptionsEx =(int)acFileNameOptions.SendToCreator;
 
            // Set Custom Dll
            DOCX.PageProcessor = "custompp.dll";
 
            // The EnablePrinter() method needs to be called right before each print job. 
            // Calling the EnablePrinter() method will start a 20 second time-out value
            DOCX.EnablePrinter(strLicenseTo, strActivationCode);
 
            // Print a sample document
            string fileName = @"C:\temp\test.txt";
 
            // The BatchConvert method converts a number of files to DOCX.
            DOCX.BatchConvert(fileName);
 
            // The RestoreDefaultPrinter function resets the system default printer 
            // to the printer that was the default before the call to SetDefaultPrinter.
            DOCX.RestoreDefaultPrinter();
 
            // This function will simply detach from an existing printer because the handle was created using DriverInit
            DOCX.DriverEnd();
 
            // Destroy DOCX object
            DOCX = null;
        }
 
    }
}
// DOCX Converter Cpp.cpp : Defines the entry point for the console application.
// 
 
#include <Windows.h>
#include <string>
#include <iostream>
#include "CdIntf.h"
#pragma comment(lib, "CDIntf.lib")
 
using namespace std;
 
 
int main()
{
    // Constants for Activation codes
#define strLicenseTo  "DOCX Converter Developer Evaluation"
#define strActivationCode "07EFCDAB010001002EE718DAABD90353AA8141F60B6762C695F4D5BA97F516CBE3EB407DC717EC1D28DE39A61F1ACE26924C99AFB190"
#define AMYUNIPRINTERNAME "Amyuni DOCX Converter"
 
    // Get a reference to the installed printer.
    // This will fail if the printer name passed to the DriverInit method is 
    // not found in the printer’s folder
    HANDLE DOCX = DriverInit(AMYUNIPRINTERNAME);
 
    // The CDISetDefaultPrinter function sets the system default printer to the one
    // initialized by the DriverInit functions.
    CDISetDefaultPrinter(DOCX);
 
    // Set Printer options
    SetFileNameOptions(DOCX, SendToCreator);
 
    // Set Custom Dll
    SetPageProcessor(DOCX, "custompp.dll");
 
    // The EnablePrinter() method needs to be called right before each print job. 
    // Calling the EnablePrinter() method will start a 20 second time-out value
    EnablePrinter(DOCX, strLicenseTo, strActivationCode);
 
    // Print a sample document
    LPSTR fileName = "C:\\temp\\test.txt";
 
    // The BatchConvert method converts a number of files to DOCX.
    BatchConvertEx(DOCX, fileName);
 
    // The RestoreDefaultPrinter function resets the system default printer 
    // to the printer that was the default before the call to SetDefaultPrinter.
    RestoreDefaultPrinter(DOCX);
 
    // This function will simply detach from an existing printer because the handle was created using DriverInit
    DriverEnd(DOCX);
 
    // Destroy DOCX object
    DOCX = NULL;
 
    return 0;
}
package Example;
 
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
 
public class DataStream {
    public enum acFileNameOptions
        {
            NoPrompt(0x00000001),
            UseFileName(0x00000002),
			            EmbedFonts(0x00000010),
            BroadcastMessages(0x00000020);
            private int value;
            private acFileNameOptions(int value)
            {
                this.value = value;
            }
            public Object value(){
                return value;
            }        }
 
 
    public static void main(String[] args)
    {
        // Constants for Activation codes
        String strLicenseTo  = "Amyuni Tech. Evaluation";
        String strActivationCode = "07EFCDAB01000100DF6EFC8664508CC905BADA9A6C56066D8219C78B8804C5D09ECA85769789782B3945B0ECA66CB3612C5D7772F0B9";
        String AMYUNIPRINTERNAME = "Amyuni DOCX Converter";
 
        // Declare a new cdintfex object if it doesn't exist in the form.
        ActiveXComponent docx = new ActiveXComponent("CDIntfEx.CDIntfEx.6.5"); 
 
        // Get a reference to the installed printer.
        // This will fail if the printer name passed to the DriverInit method is 
        // not found in the printer’s folder
        Dispatch.call(docx,"DriverInit",AMYUNIPRINTERNAME);
 
        // The SetDefaultPrinter function sets the system default printer to the one
        // initialized by the DriverInit functions.
        Dispatch.call(docx,"SetDefaultPrinter");
 
        // Set Printer options
        Dispatch.put(docx,"FileNameOptionsEx",acFileNameOptions.SendToCreator.value);
 
        // Set Custom Dll
        Dispatch.put(docx,"PageProcessor", "custompp.dll");
 
        // The EnablePrinter() method needs to be called right before each print job. 
        // Calling the EnablePrinter() method will start a 20 second time-out value
        Dispatch.call(docx,"EnablePrinter", strLicenseTo, strActivationCode); 
 
        // Print a sample document
        String fileName = "C:\\temp\\test.txt";
 
        // The BatchConvert method converts a number of files to DOCX.
        Dispatch.call(docx,"BatchConvert", fileName);
 
        // The RestoreDefaultPrinter function resets the system default printer 
        // to the printer that was the default before the call to SetDefaultPrinter.
        Dispatch.call(docx,"RestoreDefaultPrinter"); 
 
        // This function will simply detach from an existing printer because the handle was created using DriverInit
        Dispatch.call(docx,"DriverEnd");
    }
}
$acFileNameOptions = @{
    NoPrompt = 0x00000001
    UseFileName = 0x00000002
    EmbedFonts = 0x00000010
    BroadcastMessages = 0x00000020
}
 
# Constants for Activation codes
$strLicenseTo  =  "DOCX Converter Developer Evaluation"
$strActivationCode = "07EFCDAB010001002EE718DAABD90353AA8141F60B6762C695F4D5BA97F516CBE3EB407DC717EC1D28DE39A61F1ACE26924C99AFB190"
$AMYUNIPRINTERNAME = "Amyuni DOCX Converter"
 
#Declare a new cdintfex object if it does not exist in the form.
$DOCX = New-Object -ComObject CDIntfEx.CDIntfEx.6.5
 
#Get a reference to the installed printer.
#This will fail if the printer name passed to the DriverInit method is 
#not found in the printer’s folder
[System.__ComObject].InvokeMember('DriverInit', [System.Reflection.BindingFlags]::InvokeMethod,$null,$DOCX,$AMYUNIPRINTERNAME)
 
#The SetDefaultPrinter function sets the system default printer to the one
#initialized by the DriverInit functions.
[System.__ComObject].InvokeMember('SetDefaultPrinter', [System.Reflection.BindingFlags]::InvokeMethod,$null,$DOCX,$null)
 
#Set Printer options
[System.__ComObject].InvokeMember('FileNameOptionsEx', [System.Reflection.BindingFlags]::SetProperty,$null,$DOCX,$acFileNameOptions::SendToCreator)
 
#Set Custom Dll
[System.__ComObject].InvokeMember('PageProcessor', [System.Reflection.BindingFlags]::SetProperty,$null,$DOCX,"custompp.dll")
 
#The EnablePrinter() method needs to be called right before each print job. 
#Calling the EnablePrinter() method will start a 20 second time-out value
[System.__ComObject].InvokeMember('EnablePrinter', [System.Reflection.BindingFlags]::InvokeMethod,$null,$DOCX, @($strLicenseTo, $strActivationCode))
 
#Print a sample document
$fileName = "C:\temp\test.txt"
 
#The BatchConvert method converts a number of files to DOCX.
[System.__ComObject].InvokeMember('BatchConvert', [System.Reflection.BindingFlags]::InvokeMethod,$null,$DOCX, $fileName)
 
#The RestoreDefaultPrinter function resets the system default printer 
#to the printer that was the default before the call to SetDefaultPrinter.
[System.__ComObject].InvokeMember('RestoreDefaultPrinter', [System.Reflection.BindingFlags]::InvokeMethod,$null,$DOCX,$null)
 
#This function will simply detach from an existing printer because the handle was created using DriverInit 
[System.__ComObject].InvokeMember('DriverEnd', [System.Reflection.BindingFlags]::InvokeMethod,$null,$DOCX,$null)
 
#Destroy DOCX object
$DOCX = $null
 
' FileNameOptions constants
Const NoPrompt = &H1
Const UseFileName = &H2
Const EmbedFonts = &H10
Const BroadcastMessages = &H20
 
' Constants for Activation codes
Const strLicenseTo = "DOCX Converter Developer Evaluation"
Const strActivationCode = "07EFCDAB010001002EE718DAABD90353AA8141F60B6762C695F4D5BA97F516CBE3EB407DC717EC1D28DE39A61F1ACE26924C99AFB190"
Const AMYUNIPRINTERNAME = "Amyuni DOCX Converter"
 
' Declare a new cdintfex object
Dim DOCX
Set DOCX = CreateObject("CDIntfEx.CDIntfEx.6.5")
 
' Get a reference to the installed printer.
' This will fail if the printer name passed to the DriverInit method is
' not found in the printer’s folder
DOCX.DriverInit AMYUNIPRINTERNAME
 
' The SetDefaultPrinter function sets the system default printer to the one
' initialized by the DriverInit functions.
DOCX.SetDefaultPrinter
 
' Set Printer options
DOCX.FileNameOptionsEx = SendToCreator
 
' Set Custom Dll
DOCX.PageProcessor = "custompp.dll"
 
' The EnablePrinter() method needs to be called right before each print job.
' Calling the EnablePrinter() method will start a 20 second time-out value
DOCX.EnablePrinter strLicenseTo, strActivationCode
 
' Print a sample document
Dim fileName
fileName = "C:\temp\test.txt"
 
' The BatchConvert method converts a number of files to DOCX.
DOCX.BatchConvert fileName
 
' The RestoreDefaultPrinter function resets the system default printer
' to the printer that was the default before the call to SetDefaultPrinter.
DOCX.RestoreDefaultPrinter
 
' This function will simply detach from an existing printer because the handle was created using DriverInit
DOCX.DriverEnd
 
' Destroy DOCX object
Set DOCX = Nothing