Code Samples - Document Converter Pro

Example 1: How to convert a file (submitFile method) - PHP

Copy the following PHP scripts (main.php, checkstatus.php, error.php and done.php) into your web site root.

main.php Copy 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
   <?php

     // set where you want to store the uploaded files
     // in this example we keep file in folder tmpUpload
     $tmpFldr = realpath("./tmpUpload");

     if (!empty($_FILES['myFile']['name'])) {

       $DC = New COM("Neevia.docConverter");
       $docID = $DC->GUID;

       $path = $tmpFldr ."\\". $docID . $DC->getExtensionName( $_FILES['myFile']['name'] );

       print $path;

       if (move_uploaded_file($_FILES['myFile']['tmp_name'], $path))
       {
          $DC->setParameter("DocumentOutputFolder", realpath(".") );

          $rVal = $DC->submitFile( $path, "" );

          $DC->fileDelete( $path );

          if ($rVal != 0 ) {
            header("Location: error.php");
          }else{
            header("Location: checkStatus.php?docID=" . $docID . $DC->getExtensionName($path));
          }
       }
     }

   ?>
   <HTML>
   <HEAD>
     <TITLE>Neevia Document Converter Pro sample file</TITLE>
   </HEAD>
   <BODY><CENTER>
   <FORM action="main.php" method="post" enctype="multipart/form-data">
   Select File: <INPUT type="file" name="myFile"><BR>
   <INPUT type="submit" name="submit" value="Convert">
   </FORM>
   </BODY>
   </HTML>

checkstatus.php Copy 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
   <?php
     $DC = New COM("Neevia.docConverter");

     $DC->setParameter("DocumentOutputFolder", realpath("."));

     $docID=$_REQUEST["docID"];

     $rVal = $DC->checkStatus($docID, "");
     if ($rVal==0){
       header("Location: done.php?docID=". $DC->getBaseName( $docID ));
     } else {
       if ($rVal != 2) { header("Location: error.php"); }
     }
   ?>
   <HTML>
   <HEAD>
    <TITLE>Neevia.com</TITLE>
    <META HTTP-EQUIV="refresh" CONTENT="2">
   </HEAD>
   <BODY><BR><BR><CENTER>
   <H1>CONVERTING - PLEASE WAIT!!!</H1>
   </BODY>
   </HTML>

error.php Copy 

1
2
3
4
5
   <HTML>
   <BODY><BR><BR><CENTER>
   <H1>THERE WAS AN ERROR CONVERTING THE DOCUMENT</H1>
   </BODY>
   </HTML>

done.php Copy 

1
2
3
4
5
6
   <HTML>
   <BODY topMargin="0" leftMargin="0" scroll="no">
   <EMBED src="<?php echo $_REQUEST["docID"] . ".pdf" ?>" width="100%" height="100%" 
          fullscreen="yes">
   </BODY>
   </HTML>