SetDocFileProps

The SetDocFileProps method can be used in multi-threading situations to avoid conflicts between multiple applications or multiple threads requesting simultaneous access the Converter products. The CDIntf library uses the registry to interact with the printer drivers. This can cause conflicts when multiple applications use CDIntf to access the printer drivers.

 

Syntax

ActiveX:

System.Int32 SetDocFileProps(System.String szDocTitle, System.Int32 lOptions, System.String szFileDir, System.String szFileName)

DLL:

int SetDocFileProps(HANDLE hPrinter, LPCSTR szDocTitle, long lOptions, LPCSTR szFileDir, LPCSTR szFileName)

 

Parameters

szDocTitle

The document title as it appears in the print spooler when printing any document, this should be the same as the parameter szLockName used for Lock and Unlock.

lOptions

Output file name options equivalent to the function FileNameOptionsEx.

szFileDir

Destination directory, equivalent to the DefaultDirectory function call.

szFileName

Output file name, equivalent to the function DefaultFileName.

hPrinter

Handle to printer returned by any of the DriverInit function calls.

 

Return Value

The return value is 0 if the function is successful or a Windows specific error code if the function fails.

 

Remarks

This method replaces the properties DefaultDirectory, DefaultFileName and FileNameOptionsEx in the cases where print job locking is needed. The documentation for these three functions contains a complete description of the lOptions, szFileDir and szFileName parameters.

 

This method needs to be placed after the Lock Method.  Otherwise, it won' t work properly.

 

Member of CDIntfEx.CDIntfEx.

Example

<Flags()>

Public Enum acFileNameOptions As Integer

    ' Please check FileNameOptions for the complete flags version

    NoPrompt = &H1

    UseFileName = &H2

    Concatenate = &H4

    DisableCompression = &H8

    EmbedFonts = &H10

    BroadcastMessages = &H20

    PrintWatermark = &H40

End Enum

 

Public Sub Sample()

    ' Constants for Activation codes

    Const strLicenseTo As String = "Amyuni PDF Converter Evaluation"

    Const strActivationCode As String = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA"

    Const AMYUNIPRINTERNAME As String = "Amyuni PDF Converter"

 

    ' Declare a new cdintfex object if it does not exist in the form.

    Dim PDF 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

    PDF.DriverInit(AMYUNIPRINTERNAME)

 

    ' The SetDefaultPrinter function sets the system default printer to the one

    ' initialized by the DriverInit functions.

    PDF.SetDefaultPrinter()

 

    ' The EnablePrinter() method needs to be called right before each print job.

    ' and before the configuration

    ' Calling the EnablePrinter() method will start a 20 second time-out value

    PDF.EnablePrinter(strLicenseTo, strActivationCode)

 

    ' First, Lock Amyuni Printer

    PDF.Lock("docfiles.docx")

 

    ' Second, configure the printer

    ' This method replaces the properties DefaultDirectory, DefaultFileName and FileNameOptions

    PDF.SetDocFileProps("docfiles.docx", acFileNameOptions.NoPrompt, "C:\Temp", "")

 

    ' The BatchConvert method converts a file to PDF.

    PDF.BatchConvert("C:\Temp\docfiles.docx")

 

    ' Test Lock

    MsgBox(PDF.TestLock("docfiles.docx"))

 

    ' Finally, unlock Amyuni Printer

    PDF.Unlock("docfiles.docx", 1000)

 

    ' The RestoreDefaultPrinter function resets the system default printer 

    ' to the printer that was the default before the call to SetDefaultPrinter.

    PDF.RestoreDefaultPrinter()

 

    ' This function will simply detach from an existing printer because the handle was created using DriverInit

    PDF.DriverEnd()

End Sub

[Flags]

public enum acFileNameOptions

{

    // Please check FileNameOptions for the complete flags version

    NoPrompt = 0x00000001,

    UseFileName = 0x00000002,

    Concatenate = 0x00000004,

    DisableCompression = 0x00000008,

    EmbedFonts = 0x00000010,

    BroadcastMessages = 0x00000020,

    PrintWatermark = 0x00000040

}

public void Lock()

