Convert Word format files to PDF files with PHP

Source: Internet
Author: User
Small series of non-professional PHP Professional staff, so before this small series still do not know how in PHP format, you can also convert Word files into PDF files, so today's small series and everyone to share with you in the word format of PHP file converted to PDF files, I hope it helps.

PHP calls COM component Configuration take OpenOffice as an example

What is a COM component?

COM architecture, people can develop a variety of functional-specificity components, and then combine them as needed to form a complex application system. COM and language, platform-independent features enable all programmers to fully develop their talents and expertise in writing component modules.

The purpose of the configuration is primarily to solve the problem of inability to create COM objects, actually to implement the functionality of Word PPT XML into PDF

The COM Component Configuration group in PHP call OpenOffice is divided into three steps

1. JDK support, possibly with both software and sun company

Download Address

2. Installing OpenOffice

Configuration of Download Address permissions

. Run Dcomcnfg.exe
Component Services--computer--My Computer ――dcom configuration--Select

  

Right-click--Properties--

  

Configure two red markers in a diagram

Mark---Select an interactive user

Security--Start and Activate permissions and access permissions to configure

Same way

  

For editing

Icon

  

Complete the task at this point

Here are the steps to proceed:

1, install the free OpenOffice software, please go to OpenOffice.org download the latest version.

2, JDK support, please self-search download the latest version of the JDK.

3, after the installation of OpenOffice, in the start-run input DCOMCNFG open Component Services. In the Component Services-computer-My Computer-dcomp configuration, select


On these two items, click the Right button property, open the properties panel such as:


Select the Security tab, and then click Customize on the start and Activate permissions and access permissions to add the permissions for everyone.

Select the Identity tab and select the Interactive user.

4, after the installation of OpenOffice, please first confirm that you can run the software properly, and then exit and then run the following command with the command line.

First to the installation directory, for example: C:\Program files\openoffice 4\program\

Execute command:

Soffice-headless-accept= "SOCKET,HOST=127.0.0.1,PORT=8100;URP;"-nofirststartwizard

After success, the software is run in the background.

5, if it is php5.4.5 previous version, need to php.ini com.allow_dcom = True Open, that is, remove the preceding semicolon. If it is a later version, you need to add a line extension Extension=php_com_dotnet.dll in the php.ini, and then check the PHP ext directory for the DLL file, if not please download the corresponding version of the DLL. Then restart the Apache or IIS server.

6. Code implementation

<?php//php can also implement the ability to export Word documents to PDF, but with the help of a third-party class library, today we'll show you how PHP relies on Com.sun.star.ServiceManager to convert Word to PDF documents. Sample code for PHP handling Word to PDF: Set_time_limit (0), function makepropertyvalue ($name, $value, $osm) {$oStruct = $osm->bridge_ Getstruct ("Com.sun.star.beans.PropertyValue"); $oStruct->name = $name; $oStruct->value = $value; return $oStruct ;} function Word2pdf ($doc _url, $output _url) {$osm = new COM ("Com.sun.star.ServiceManager") or Die (" Make sure the OpenOffice.org Library is installed. \ n "), $args = Array (Makepropertyvalue (" Hidden ", True, $osm)); $oDesktop = $osm CreateInstance ("Com.sun.star.frame.Desktop"); $oWriterDoc = $oDesktop->loadcomponentfromurl ($doc _url, "_blank", 0, $args), $export _args = Array (Makepropertyvalue ("FilterName", "Writer_pdf_export", $osm)); $oWriterDoc Storetourl ($output _url, $export _args); $oWriterDoc->close (true);} $output _dir = "d:/temp/"; $doc _file = "D:/temps/test03.docx"; $pdf _file = "Test03.pdf"; $output _file = $output _dir. $pdf _ file; $doc _file = "file:///". $doc _file; $output _file = "Word2pdf ($Doc_file, $output _file);? >

Above is all the content, no matter whether such methods have completely help you solve the problem, hope can give you to solve such problems of thinking, if you have better suggestions can also be in the comment area.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.