Forum


Replies: 7   Views: 4104
Add blank page if odd page count
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by loktron  · 21-11-2016 - 10:46

I did it now :) i read about word typelib, but the including didnt work so I read out all the constants and defined them myself. I dont wanna use LibreOffice if i dont have to because creating the docs with word, then analyse them with libre and then convert them with word are too many components that can go wrong i think.

So here is my function. I use it on every created document before merging:

public function printDuplex($file){
            $word=new COM("Word.Application") or die("Cannot start MS Word");
            $word->visible = 0 ;
            //6 = wdStory VB (end of document)
            define('endOfPage', 6);
            //(2 = wdStatisticPages VB)
            define('pageCount', 2);
            //open File
            $word->Documents->Open($file);
            // get pagecount
            $count = $word->ActiveDocument->ComputeStatistics(pageCount);
            //If odd pagecount
            if($count%2 > 0){
                //6 = wdStory VB (end of document)
                //go to end of document
                $word->Selection->EndKey(endOfPage);
                //add page
                $word->Selection->InsertBreak();
            }
            //save document
            $word->Documents[1]->SaveAs($file);
            $word->Quit( );
            $word = null;
        }

 

Thank you for your help you sat me on the right track :)

 

regards