dcsimg
www.webdeveloper.com
Results 1 to 7 of 7

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.

  5. #5
    Join Date
    Sep 2015
    Posts
    22
    Quote Originally Posted by retna.arliana View Post
    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);
    ?>

    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.
    Hi, retna.arliana.
    Thanks for your nice sharing. But I wonder do I need another
    pdf converter to deal with those code? Any sugegstion will be appreciated. Thanks in adcance.



    Best regards,
    Pan

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    20,979
    Since this is a 6+ year old thread, I would suggest not holding your breath waiting for an answer.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

  7. #7
    Join Date
    Feb 2015
    Posts
    85
    <?php

    class gridPdfGenerator {

    public $minOffsetTop = 10;
    public $minOffsetBottom = 10;
    public $minOffsetLeft = 10;
    public $minOffsetRight = 10;
    public $headerHeight = 7;
    public $rowHeight = 5;
    public $minColumnWidth = 13;
    public $pageNumberHeight = 10;
    public $fontSize = 8;
    public $dpi = 96;
    public $strip_tags = false;

    public $bgColor = 'D1E5FE';
    public $lineColor = 'A4BED4';
    public $headerTextColor = '000000';
    public $scaleOneColor = 'FFFFFF';
    public $scaleTwoColor = 'E3EFFF';
    public $gridTextColor = '000000';
    public $pageTextColor = '000000';

    public $footerImgHeight = 50;
    public $headerImgHeight = 50;
    public $lang = Array('a_meta_charset' => 'UTF-8', 'a_meta_dir' => 'ltr', 'a_meta_language' => 'en', 'w_page' => 'Page');

    private $orientation = 'P';
    private $columns = Array();
    private $rows = Array();
    private $summaryWidth;
    private $profile;
    private $header = false;
    private $footer = false;
    private $headerFile;
    private $footerFile;
    private $pageHeader = false;
    private $pageFooter = false;
    private $coll_options = Array();
    private $hiddenCols = Array();

    // print grid
    public function printGrid($xml) {
    $this->headerParse($xml->head);
    $this->footerParse($xml->foot);
    $this->mainParse($xml);
    $this->collectionsParse($xml->coll_options);
    $this->rowsParse($xml->row);
    $this->printGridPdf();
    }


    // sets colors according profile
    private function setProfile() {
    switch ($this->profile) {
    case 'color':
    $this->bgColor = 'D1E5FE';
    $this->lineColor = 'A4BED4';
    $this->headerTextColor = '000000';
    $this->scaleOneColor = 'FFFFFF';
    $this->scaleTwoColor = 'E3EFFF';
    $this->gridTextColor = '000000';
    $this->pageTextColor = '000000';
    break;
    case 'gray':
    $this->bgColor = 'E3E3E3';
    $this->lineColor = 'B8B8B8';
    $this->headerTextColor = '000000';
    $this->scaleOneColor = 'FFFFFF';
    $this->scaleTwoColor = 'EDEDED';
    $this->gridTextColor = '000000';
    $this->pageTextColor = '000000';
    break;
    case 'bw':
    $this->bgColor = 'FFFFFF';
    $this->lineColor = '000000';
    $this->headerTextColor = '000000';
    $this->scaleOneColor = 'FFFFFF';
    $this->scaleTwoColor = 'FFFFFF';
    $this->gridTextColor = '000000';
    $this->pageTextColor = '000000';
    break;
    }
    }
    private function mainParse($xml) {
    $this->profile = (string) $xml->attributes()->profile;
    if ($xml->attributes()->header) {
    $this->header = (string) $xml->attributes()->header;
    }
    if ($xml->attributes()->footer) {
    $this->footer = (string) $xml->attributes()->footer;
    }
    if ($xml->attributes()->pageheader) {
    $this->pageHeader = (string) $xml->attributes()->pageheader;
    }
    if ($xml->attributes()->pagefooter) {
    $this->pageFooter = $xml->attributes()->pagefooter;
    }
    if (100/count($this->widths) < $this->minColumnWidth) {
    $this->orientation = 'L';
    }
    if ($xml->attributes()->orientation) {
    if ($xml->attributes()->orientation == 'landscape') {
    $this->orientation = 'L';
    } else {
    $this->orientation = 'P';
    }
    }
    $this->setProfile();
    }
    public function printGridPdf() {
    if (($this->header)||($this->pageHeader)) {
    $this->headerImgInit();
    }
    if (($this->footer)||($this->pageFooter)) {
    $this->footerImgInit();
    }
    // initials PDF-wrapper
    $this->wrapper = new gridPdfWrapper($this->minOffsetTop, $this->minOffsetRight, $this->minOffsetBottom, $this->minOffsetLeft, $this->orientation, $this->fontSize, $this->dpi, $this->lang);
    // checking if document will have one page
    $pageHeight = $this->wrapper->getPageHeight() - $this->minOffsetTop - $this->minOffsetBottom;
    if (($this->header)||($this->pageHeader)) {
    $pageHeight -= $this->headerImgHeight;
    }
    if (($this->footer)||($this->pageFooter)) {
    $pageHeight -= $this->footerImgHeight;
    }
    $numRows = floor(($pageHeight - $this->headerHeight)/$this->rowHeight);
    // denies page numbers if dpcument have one page
    if ($numRows >= count($this->rows)) {
    $this->wrapper->setNoPages();
    }
    $rows = Array();
    $pageNumber = 1;
    $startRow = 0;
    // circle for printing all pages
    while ($startRow < count($this->rows)) {
    $numRows = $this->printGridPage($startRow, $pageNumber);
    $startRow += $numRows;
    if ($numRows == 0) $startRow++;
    $pageNumber++;
    }

    // outputs PDF in browser
    $this->wrapper->pdfOut();
    }
    // prints one page
    private function printGridPage($startRow, $pageNumber) {
    // adds new page
    $this->wrapper->addPage();

    // calculates top offset
    if ((($this->header)&&($pageNumber == 1))||($this->pageHeader)) {
    $offsetTop = $this->headerImgHeight;
    } else {
    $offsetTop = 0;
    }

    if ($this->pageFooter) {
    $offsetBottom = $this->footerImgHeight;
    } else {
    $offsetBottom = 0;
    }


    $pageHeight = $this->wrapper->getPageHeight() - $offsetTop - $offsetBottom - $this->minOffsetTop - $this->minOffsetTop;

    $numRows = floor(($pageHeight - $this->headerHeight*count($this->columns) - $this->headerHeight*count($this->footerColumns))/$this->rowHeight);

    $lastPage = ((count($this->rows) - $startRow) <= $numRows);

    $offsetRight = $this->minOffsetRight;
    $offsetLeft = $this->minOffsetLeft;
    // sets page offsets
    $this->wrapper->setPageSize($offsetTop, $offsetRight, $offsetBottom, $offsetLeft);

    // returns number of printed rows ;
    return $rowsNum;
    }
    }


    ?>
    Web Design Company in Bangalore | Web Design Company Bangalore, Top Web Designing Company in Bangalore

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