PHP COM script
Posted: Mon Oct 06, 2008 6:33 pm
Hi,
I created a script in PHP to convert mutiple files to PDF using COM. Here it is (defaults to everything in z:\):
$x = new COM('Bullzip.PDFPrinterSettings');
$printername = $x->GetPrinterName;
$runonce = $x->GetSettingsFileName(true);
foreach (glob('z:\*.xls') as $printfile)
{
$x->Init();
$x->SetValue('Output', "$printfile.pdf");
$x->SetValue('ShowSettings', 'never');
$x->SetValue('ShowPDF', 'no');
$x->SetValue('WatermarkText', 'teste');
$x->SetValue('ShowProgress', 'no');
$x->SetValue('ShowProgressFinished', 'no');
$x->SetValue('SuppressErrors', 'yes');
$x->SetValue('ConfirmOverwrite', 'no');
$x->WriteSettings (true);
exec ('z:\printto.exe "' . $printfile . '" "' . $printername . '"');
while (file_exists($runonce))
{
usleep(100000);
}
}
$x = null;
I faced an unusual problem both in Bullzip PDF Printer and PDFcreator and I think is OS related. HTML files always prompt for the "print dialog" no matter you use a script in VBA, C, PHP or whatever, and therefore hang the script. If anyone knows a workaround I would be glad to have it.
If any other file (most usually spreadsheets) cause the host program to ask for saving changes (even if there isn't any), it will also naturally hang the script.
I created a script in PHP to convert mutiple files to PDF using COM. Here it is (defaults to everything in z:\):
$x = new COM('Bullzip.PDFPrinterSettings');
$printername = $x->GetPrinterName;
$runonce = $x->GetSettingsFileName(true);
foreach (glob('z:\*.xls') as $printfile)
{
$x->Init();
$x->SetValue('Output', "$printfile.pdf");
$x->SetValue('ShowSettings', 'never');
$x->SetValue('ShowPDF', 'no');
$x->SetValue('WatermarkText', 'teste');
$x->SetValue('ShowProgress', 'no');
$x->SetValue('ShowProgressFinished', 'no');
$x->SetValue('SuppressErrors', 'yes');
$x->SetValue('ConfirmOverwrite', 'no');
$x->WriteSettings (true);
exec ('z:\printto.exe "' . $printfile . '" "' . $printername . '"');
while (file_exists($runonce))
{
usleep(100000);
}
}
$x = null;
I faced an unusual problem both in Bullzip PDF Printer and PDFcreator and I think is OS related. HTML files always prompt for the "print dialog" no matter you use a script in VBA, C, PHP or whatever, and therefore hang the script. If anyone knows a workaround I would be glad to have it.
If any other file (most usually spreadsheets) cause the host program to ask for saving changes (even if there isn't any), it will also naturally hang the script.