{

    // Constants for Activation codes

    const string strLicenseTo = "Amyuni PDF Converter Evaluation";

    const string strActivationCode = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA";

    const string AMYUNIPRINTERNAME = "Amyuni PDF Converter";

 

    // Declare a new cdintfex object if it does not exist in the form.

    CDIntfEx.CDIntfEx PDF = 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

    PDF.DriverInit(AMYUNIPRINTERNAME);

 

    // The SetDefaultPrinter function sets the system default printer to the one

    // initialized by the DriverInit functions.

    PDF.SetDefaultPrinter();

 

    // The EnablePrinter() method needs to be called right before each print job.

    // and before the configuration

    // Calling the EnablePrinter() method will start a 20 second time-out value

    PDF.EnablePrinter(strLicenseTo, strActivationCode);

 

    // First, Lock Amyuni Printer

    PDF.Lock("docfiles.docx");

 

    // Second, configure the printer

    // This method replaces the properties DefaultDirectory, DefaultFileName and FileNameOptions

    PDF.SetDocFileProps("docfiles.docx", (int)acFileNameOptions.NoPrompt, "C:\temp", "");

 

    // The EnablePrinter() method needs to be called right before each print job.

    // and before the configuration

    // Calling the EnablePrinter() method will start a 20 second time-out value

    PDF.EnablePrinter(strLicenseTo, strActivationCode);

 

    // The BatchConvert method converts a file to PDF.

    PDF.BatchConvert("C:\temp\\docfiles.docx");

 

    // Test Lock

    MessageBox.Show(Convert.ToString(PDF.TestLock("docfiles.docx")));

 

    // Finally, Unlock Amyuni Printer in case of error

    PDF.Unlock("docfiles.docx", 1000);

 

    // The RestoreDefaultPrinter function resets the system default printer 

    // to the printer that was the default before the call to SetDefaultPrinter.

    PDF.RestoreDefaultPrinter();

 

    // This function will simply detach from an existing printer because the handle was created using DriverInit

    PDF.DriverEnd();

}

// PDF 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  "Amyuni PDF Converter Evaluation"

    #define strActivationCode "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA"

    #define AMYUNIPRINTERNAME "Amyuni PDF 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 PDF = DriverInit(AMYUNIPRINTERNAME);

 

    // The CDISetDefaultPrinter function sets the system default printer to the one

    // initialized by the DriverInit functions.

    CDISetDefaultPrinter(PDF);

 

    // The EnablePrinter() method needs to be called right before each print job.

    // and before the configuration

    // Calling the EnablePrinter() method will start a 20 second time-out value

    EnablePrinter(PDF, strLicenseTo, strActivationCode);

 

    // First, Lock Amyuni Printer

    Lock(PDF, "docfiles.docx");

 

    // Second, configure the printer

    // This method replaces the properties DefaultDirectory, DefaultFileName and FileNameOptions

    SetDocFileProps(PDF, "docfiles.docx", NoPrompt, "C:\temp", "");

    // The BatchConvert method converts a file to PDF.

    BatchConvertEx(PDF, "C:\temp\\docfiles.docx");

 

    // Test Lock

    cout << TestLock(PDF, "docfiles.docx");

 

    // Finally, Unlock Amyuni Printer in case of error

    Unlock(PDF, "docfiles.docx", 1000);

 

    // The RestoreDefaultPrinter function resets the system default printer 

    // to the printer that was the default before the call to SetDefaultPrinter.

    RestoreDefaultPrinter(PDF);

 

    // This function will simply detach from an existing printer because the handle was created using DriverInit

    DriverEnd(PDF);  

 

    // Destroy PDF object

    PDF = nullptr;    

 

    return 0;

}

package Example;

 

import com.jacob.activeX.ActiveXComponent;

import com.jacob.com.Dispatch;

 

public class GUnLock {

    public enum acFileNameOptions

    {

        // Please check FileNameOptions for the complete flags version

        NoPrompt(0x00000001),

        UseFileName(0x00000002),

        Concatenate(0x00000004),

        DisableCompression(0x00000008),

        EmbedFonts(0x00000010),

        BroadcastMessages(0x00000020),

        PrintWatermark(0x00000040);

        public int value;

        public acFileNameOptions(int value)

        {

            this.value = value;

        }

        public Object value(){

            return value;

        }

    }

    public static void main(String[] args)

    {

        // Constants for Activation codes

        String strLicenseTo  = "Amyuni PDF Converter Evaluation";

        String strActivationCode = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA";

        String AMYUNIPRINTERNAME = "Amyuni PDF Converter";

 

        // Declare a new cdintfex object if it does not exist in the form.

        ActiveXComponent pdf = 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(pdf,"DriverInit",AMYUNIPRINTERNAME);

 

        // The SetDefaultPrinter function sets the system default printer to the one

        // initialized by the DriverInit functions.

        Dispatch.call(pdf,"SetDefaultPrinter");

 

        // The EnablePrinter() method needs to be called right before each print job.

        // and before the configuration

        // Calling the EnablePrinter() method will start a 20 second time-out value

        Dispatch.call(pdf,"EnablePrinter", strLicenseTo, strActivationCode);

 

        // First, Lock Amyuni Printer

        Dispatch.call(pdf,"Lock", "docfiles.docx");

 

        // Second, configure the printer

        // This method replaces the properties DefaultDirectory, DefaultFileName and FileNameOptions

        Dispatch.call(pdf,"SetDocFileProps", "docfiles.docx", acFileNameOptions.NoPrompt.value, "C:\temp", "");

 

        // The BatchConvert method converts a file to PDF.

        Dispatch.call(pdf,"BatchConvert","C:\temp\\docfiles.docx");

 

        // Test Lock

        Dispatch.call(pdf,"TestLock", "docfiles.docx");

 

        // Finally, Unlock Amyuni Printer in case of error

        Dispatch.call(pdf,"Unlock", "docfiles.docx", 1000);

 

        // The RestoreDefaultPrinter function resets the system default printer 

        // to the printer that was the default before the call to SetDefaultPrinter.

        Dispatch.call(pdf,"RestoreDefaultPrinter"); 

 

        // This function will simply detach from an existing printer because the handle was created using DriverInit

        Dispatch.call(pdf,"DriverEnd");

 

        // Destroy PDF object

        pdf = null;        

    }

}

