This Server application converts Office files to PDF by using ghostscript with Postscript printer.
By : yuppie
<?
//For more Information or a PYthon Server Pages based application see http://www.goermezer.de
//Developed by Mustafa Görmezer
//Please leave the above 3 comments in this script !
$printername="PDF-Datei mit erweiterten Einstellungen"
$psfile="C:\\temp\\".$_FILES['userfile']['name'].".ps";
$pdffile="c:\\Apache2\\htdocs\\uploads\\".$_FILES['userfile']['name'].".pdf";
$result_link="<b>Result: <a href='http://lap-ibm-331/downloads/".$_FILES['userfile']['name'].".pdf'>Open PDF Result</a>\n";
$uploaddir = 'c:\\Apache2\\htdocs\\uploads\\';
$uploaded_doc=$uploaddir.$_FILES['userfile']['name'];
$gsinst="c:\\gs\\gs8.13\\bin\\gswin32c.exe"
?>
<html><head><title>PDF Document Converter</title></head>
<body bgcolor="#FFFFFF" text="#000000" link="#0000FF">
<table width="100%" border="0">
<tr>
<td width="94%"><b>Office2PDF Conversion Service</b></td>
</tr>
<tr>
<td>Supported Formats: doc, rtf, xls, ppt, txt, html, ps, eps</td>
</tr>
</table>
<form enctype="multipart/form-data" action="<? $PHP_SELF ?>" method="post">
<table width="100%" border="0" bgcolor="#CCCCCC">
<tr>
<td width="17%">Office File: </td>
<td width="83%"><input name="userfile" type="file"></td>
</tr>
<tr>
<td width="17%">Document-Password (if given): </td>
<td width="83%"><input name="password" type="password"></td>
</tr>
<tr>
<td>Quality: </td>
<td><table width="200">
<tr>
<td><label>
<input type="radio" name="quality" value="300dpi">
300 DPI</label>
</td>
</tr>
<tr>
<td><label>
<input type="radio" name="quality" value="600dpi">
600 DPI</label>
</td>
</tr>
<tr>
<td><label>
<input type="radio" name="quality" value="1200dpi">
1200 DPI</label>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>Start conversion</td>
<td><input type="submit" name="send" value="send file">
</td>
</tr>
</table>
</form>
<?
if ($_POST['password']){
$password=$_POST['password'];
}
else { $password="False"; }
list ($name, $suffix) = split ('[.]', $_FILES['userfile']['name']);
function excel($document, $ps_file, $pdf_file){
$excel = new COM("excel.application") or die("Unable to instantiate Excel");
$excel->AskToUpdateLinks = 0;
$excel->Workbooks->Open($document);
$excel->Workbooks[1]->Saved=1;
$excel->Workbooks[1]->PrintOut(1, 5000, 1, False, $printername, True, False, $ps_file);
$excel->Workbooks[1]->Close(false);
$excel->Quit();
$excel->Release();
$excel = null;
unset($excel);
while (exec("$gsinst -sDEVICE=pdfwrite -r300 -dNOPAUSE -dBATCH -dSAFER -sPAPERSIZE=a4 -sOutputFile=\"".escapeshellcmd($pdf_file)."\" \"".escapeshellcmd($ps_file)."\"") > 0){
sleep(1);
}
}
function powerpoint($document, $ps_file, $pdf_file){
$powerpoint = new COM("powerpoint.application") or die("Unable to instantiate Powerpoint");
$powerpoint->Visible = 1;
$powerpoint->Presentations->Open($document, False, False, False, False);
$powerpoint->Presentations[1]->Saved=1;
$powerpoint->ActivePrinter = $printername;
$powerpoint->Presentations[1]->PrintOut(1, 5000, $ps_file, 0, False);
$powerpoint->Presentations[1]->Close();
$powerpoint->Quit();
$powerpoint->Release();
$powerpoint = null;
unset($powerpoint);
while (exec("$gsinst -sDEVICE=pdfwrite -r300 -dNOPAUSE -dBATCH -dSAFER -sPAPERSIZE=a4 -sOutputFile=\"".escapeshellcmd($pdf_file)."\" \"".escapeshellcmd($ps_file)."\"") > 0) {
sleep(1);
}
}
function word($document, $ps_file, $pdf_file, $passwd){
$word = new COM("word.application") or die("Unable to instantiate Word");
//$word->Visible = 0;
$word->Documents->Open($document, False, True, False, $passwd);
$word->Documents[1]->Saved = 1;
$word->ActivePrinter = "PDF-Datei mit erweiterten Einstellungen";
$word->Documents[1]->PrintOut(True, False, 0, $ps_file);
while($word->BackgroundPrintingStatus > 0){
sleep(1);
}
$word->Documents[1]->Close(false);
$word->Quit();
$word->Release();
$word = null;
unset($word);
while (exec("$gsinst -sDEVICE=pdfwrite -r300 -dNOPAUSE -dBATCH -dSAFER -sPAPERSIZE=a4 -sOutputFile=\"".escapeshellcmd($pdf_file)."\" \"".escapeshellcmd($ps_file)."\"") > 0){
sleep(1);
}
}
if ($_POST['send']){
print "<pre>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir.$_FILES['userfile']['name'])) {
if ($suffix=="doc" || $suffix=="dot" || $suffix=="htm" || $suffix=="html" || $suffix=="txt" || $suffix=="rtf"){
word($uploaded_doc, $psfile, $pdffile, $password);
}
elseif ($suffix=="xls" || $suffix=="xlt" || $suffix=="csv"){
excel($uploaded_doc, $psfile, $pdffile);
}
elseif ($suffix=="ps" || $suffix=="prn" || $suffix=="eps"){
while (exec("$gsinst -dBATCH -sDEVICE=pdfwrite -sOutputFile=\"c:\\apache2\\htdocs\\uploads\\".escapeshellcmd($pdffile)."\" -dNOPAUSE \"$uploaded_doc\"") > 0){
sleep(1);
}
}
elseif ($suffix=="ppt" || $suffix=="pps" || $suffix=="pot" || $suffix=="PPT"){
powerpoint($uploaded_doc, $psfile, $pdffile);
} else {
echo'<strong><font color="#FF0000">Dateiformat wird nicht unterstützt !!!</strong></font><br>';
//exec("del \"$uploaded_doc\"");//Hochgeladene Datei löschen
echo'<strong><font color="#FF0000">Hochgeladene Datei wieder gelöscht.</strong></font>';
exit();
}
} else {
echo '<strong><font color="#FF0000">Datei konnte nicht hochgeladen werden !</strong></font>';
exit();
}
while (!(is_writable($pdffile))){
sleep(1);
}
if (!headers_sent()) {
$header="http://localhost/uploads/".$_FILES['userfile']['name'].".pdf";
header ("Location: $header");
exit();
} else { echo 'Das Resultat befindet sich für 24 Stunden unter: <a href="http://rechnername/uploads/'.$_FILES['userfile']['name'].'.pdf">'.$_FILES['userfile']['name'].'.pdf</a>'; }
exit();
}
?>
</BODY>
</HTML>
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Miscellaneous Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
Join this Rational Talks to You teleconference on December 4 at 1:00 pm ET to discuss how Rational Method Composer can help meet your compliance objectives. Get your questions answered! FREE! Go There Now!
|
|
|
|
XML has become a common way of storing business data as flat files and many data server vendors including IBM have provided ways to store this data within relational database systems. Increasingly collections of XML files are accessed like databases using an xQuery and other XML standard mechanisms. Businesses find the need to combine the traditional tabular structured data with XML formatted data. In this webcast, you’ll learn about IBM’s WebSphere Federation Server technology, which provides users with the ability to integrate these two data formats. FREE! Go There Now!
|
|
|
|
Effective governance for lean development isn’t about command and control. Instead, the focus is on enabling the right behaviors and practices through collaborative and supportive techniques. Hear from Scott Ambler on how it is far more effective to motivate people to do the right thing than it is to force them to do so. Learn how to form a lightweight, collaboration-based framework that reflects the realities of modern IT organizations. FREE! Go There Now!
|
|
|
|
The Eclipse community is constantly working to extend Eclipse's functionality. In this webcast, learn about some of the most important and feature-rich projects under development. From multi-language support to plug-in development, tune in to see what Eclipse is capable of now. FREE! Go There Now!
|
|
|
|
Join this webcast, to learn how the Rational Process Library can help with compliance issues, drive process improvement, and assist in service-oriented architecture (SOA) or Agile development. We will take a peek into the Rational Process Library with content around software and systems engineering (including RUP), operations and systems management, program and portfolio management, and asset and SOA governance. FREE! Go There Now!
|
|
|
|
IBM Enterprise Modernization solutions help organizations evolve core IT systems towards modern architectures and technologies—reducing the burden of maintenance and freeing up resources to develop new business requirements and capabilities. With the IBM Enterprise Modernization Sandbox for System z you can evaluate IBM Enterprise Modernization solutions focused on five key areas: Assets, Architectures, Skills, Processes and Infrastructures, and Investment. Each solution is based upon real customer experiences and offers a proven path to get you started with your modernization projects. FREE! Go There Now!
|
|
|
|
Learn field-tested SOA principles, methodology, technology and implementation from the global SOA market leader - in a new e-book by an IBM SOA expert. Written by IBM Certified SOA Solution Designer Bobby Woolf, "Exploring IBM SOA Technology & Practice" is the ultimate insider's guide to SOA - a PDF e-book packed cover to cover with IBM's specific advice on how to make your SOA implementation a success. FREE! Go There Now!
|
|
|
|
As organizations integrate software into every aspect of business, they are constantly pressured to deliver faster, better, and cheaper results. Unfortunately, a “dis-integrated” software delivery approach reduces returns while increasing costs. This IBM Rational White Paper shows how Integrated Requirements Management aligns organizations around maximizing value and keeping pace with change. FREE! Go There Now!
|
|
|
|
Join us for this on demand webcast to learn about developing complex systems more quickly and efficiently. We'll cover market drivers for developing, governing and reusing systems software assets and how you can develop system software assets with Rational Asset Manager. FREE! Go There Now!
|
|
|
|
Discover how IBM Rational AppScan Standard Edition can help you detext vulnerabilities in your web applications in the Web Application Security eKit. IBM Rational AppScan is a leading suite of automated web application security solutions that scan and test for common Web application vulnerabilities. The new Web Application Security eKit provides you with valuable resources, including white papers, demos, and additional information on the benefits of testing your Web applications. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |