I am using OpenOffice Writer, and I wish to Print under Program control. However, I do not wish to print to the default printer, but rather direct certain documents to certain printers, according to the type of document I generate.
Using Bernard Marcelly's OOoTools library, for Delphi, to do OLE Automation, talking to OpenOffice, 4.0, the following code works to Print to the current printer,
procedure TMyOODocClass.Print;
var
docObj : variant; // Current OOo Document, implements IXPrintable
printProps : variant;
begin
docObj := GetMyActiveDocument; // method not shown, pretty standard stuff.
try
// empty array, I think this is where I would fill in PrinterName?
printProps := VarArrayCreate([0, -1], varVariant);
docObj.print(printProps);
except
on E:EOleException do
begin
raise Exception.Create('OpenOffice Document Print failed. '+E.Message);
end;
end;
end;
I am not able to locate the documentation for OpenOffice Writer Document Print method or the properties it supports, I think I am supposed to define some properties, something like this:
printProps := VarArrayCreate([0, 1], varVariant);
printProps[0] := MakePropertyValue('PrinterName', 'PrinterNameHere') ;
Question Part A, is there a thorough HTML online reference for all the properties that Print, and all other similar Document methods accept? And Part B, is what is the property or technique to set the above. I do believe that the Document objects in OO implement an interface called IXPrintable, and so what I am wondering how to find is all the methods of IXPrintable, and what parameters or properties the Print method within that method, accepts.
Update Following the comment suggestion, I tried using a property named 'Name', like this:
procedure TMyOODocClass.PrintTo(PrinterName:String);
var
docObj : variant; // Current OOo Document, implements IXPrintable
printProps : variant;
begin
docObj := GetMyActiveDocument; // method not shown, pretty standard stuff.
try
if PrinterName='' then
printProps := dummyArray
else
begin
printProps := VarArrayCreate([0, 1], varVariant);
printProps[0] := MakePropertyValue('Name',PrinterName);
end;
docObj.print(printProps);
except
on E:EOleException do
begin
raise EOOoError.Create('OpenOffice Document Print failed. '+E.Message);
end;
end;
end;
The above does not work, so there must be something missing or wrong. I tried calling docObj.SetPrinter
as well, but I get a parameter type mismatch error.