Delphi Saving open office document as PDF

放肆的年华 提交于 2020-01-05 08:59:28

问题


I am using the following code to export an Open Office document as a pdf file using Delphi:

procedure TOOoWriter.SaveToPDF(FileName: string);
var
   wProperties: variant;
begin
   if not (fConnected and fDocumentOpened) then
      abort;

   wProperties := VarArrayCreate([0, 3], varVariant);
   if fHTMLSrc then
      wProperties[0] := MakePropertyValue('FilterName', 'writer_web_pdf_Export')
   else
      wProperties[0] := MakePropertyValue('FilterName', 'writer_pdf_Export');

   wProperties[1] := MakePropertyValue('CompressionMode', '1');
   wProperties[2] := MakePropertyValue('Pages', 'All');
   wProperties[3] := MakePropertyValue('Overwrite', TRUE);

   fDocument.StoreToURL('file:///'+ StringReplace(FileName, '\', '/', [rfIgnoreCase, rfReplaceAll]), wProperties);
end;

All is working well except:

  1. it insists on opening the resultant pdf file (but not the OO file). This is problematic because I will be writing 100s of files without user interaction.

  2. if the output pdf file does not exist I get an exception, but the file is created properly. The second time it works ok as the file was created the first time.

Are there solutions to these problems?

来源:https://stackoverflow.com/questions/22019000/delphi-saving-open-office-document-as-pdf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!