Okay I got it to work, the problem was I wasn't creating the Property values properly. Also I stupidly assumed that you pass the parameters to Print when what you do is call SetPrinter
, with property Name set to printer name, then call Print
, still with no parameters. The url linked by TLama clearly stated this, but I missed it initially, I think I need more coffee.
Also it seems that the Unicode VarType 258 (varUString) values are not particularly OLE Automation friendly, so I am explicitly using AnsiString
in the code below.
uses
ComObj,
Classes,
SysUtils,
Dialogs,
Controls,
Windows,
oOoConstants,
OOoTools,
DB,
Variants,
StdCtrls,
Forms;
procedure TMyOODocClass.PrintTo(PrinterName:AnsiString);
var
docObj : variant; // Current OOo Document, implements IXPrintable
emptyProps, printProps: variant;
propName:AnsiString;
begin
docObj := GetMyActiveDocument; // method not shown, pretty standard stuff.
try
emptyProps := dummyArray;
if PrinterName <> '' then
begin
propName := 'Name';
printProps := createProperties( [propName,PrinterName] ); // OOTools helper
docObj.SetPrinter( printProps );
end;
docObj.print(emptyProps);
except
on E:EOleException do
begin
raise EOOoError.Create('OpenOffice Document Print failed. '+E.Message);
end;
end;
end;
A complete demo that compiles and runs is on bitbucket here as delphi_openoffice_demo01