Home  Mini-EMF-Printer  docPrint  docPrint-Pro  Support  ScreenShots

How to call docPrint SDK from VB, C#, ASP, PHP etc. program languages?

Example 1: Call doc2pdf.exe from C# code directly, this example is only work from desktop account (run from current user account),

Make use of the PROCESS class available in SYSTEM.DIOGNOSTICS namespace, use the following piece of code to execute the doc2pdf.exe application,

Sub Main()

        Const strToolPath As String = "C:\Program Files\docPrint Pro v4.0\doc2pdf.exe"
        Dim myProcess As Process = Nothing
        Dim pathIn As String = String.Empty
        Dim pathOut As String = String.Empty
        Dim strArguments As String = String.Empty
        Dim dir As New DirectoryInfo("C:\temp\docPrint")

        Try
                If dir.Exists Then
                        For Each File As FileInfo In dir.GetFiles
                                If File.Extension <> "exe" Then
                                        pathIn = File.FullName
                                        pathOut = File.FullName.Remove(File.FullName.Length - 4, 4) & ".xps"
                                        strArguments = "-i " & pathIn & " -o " & pathOut & " -d"
                                        myProcess = New Process()
                                        myProcess.StartInfo.FileName = strToolPath
                                        myProcess.StartInfo.Arguments = strArguments
                                        myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
                                        myProcess.StartInfo.CreateNoWindow = True
                                        myProcess.Start()
                                        myProcess.WaitForExit()
                                        If Not myProcess.HasExited Then
                                                myProcess.Kill()
                                        End If
                                        Console.WriteLine("closed at: " & myProcess.ExitTime & "." & System.Environment.NewLine & "Exit Code: " & myProcess.ExitCode)
                                        If myProcess IsNot Nothing Then myProcess.Dispose() : myProcess = Nothing
                                End If
                        Next
                End If
        Catch ex As Exception
                Console.WriteLine(ex.Message)
        Finally
                If myProcess IsNot Nothing Then myProcess.Dispose() : myProcess = Nothing
                Console.ReadKey()
        End Try
End Sub


Example 2: Call doc2pdf.exe from PHP code, (execute conversion from a special user account, this example can be used from service)

Please by following steps to run doc2pdf.exe inside a special user account,

1. Please download and install EXEShell COM Library (freeware) from following URL first,

http://www.verydoc.com/exeshell.html
http://www.verydoc.com/download/exeshell.zip

2. Please use following PHP code to run the conversion inside a special user account,

<?php
    $com = new COM("exeshell.shell");
    $com->RunCommandLine("Administrator", "123456", "C:\Programme\docprint\doc2pdf.exe -i C:\test.doc -o C:\test.pcx -b 1 -r 204x196");
?>

Please notice:
1. You need change "Administrator" and "123456" to correct user name and password in your system, the conversion will be executed from this user account, the conversion will be executed from current user account if you leave them blank,
2. You may encounter Error 1314 in some Windows systems when you switch between user accounts, this is caused by permission setting, please by following steps to solve this 1314 Error,

ERROR 1314:
~~~~~~~~~~~~~
1314 A required privilege is not held by the client. ERROR_PRIVILEGE_NOT_HELD
~~~~~~~~~~~~~

To resolve this issue:
1. Click Start, click Run, type "secpol.msc", and then press ENTER.
2. Double-click "Local Policies".
3. Double-click "User Rights Assignment".
4. Double-click "Replace a process level token".
5. Click "Add", and then double-click the "Everyone" group
6. Click "OK".
7. You may have to logout or even reboot to have this change take effect.

Please refer to following two screenshots to understand above steps,

http://www.verydoc.com/images/err1314-1.png
http://www.verydoc.com/images/err1314-2.png

Please look at following page for the details about ERROR 1314,

http://www.verydoc.com/exeshell.html


Example 3: Run conversion from C# code, (run conversion inside a special user account or current user account)