$acFileNameOptions = @{

    NoPrompt = 0x00000001

    UseFileName = 0x00000002

    Concatenate = 0x00000004

    DisableCompression = 0x00000008

    EmbedFonts = 0x00000010

    BroadcastMessages = 0x00000020

    PrintWatermark = 0x00000040

# Please check FileNameOptions for the complete flags version

 

# Constants for Activation codes

$strLicenseTo  =  "Amyuni PDF Converter Evaluation"

$strActivationCode = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA"

$AMYUNIPRINTERNAME = "Amyuni PDF Converter"

 

# Declare a new cdintfex object if it does not exist in the form.

$PDF = 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,$PDF,$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,$PDF,$null)

# First, Lock Amyuni Printer

 

# The EnablePrinter()method needs to be called right before each print job.

# and before the configuration

# Calling the EnablePrinter()method will start a 20 second time-out value

[System.__ComObject].InvokeMember('EnablePrinter', [System.Reflection.BindingFlags]::InvokeMethod,$null,$PDF, @($strLicenseTo, $strActivationCode))

 

[System.__ComObject].InvokeMember('Lock', [System.Reflection.BindingFlags]::InvokeMethod,$null,$PDF, "docfiles.docx") 

 

# Second, configure the printer

# This method replaces the properties DefaultDirectory, DefaultFileName and FileNameOptions

[System.__ComObject].InvokeMember('SetDocFileProps', [System.Reflection.BindingFlags]::InvokeMethod,$null,$PDF,

@("docfiles.docx", $acFileNameOptions::NoPrompt, "C:\Temp", ""))

 

# The BatchConvert method converts a file to PDF.

[System.__ComObject].InvokeMember('BatchConvert', [System.Reflection.BindingFlags]::InvokeMethod,$null,$PDF, "C:\Temp\docfiles.docx")

 

# Finally, Unlock Amyuni Printer in case of error

[System.__ComObject].InvokeMember('Unlock', [System.Reflection.BindingFlags]::InvokeMethod,$null,$PDF, @("docfiles.docx", 1000)) 

# 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,$PDF,$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,$PDF,$null) 

 

# Destroy PDF object

$PDF = $null

' FileNameOptions constants

' Please check FileNameOptions for the complete flags version

Const NoPrompt = &H1

Const UseFileName = &H2

Const Concatenate = &H4

Const DisableCompression = &H8

Const EmbedFonts = &H10

Const BroadcastMessages = &H20

Const PrintWatermark = &H40

Const MultilingualSupport = &H80

Const EncryptDocument = &H100

Const FullEmbed = &H200

 

' Constants for Activation codes

Const strLicenseTo = "Amyuni PDF Converter Evaluation"

Const strActivationCode = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA"

Const AMYUNIPRINTERNAME = "Amyuni PDF Converter"

 

' Declare a new cdintfex object

Dim PDF

Set PDF = 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

PDF.DriverInit AMYUNIPRINTERNAME

 

' The SetDefaultPrinter function sets the system default printer to the one

' initialized by the DriverInit functions.

PDF.SetDefaultPrinter

 

' The EnablePrinter() method needs to be called right before each print job.

' and before the configuration

' Calling the EnablePrinter() method will start a 20 second time-out value

PDF.EnablePrinter strLicenseTo, strActivationCode

 

' First, Lock Amyuni Printer

PDF.Lock "docfiles.docx"

 

' Second, configure the printer

' This method replaces the properties DefaultDirectory, DefaultFileName and FileNameOptions

PDF.SetDocFileProps "docfiles.docx", NoPrompt, "C:\Temp", ""

 

' The BatchConvert method converts a number of files to PDF.

PDF.BatchConvert "C:\Temp\docfiles.docx"

 

' Test Lock

WScript.Echo(PDF.TestLock("docfiles.docx"))

 

' Finally, Unlock Amyuni Printer in case of error

PDF.Unlock "docfiles.docx", 1000

 

' The RestoreDefaultPrinter function resets the system default printer

' to the printer that was the default before the call to SetDefaultPrinter.

PDF.RestoreDefaultPrinter

 

' This function will simply detach from an existing printer because the handle was created using DriverInit

PDF.DriverEnd

 

' destroy pdf object

Set PDF = Nothing