从 OpenOffice 保存为 pdf [英] Saving to pdf from OpenOffice
问题描述
因为我刚刚问了这个问题 并得到了一个非常有用的答复,我想知道是否有人已经使用 Open Office 中内置的 documentTopdf 例程将 odt、doc、docx 文件保存为 pdf.
Since I just asked this question and got a very useful reply I wonder if anyone has already the code for using the documentTopdf routine built in in Open Office for saving odt, doc, docx files to pdf.
这里 无论如何都有 c# 示例,因为在 Delphi 中直接使用它非常适合许多用户.
Here there is the c# example anyway since having it in Delphi direcly would be great for many users.
推荐答案
非常相似 :)
这里是描述用于配置生成文档的所有功能的教程.
对于以下示例,我选择了适合宽度放大、密码保护和隐藏窗口控件.当转换时未显示 OpenOffice 窗口时,导出在隐藏模式下完成.
请注意,以下代码再次没有错误处理.
Very similarly :)
Here is the tutorial describing all features used for configuration of the generated document.
For the following example I chose fit to width magnification, password protection and hidden window controls. The export is done in hidden mode when the OpenOffice window isn't shown at conversion.
Note that the following code is again without error handling.
uses
ComObj;
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, 3], varVariant);
ExportParams[0] := CreateProperty('Magnification', 2);
ExportParams[1] := CreateProperty('EncryptFile', True);
ExportParams[2] := CreateProperty('DocumentOpenPassword', AnsiString('StackOverflow'));
ExportParams[3] := CreateProperty('HideViewerWindowControls', True);
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;
procedure TForm1.Button1Click(Sender: TObject);
begin
OpenOfficeExportToPDF('file:///C:/SourceFile.odt', 'file:///C:/TargetFile.pdf');
end;
这篇关于从 OpenOffice 保存为 pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!