开发者

Word OLE Automation Watermark adding in MS-Office COM Object

I am using PHP COM Object but i guess it is the same in all other languages. How do i add watermark to a .doc / .docx Microsoft Word using COM / OLE Automation?

    try
    {
        $word = new COM("word.application") //$word = new COM("C:\\x.docx");
or die(error::asString("couldnt create an instance of word", 20100408.01812, true));

        //bring word to the front
        $word->Visible = 1;

        //open a word document
        $word->Documents->Open($abs_filename);

        $range = $word->ActiveDocument->Content();
        $this->text = iconv('CP1255', 'UTF-8', $range->Text);

        //save the document as html
开发者_高级运维        // format: 0 - same?, 1 - doc?, 2 - text,  4 - text other encoding, 5 - ?, 6 - rtf , 8 - html
        $word->Documents[1]->SaveAs($result_file_name, 8);

Thanks.


In Word start a new macro, and record the steps you need to add a watermark to your document. Then view the generated macro code and translate that to OLE Automation calls in your php script.

TIP: when you open a document $word->Documents->Open($abs_filename); you will get a reference to that document. It is better to work with that reference than working with ActiveDocument and Documents[1] as you do now.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