www.webdeveloper.com
Results 1 to 4 of 4

Thread: .doc to .pdf using php

  1. #1
    Join Date
    Nov 2006
    Posts
    4

    .doc to .pdf using php

    Hi

    I want convert .doc file into .pdf file .
    How we can do this using php?

    I need help?

    Thnaks in advance.

    Best regards
    zohab.

  2. #2
    Join Date
    Oct 2005
    Location
    Gold Coast, Australia
    Posts
    2,115
    Here's a Windows PHP converter of Word documents to PDF using OpenOffice via a COM wrapper of the OpenOffice API's. It's a lot of description for something fairly simple.

    PHP Code:
    <?php
    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){
    //Invoke the OpenOffice.org service manager
    $osm = new COM("com.sun.star.ServiceManager") or die ("Please be sure that OpenOffice.org is installed.\n");
    //Set the application to remain hidden to avoid flashing the document onscreen
    $args = array(MakePropertyValue("Hidden",true,$osm));
    //Launch the desktop
    $*****top $osm->createInstance("com.sun.star.frame.Desktop");
    //Load the .doc file, and pass in the "Hidden" property from above
    $oWriterDoc $*****top->loadComponentFromURL($doc_url,"_blank"0$args);
    //Set up the arguments for the PDF output
    $export_args = array(MakePropertyValue("FilterName","writer_pdf_Export",$osm));
    //Write out the PDF
    $oWriterDoc->storeToURL($output_url,$export_args);
    $oWriterDoc->close(true);
    }
    $output_dir "C:/dev/openofficeintegration/docconverter/";
    $doc_file "C:/dev/openofficeintegration/docconverter/DpmR5Reqv1.20.doc";
    $pdf_file "DpmR5Reqv1.20.pdf";
    $output_file $output_dir $pdf_file;
    $doc_file "file:///" $doc_file;
    $output_file "file:///" $output_file;
    word2pdf($doc_file,$output_file);
    ?>
    http://www.wynia.org/wordpress/word-...-php-word2pdf/

  3. #3
    Join Date
    Feb 2008
    Posts
    7

    Time out new COM("com.sun.star.ServiceManager")

    Hi can somewone help out...
    I want to connect to openoffice using php
    But my code stucks at

    $osm = new COM("com.sun.star.ServiceManager") or die ("Please be sure that OpenOffice.org is installed.\n");

    with a Time out message!

    does anyone why this is???

  4. #4
    Join Date
    Jul 2008
    Posts
    1

    please help...

    <?php
    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){
    //Invoke the OpenOffice.org service manager
    $osm = new COM("com.sun.star.ServiceManager") or die ("Please be sure that OpenOffice.org is installed.\n");
    //Set the application to remain hidden to avoid flashing the document onscreen
    $args = array(MakePropertyValue("Hidden",true,$osm));
    //Launch the desktop
    $*****top = $osm->createInstance("com.sun.star.frame.Desktop");
    //Load the .doc file, and pass in the "Hidden" property from above
    $oWriterDoc = $*****top->loadComponentFromURL($doc_url,"_blank", 0, $args);
    //Set up the arguments for the PDF output
    $export_args = array(MakePropertyValue("FilterName","writer_pdf_Export",$osm));
    //Write out the PDF
    $oWriterDoc->storeToURL($output_url,$export_args);
    $oWriterDoc->close(true);
    }
    $output_dir = "C:/dev/openofficeintegration/docconverter/";
    $doc_file = "C:/dev/openofficeintegration/docconverter/DpmR5Reqv1.20.doc";
    $pdf_file = "DpmR5Reqv1.20.pdf";
    $output_file = $output_dir . $pdf_file;
    $doc_file = "file:///" . $doc_file;
    $output_file = "file:///" . $output_file;
    word2pdf($doc_file,$output_file);
    ?>


    dear super moderator, i had used the above programs and it had been success for open office(.doc) document, the file size of document is smaller than the original one. so i try for ms office(.doc) it also success but the file size result is bigger than the original file.please help me in order that the file size from ms office(.doc) conversion to pdf is also become smaller than the original.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles