PHPBuilder - COM Functions in PHP4 Page 4



RSS Twitter
Articles Php Functions

COM Functions in PHP4 - Page 4

by: Alain M. Samoun
|
October 3, 2000

Using PHP COM with Adobe Distiller

This last example is for a non-MS program: If your program has produced a PostScript document, it may be interesting to transform it (Distill it) to a PDF document. Adobe has a program called Distiller with a windows version that can be instantiated, with the following code:

<?php

$pdf 
= new COM('pdfdistiller.pdfdistiller.1');

?>
Note that the OLE Identifier name is not obvious, especially when the distiller documentation (Adobe's Technical Note #5158) refers to it as "pdfdistiller".
The principal method to distill a document is:

<?php

$pdf
->FileToPdf ($psfilestrOutputPDF ''strJobOptions "");    

?>
Where $psfile is the name of the PostScript file, strOutputPDF is the name for the output PDF file. StrJobOptions is the name of the parameters file for Distiller. The two last parameters of the method can be left blank to use the same name, the PS file for the PDF file and to use the default Job options file. For example:

<?php

$pdf
->FileToPdf ($psfile""""); 
#Where $psfile could be Myfile.ps and the result file: Myfile.pdf 

?>
There are more methods and properties that can be used with Distiller. If you are interested, look at the Adobe's technical note.

Caveats/Possible problems

If there are some errors in your code, you may instantiate the object and your program may not close before it times out. Worst of all, the application may retentively be instantiated. As a result, several copies may lay around in your programs list and interfere after you have corrected the problem. The solution: After fixing the bug, clean up (<CTRL+ALT+Delete> and End Task) all the instances in the program list before you restart. For this same reason, always close the application at the end of your code and unlink the instance.
You may experience some oddities with com_get and com_set. For example: $Version = Com_get($instance->Application,"Version"); Works with Word, but produces an error with Excel.
Some Objects won't be instantiated by PHP4, it appears that these objects need a custom interface that PHP4-COM doesn't support.

Why use it?

Hopefully, these three examples have shown you the ropes. PHP COM allows the connection to many Windows programs inside a PHP script. The code is simpler than ASP's and can be integrated with the rest of PHP's powerful database functions. Microsoft markets the COM technology everywhere and under different names and architectures, like COM+(Combine COM with Microsoft Transaction Server MTS), ADO, OLE DB, OWC, Windows DNA, etc. PHP and Apache, working together, are now offering an open source solution to this confusion.
--Alain
PS: See the EXCEL class using the COM interface at: http://phpclasses.upperdesign.com/browse.html?package=86

« Previous Page
1
|
2
|
3
|
4

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Alain M. Samoun

Comment:



Comment:

(Maximum characters: 1200). You have characters left.