Code Samples - Document Converter Pro

Example 3: How to convert an URL - 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
   <?php
     if ($_REQUEST["urlToConvert"] != "") {
       $DC = New COM("Neevia.docConverter");

       $DC->setParameter( "DocumentOutputFormat", "PDF" );
       $DC->setParameter( "DocumentOutputFolder", realpath(".") );
       $DC->setParameter( "PDFAutoRotatePage", "All" );

       $docID = $DC->GUID . ".url";
       $rVal = $DC->submitURL($_REQUEST["urlToConvert"], $docID, "");

       if ($rVal != 0 ) {
          header("Location: error.php");
       }else{
          header("Location: checkStatus.php?docID=" . $docID);
       }
     }
   ?>
   <HTML>
   <HEAD>
     <TITLE>Neevia Document Converter Pro sample file</TITLE>
   </HEAD>
   <BODY><CENTER>
   <FORM action="main.php">
   URL to convert:
   <INPUT type="input" name="urlToConvert" value="http://neevia.com"><BR>
   <INPUT type="submit" name="submit" value="Convert URL">
   </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>