Thursday 4 May 2017

simple web site for converting drawing file into 3d pdf using FME

Once in while our CIVIL users want to convert a drawing file into a 3d PDF file. As they are not familiar with FME and dont have access to it anyway I set up a web page where a drawing file can be uploaded and gets converted to a 3d PDF. FME 32bit is installed on the server just for this purpose.

The website consists of two frames. The first frame allows to upload the drawing file, the second frame just lists the contents of the folder on the server where the PDF file gets stored.

Here is the PHP code for the upload. After uploading it triggers the execution of a BATCH file (see below) which starts the FME workbench. The workbench is a simple ACAD drawing reader connected to an 3d PDF writer. Everything is kept very simple.


 <html>  
 <body>  
 <script>  
 //refresh download frame in order to list newly created PDF file  
 parent.frames['download'].location.reload();  
 </script>  
 <h1>DWG zu 3D PDF</h1>  
 <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" enctype="multipart/form-data">  
   DWG ausw&auml;hlen:  
   <input type="file" name="uploaded" id="fileToUpload"><br><br>  
      DWG hochladen:  
   <input type="submit" value="DWG hochladen" name="submit">  
 <br><br>  
 Nach dem Hochladen kann es einige Zeit dauern, bis die DWG konvertiert wurde. Bitte warten, bis eine Meldung erscheint.<br><br>  
 Im unteren Fenster sollte nach erfolgreicher Erstellung der PDF diese zum Download aufgelistet sein - falls nicht die gesamte Webseite aktualisieren.  
 <br><b>PDF bitte herunterladen (rechte Maustaste >> "Link speichern unter") - im Webbrowser werden keine 3d PDFs angezeigt.</b>  
 <br>  
 </form>  
 </body>  
 </html>  
 <?php  
 // PHP.INI  
 // upload_max_filesize = 20M  
 // --> if files are too big variables such as $_FILES['uploaded']['name'] and others are empty  
 // max_execution_time = 90  
 // FastCGI PHP in IIS execution time set to 90 secs  
 // Upload folder : set permissions  
 error_reporting(E_ALL);  
 if ($_POST['submit'] == '') die();       
 $target = "E:/www_fme_3dpdf_batch/uploads/";   
 $target = $target . basename( $_FILES['uploaded']['name']) ;   
 if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))  
 {   
      //sending message to browser - doesnt work with IIS it seems :-(  
      //ob_implicit_flush(true);  
      //ob_start();  
      //ob_flush();  
      echo "<br><br>Datei <b>'". basename( $_FILES['uploaded']['name']). "'</b> hochgeladen.";   
      echo "<br><br>Dateikonvertierung gestartet....<br><br>";        
      echo "<small><pre>";  
      system("cmd /c E:/www_fme_3dpdf_batch/run_fme_acad2pdf.bat 2>&1", $output);  
      echo "</small></pre>";  
 }   
 else   
 {   
      echo "Problem aufgetreten. Datei nicht hochgeladen.";   
 }   
 ?>  

The batch file content:

 SET SOURCE="E:\www_fme_3dpdf_batch\uploads"  
 SET OUTPUT="E:\www_fme_3dpdf_batch\downloads"  
 DEL /Q %OUTPUT%\*.*  
 FOR %%F IN ("%SOURCE%\*.dwg") DO (    
     C:\apps\FME32\fme.exe acad2pdf.fmw --SourceDataset_ACAD "%%F"^  
                --DestDataset_PDF "%OUTPUT%\%%~nF.pdf"^  
                --LOG_FILE "%OUTPUT%\%%~nF_load.log"  
 )  
 DEL /Q %SOURCE%\*.*  

No comments:

Post a Comment