User login

Donate

Donate for server costs [more]

Target:
$ 3000
Achieved:
$ 186.3
Fees:
$ 13.36
6.2 %
Donate
SourceForge.net Logo

PHP Scripting with COM

7 replies [Last post]
Antjac
Offline
Joined: 10/12/2009

Hi,

 

I'll like to create a script to convert an office document (XLS) to PDF by using PDFCreator and its COM object.

I used the examples in JS in the documentation

Here is my script

http://pastebin.com/mca806d8

It doesn't work (infinite loops and timeout)

Could you help me ?

 

Thx, Antoine ALEXANDRE

 

hugo69
Offline
Joined: 10/27/2009

Hy I have the same problem...

 

did you find a solution?

Antjac
Offline
Joined: 10/12/2009

No... any idea ?

<?php

$maxTime = 30 ; // in seconds
$sleepTime = 250; // in milliseconds

echo "buh";
$ifname='C://test.xls';
$PDFCreator = New COM("PDFCreator.clsPDFCreator") or die("Couldn\' start the COM-object");
$PDFCreator->cStart("/NoProcessingAtStartup");

$PDFCreator->cOptions->UseAutosave = 1;
$PDFCreator->cOptions->UseAutosaveDirectory = 1;
$PDFCreator->cOptions->AutosaveFormat = 0;

$DefaultPrinter = $PDFCreator->cDefaultprinter;

$PDFCreator->cDefaultprinter = "PDFCreator";
$PDFCreator->cClearcache();

if (!file_exists($ifname))
{
echo "Can't find the file: " .$ifname;
break;
}

if (!$PDFCreator->cIsPrintable($ifname))
{
echo "Converting: " .$ifname ."\r\n\r\nAn error is occured: File is not printable!";
break;
}

$ReadyState = 0;

$PDFCreator->cOptions->AutosaveDirectory = realpath($ifname);
$PDFCreator->cOptions->AutosaveFilename = basename("C:\test.pdf");
$PDFCreator->cPrintfile($ifname); //C'est cette ligne qui bloque
$PDFCreator->cPrinterStop = false;

// Wait 1000 miliseconds..
// This is a specific PHP-function, so you'll have to
// change this one for something else
com_message_pump(1000);

// Set the default printer back to the old one
//$PDFC->cDefaultprinter = $DefaultPrinter;
// Clear cache (again don't know why :) )
$PDFCreator->cClearcache();
// ...wait
com_message_pump(200);
// Close the printer
$PDFCreator->cClose();
?>

devcphp
Offline
Joined: 12/24/2009

Hello alexandre ,

I try about 2 months to make that you want to do in php.The only result i have make is to pass with script vb by invoking exec function.

 

If you want , i can send you my script.

However, i have try your script and the service not appaer in the evenement task .I don't know why.

 

sorry for my english i'm french.

I hope have more informations with you. that's coulud be fun to complete that .

ChopStickr
Offline
Joined: 12/30/2009

I had problems getting PHP to work with the COM object as well.  After looking at other examples in the COM folder (Python\Testpage2PDF.py) I tried the cSaveOptions method and it worked.  Here is my example.  I got it to work running PHP at the command line and tested it with an XLS and a TXT input file.

<?php
$ifname='C:\\test.xls';
$PDFCreator = New COM("PDFCreator.clsPDFCreator") or die("Couldn\' start the COM-object");
$PDFCreator->cStart("/NoProcessingAtStartup");

$options = $PDFCreator->cOptions;
$options->UseAutosave = 1;
$options->UseAutosaveDirectory = 1;
$options->AutosaveFormat = 0;
$options->AutosaveDirectory = "c:\\";
$options->AutosaveFilename = "test.pdf";
$PDFCreator->cOptions = $options;
$PDFCreator->cSaveOptions();
//for testing.  Shows you that $PDFCreator has the options you set
//$PDFCreator->cSaveOptionsToFile('c:\\PDFOptions.ini');

$DefaultPrinter = $PDFCreator->cDefaultprinter;

$PDFCreator->cDefaultprinter = "PDFCreator";
$PDFCreator->cClearcache();

if (!file_exists($ifname))
{
echo "Can't find the file: " .$ifname;
break;
}

if (!$PDFCreator->cIsPrintable($ifname))
{
echo "Converting: " .$ifname ."\r\n\r\nAn error is occured: File is not printable!";
break;
}

//$PDFCreator->cSaveOptionsToFile('c:\\PDFOptions.ini');
$PDFCreator->cPrintfile($ifname);

$PDFCreator->cPrinterStop = false;

// Wait 1000 miliseconds..
// This is a specific PHP-function, so you'll have to
// change this one for something else
com_message_pump(1000);

// Set the default printer back to the old one
//$PDFC->cDefaultprinter = $DefaultPrinter;
// Clear cache (again don't know why :) )
$PDFCreator->cClearcache();
// ...wait
com_message_pump(200);
// Close the printer
$PDFCreator->cClose();

?>

 

Hope this can help someone.

immez
Offline
Joined: 01/06/2010

Thanks ChopStickr! I use your code successfully created pdf file from TXT file. But I encounter a problem with other file formats :-(

If the file was a ".doc" or ".xls", the pdfCreator will init a winword.exe or an excel.exe process and then occupied 100% cpu, and then stop to resonpse...The php script will hopeless run until it exceed the max_execution_time.

I have no idea about this. I have Office 2003 in my computer and I am using pdfCreator 0.9.9.

dinowilliam
Offline
Joined: 02/10/2010

Hi, Thanks for the example

But unfortunately i have a problem with it, in the line $options = $PDFCreator->cOptions; the php return an error with the following description:

      PHP Fatal error: Uncaught exception 'com_exception' with message 'Error [0x8002000f] Parameter not optional.

       I don´t have any idea about the cause of this erro, if you can help I appreciate :).

Thanks for any help

 

 

 

 

krambiorix
Offline
Joined: 09/20/2010

Hi guys,

i use this script http://www.pdfforge.org/forum/open-discussion/5196-convert-word-pdf-usin... .

I followed all steps in the readme file but no PDF is created.

PDFCreator and Word start but no PDF is generated...
CPU also up to 100%...

Can someone help?

Greets

© pdfforge.org :: Contact us :: Sitemap