#1: Run conversion inside a special user account

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestWithVeryPDF
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                DocPrintCom.docPrint docPrintObj = new DocPrintCom.docPrint();
                docPrintObj.docPrintCOM_Register("XXXXXXXXXXXXXX", "VeryPDF.com Company")
                docPrintObj.docPrintCOM_DocumentConverterEx("Administrator", "123456", "C:\test.doc", "C:\out.pdf", "-* XXXXXXXXXXXX -d")
                docPrintObj = null;
                Console.WriteLine("Done");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}

#2: Run conversion from current user account,

    DOCPRINTCOMLib.docPrintClass docLib = new DOCPRINTCOMLib.docPrintClass();
    docLib.docPrintCOM_DocumentConverterEx("", "", "C:\\Users\\test.docx", "C:\\Users\\out.pdf", "-d");


Please notice:
1. You need change "Administrator" and "123456" to correct user name and password in your system, the conversion will be executed from this user account, the conversion will be executed from current user account if you leave them blank,
2. You may encounter Error 1314 in some Windows systems when you switch between user accounts, this is caused by permission setting, please by following steps to solve this 1314 Error,

ERROR 1314:
~~~~~~~~~~~~~
1314 A required privilege is not held by the client. ERROR_PRIVILEGE_NOT_HELD
~~~~~~~~~~~~~

To resolve this issue:
1. Click Start, click Run, type "secpol.msc", and then press ENTER.
2. Double-click "Local Policies".
3. Double-click "User Rights Assignment".
4. Double-click "Replace a process level token".
5. Click "Add", and then double-click the "Everyone" group
6. Click "OK".
7. You may have to logout or even reboot to have this change take effect.

Please refer to following two screenshots to understand above steps,

http://www.verydoc.com/images/err1314-1.png
http://www.verydoc.com/images/err1314-2.png

Please look at following page for the details about ERROR 1314,

http://www.verydoc.com/exeshell.html


Example 4: Run conversion from ASP code,

#1:

