Hi,
I would like to know how to set the Font.Color of a DocumentBuilder using the COM/PHP interop.
$this->oBuilder->Font->Name = "Courier New";
$this->oBuilder->Font->Color = 255;
The second line here rises an error.
Regards,
Vincent
Hi,
I would like to know how to set the Font.Color of a DocumentBuilder using the COM/PHP interop.
$this->oBuilder->Font->Name = "Courier New";
$this->oBuilder->Font->Color = 255;
The second line here rises an error.
Regards,
Vincent
Hi
Thanks for your inquiry. You should create your own COM visible class that will contain method that sets color of Font.
Open Visual Studio and create new ClassLibrary
Put the following simple code
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace ColorHelper
{
[ComVisible(true)]
[ProgId("ColorHelper.Helper")]
public class Helper
{
public Helper() { }
public void SetColor(object builder, int argb)
{
(builder as Aspose.Words.DocumentBuilder).Font.Color = System.Drawing.Color.FromArgb(argb);
}
}
}
Set strong name of assembly.
Compile library.
Open Visual Studio Command Prompt and register library using the following command
regasm D:\Aleksey\_projects\Tets\_projects\ColorHelper\ColorHelper\bin\Debug\ColorHelper.dll /codebase
Here is PHP code:
<?php
//Create Document object
$doc = new COM("Aspose.Words.Document");
//Create DocumentBuilder
$builder = new COM("Aspose.Words.DocumentBuilder");
//Set document
$builder->Document = $doc;
//Create ColorHelper instance
$colorHelper = new COM("ColorHelper.Helper");
//Set color of font
$colorHelper->SetColor($builder, 255);
//Write "Hello world!" in word document
$builder->Write("Hello world!!!");
//Save created document
$doc->Save("C:\\Temp\\out.doc");
?>
I hope this could help you.
Best regards.