1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
procedure OpenOfficeExportToPDF(const ASourceFileURL: string; const ATargetFileURL: string);
var
StarOffice: Variant;
StarDesktop: Variant;
StarDocument: Variant;
FilterParams: Variant;
ExportParams: Variant;
ExportObject: Variant;
function CreateProperty(const AName: AnsiString; AValue: Variant): Variant;
begin
Result := StarOffice.Bridge_GetStruct('com.sun.star.beans.PropertyValue');
Result.Name := AName;
Result.Value := AValue;
end;
begin
StarOffice := CreateOleObject('com.sun.star.ServiceManager');
StarDesktop := StarOffice.CreateInstance('com.sun.star.frame.Desktop');
FilterParams := VarArrayCreate([0, 0], varVariant);
FilterParams[0] := CreateProperty('Hidden', True);
StarDocument := StarDesktop.LoadComponentFromURL(ASourceFileURL, '_blank', 0, FilterParams);
ExportParams := VarArrayCreate([0, 2], varVariant);
ExportParams[0] := CreateProperty('Magnification', 2);
ExportParams[1] := CreateProperty('EncryptFile', True);
ExportParams[2] := CreateProperty('HideViewerWindowControls', True);
// ExportParams[3] := CreateProperty('DocumentOpenPassword', AnsiString('StackOverflow'));
ExportObject := StarOffice.Bridge_GetValueObject;
ExportObject.Set('[]com.sun.star.beans.PropertyValue', ExportParams);
FilterParams := VarArrayCreate([0, 1], varVariant);
FilterParams[0] := CreateProperty('FilterName', AnsiString('writer_pdf_Export'));
FilterParams[1] := CreateProperty('FilterData', ExportObject);
StarDocument.StoreToURL(ATargetFileURL, FilterParams);
StarDocument.Close(True);
StarDesktop.Terminate;
StarDocument := Unassigned;
StarDesktop := Unassigned;
StarOffice := Unassigned;
end; |
Partager