<%
    'On Error Resume next
    Set docPrint = Server.CreateObject("DocPrintCom.docPrint")

    DocumentConverter docPrint, "VeryPDF.doc", "VeryPDF.pdf", ""
    DocumentConverter docPrint, "VeryPDF.doc", "VeryPDF.ps", ""
    DocumentConverter docPrint, "VeryPDF.doc", "VeryPDF.jpg", ""
    DocumentConverter docPrint, "VeryPDF.doc", "VeryPDF.png", ""
    DocumentConverter docPrint, "VeryPDF.doc", "VeryPDF.tif", " -b 1 -r 300"

    function DocumentConverter(byval docPrint, strInFile, strOutFile, strOptions)
        Dim strFullInFileName,strFullOutFileName
        Dim strRootPath
        Dim strAllOptions

        strRootPath = Server.MapPath(".") & "\"
        strFullInFileName = strRootPath & strInFile
        strFullOutFileName = strRootPath & strOutFile

        ' Please replace "XXXXXXXXXXXXXX" with your real License Key which issued by VeryPDF.com company
        ' Please notice, the trial version of docPrintCOM_DocumentConverterEx() will popup a message box,
        ' this message box will hang the ASP application, so docPrintCOM_DocumentConverterEx() function
        ' will not work from ASP code in the trial version of docPrint SDK product.
        ' However, you can test "doc2img.dll" instead of "docPrintCom.dll" in the trial version of docPrint SDK,
        ' you can call "doc2img.dll" from VB, VC++, Delphi, etc. program languages easily for test purpose.

        strAllOptions = """-*"" ""XXXXXXXXXXXXXX"""
        strAllOptions = strAllOptions & strOptions
        nRet = docPrint.docPrintCOM_Register("XXXXXXXXXXXXXX", "VeryPDF.com Company")

        ' Execute document conversion from "Administrator" user account,
        nRet = docPrint.docPrintCOM_DocumentConverterEx("Administrator", "123456", strFullInFileName, strFullOutFileName, strAllOptions)

        strHTMLCode = strFullInFileName & " ==> " & strFullOutFileName & "<br>"
        strHTMLCode = strHTMLCode & "<A href=""" & strOutFile & """ target=""_blank"">" & strOutFile & "</A><br>"
        Response.write strHTMLCode
    end function
%>

#2:
<%
    Set docPrint = Server.CreateObject("DocPrintCom.docPrint")
    nRet = docPrint.docPrintCOM_Register("XXXXXXXXXXXXXX", "VeryPDF.com Company")
    nRet = docPrint.docPrintCOM_DocumentConverterEx("Administrator", "123456", "C:\test.doc", "C:\out.pdf", "-* XXXXXXXXXXXXXX")
    nRet = docPrint.docPrintCOM_DocumentConverterEx("Administrator", "123456", "C:\test.doc", "C:\out.pdf", """-*"" ""XXXXXXXXXXXXXX""")
    nRet = docPrint.docPrintCOM_DocumentConverterEx("Administrator", "123456", "C:\test.doc", "C:\out.tif", """-*"" ""XXXXXXXXXXXXXX"" -b -1")
    nRet = docPrint.docPrintCOM_DocumentConverterEx("Administrator", "123456", "C:\test.pdf", "C:\out.tif", """-*"" ""XXXXXXXXXXXXXX"" -b -1 -r 200")
%>

Please notice:
1. You need change "Administrator" and "123456" to correct user name and password in your system, the conversion will be executed from this user account, the conversion will be executed from current user account if you leave them blank,
2. You may encounter Error 1314 in some Windows systems when you switch between user accounts, this is caused by permission setting, please by following steps to solve this 1314 Error,

ERROR 1314:
~~~~~~~~~~~~~
1314 A required privilege is not held by the client. ERROR_PRIVILEGE_NOT_HELD
~~~~~~~~~~~~~

To resolve this issue:
1. Click Start, click Run, type "secpol.msc", and then press ENTER.
2. Double-click "Local Policies".
3. Double-click "User Rights Assignment".
4. Double-click "Replace a process level token".
5. Click "Add", and then double-click the "Everyone" group
6. Click "OK".
7. You may have to logout or even reboot to have this change take effect.

Please refer to following two screenshots to understand above steps,

http://www.verydoc.com/images/err1314-1.png
http://www.verydoc.com/images/err1314-2.png

Please look at following page for the details about ERROR 1314,

http://www.verydoc.com/exeshell.html


Example 5: Run conversion from ColdFusion code,

Below is the equivalent for ColdFusion:
<cfset mylicense ="XXXXXXXXXXXXXXX">
<cfset myInDoc = "C:\test\test.doc">
<cfset myOutDoc = "C:\test\test.jpg">
<cfset myUser = "user">
<cfset myPassword = "password">

<cfobject action="create" type="com" class="DocPrintCom.docPrint" name="docPrintObj">
<cfset temp = docPrintObj.docPrintCOM_Register("#mylicense#", "VeryPDF.com Company")>
<cfset temp = docPrintObj.docPrintCOM_DocumentConverterEx("#myUser#", "#myPassword#", "#myInDoc#", "#myOutDoc#", "-* #mylicense# -d")>


Example 5: Call doc2pdf.exe from Java code,

import java.io.*;
public class CmdExec {
    public static void main(String argv[]) {
        try {
            String strCmdLine = ""C:\\Program Files\\docPrint Pro v4.0\\doc2pdf.exe" -i C:\\input.doc -o C:\\output.pdf";
            Process p = Runtime.getRuntime().exec(strCmdLine);
            p.waitFor();
            System.out.println(p.exitValue());
        }
        catch (Exception err) {
            err.printStackTrace();
        }
    }
}


Example 6: Run conversion via "docPrint_Service.exe" application,

Please by following steps to run conversion via "docPrint_Service.exe" application,

1. Please login your server via Remote Desktop under Administrator user account (or other user accounts who own Administrator right),

2. Please run "docPrint_Service.exe" application,

    "C:\Program Files\docPrint Pro v5.0\docPrint_Service.exe"

3. Call RunCmd() method to deliver a command line to "docPrint_Service.exe" application,

PHP example,

<?php
    $com = new COM("DocPrintCom.docPrint");
    $com->docPrintCOM_Register("XXXXXXXXXXXXXX","VeryPDF.com Inc.");
    $com->RunCmd("-i http://www.verypdf.com -o C:\\test\\output.pdf -* XXXXXXXXXXXXXX -d -O 2 -s ShowHTMLStatusBar=1 -l 10000", 0);
?>

VB example,

Private Sub Command1_Click()
    Set docPrint = CreateObject("DocPrintCom.docPrint")
    nRet = docPrint.docPrintCOM_Register("XXXXXXXXXXXXXX", "VeryPDF.com Company")
    nRet = docPrint.RunCmd("-i http://www.verypdf.com -o C:\output.pdf -* XXXXXXXXXXXXXX -d -O 2 -s ShowHTMLStatusBar=1 -l 10000", 0)
    MsgBox "Return value = " & Str(nRet)
End Sub

4. Close Remote Desktop and leave this user logged in.

*Please Notice: After you reboot the server, you need login your server via Remote Desktop with this user account ("docPrint_Service.exe" was installed inside this user account), and close Remote Desktop, leave this user logged in, when you call RunCmd() function, the conversion will be executed from this user account automatically.


Example 7: Run conversion inside an interactive user account from service or web applications,

Please by following solution to run document conversion inside an interactive user account,

1. Please add "Everyone" user account to "C:\Program Files\docPrint Pro v5.0" folder and sub-folders, give "Full Control" permission to "Everyone" user account,

2. Download CmdAsUser.exe from following page,

http://www.verydoc.com/exeshell.html

You can also download it from following URL directly,

http://www.verydoc.com/download/cmdasuser.zip

3. Run following command line to test CmdAsUser.exe application,

C:\test\CmdAsUser.exe Administrator . /p password /c "C:\Program Files\docPrint Pro v5.0\doc2pdf.exe" -i http://www.google.com -o C:\test\out.pdf

OR

C:\test\CmdAsUser.exe Administrator . /p password /c "C:\Program Files\docPrint Pro v5.0\doc2pdf.exe" -i C:\test\test.doc -o C:\test\test.pdf

If you can run above command line in Command Line Window correctly, please call above command line from PHP by shell_exec() function or other web applications, then you will get it work properly.

Please notice:
1. You need modify "Administrator" and "password" parameters to correct user name and password in above command line, CmdAsUser.exe will launch doc2pdf.exe from this special user account with administrator privilege.
2. You may encounter Error 1314 in some Windows systems when you switch between user accounts, this is caused by permission setting, please by following steps to solve this 1314 Error,

ERROR 1314:
~~~~~~~~~~~~~
1314 A required privilege is not held by the client. ERROR_PRIVILEGE_NOT_HELD
~~~~~~~~~~~~~

To resolve this issue:
1. Click Start, click Run, type "secpol.msc", and then press ENTER.
2. Double-click "Local Policies".
3. Double-click "User Rights Assignment".
4. Double-click "Replace a process level token".
5. Click "Add", and then double-click the "Everyone" group
6. Click "OK".
7. You may have to logout or even reboot to have this change take effect.

Please refer to following two screenshots to understand above steps,

http://www.verydoc.com/images/err1314-1.png
http://www.verydoc.com/images/err1314-2.png

Please look at following page for the details about ERROR 1314,

http://www.verydoc.com/exeshell.html


VeryPDF.com | VeryDOC.com | VeryPCL.com | Links | Contact

Copyright © 2002- VeryPDF.com, Inc. All rights reserved.
Send comments about this site to the webmaster.