1

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?

Maxime Lorant
  • 34,607
  • 19
  • 87
  • 97
user745323
  • 153
  • 1
  • 1
  • 8
  • 1
    With code from [`this post`](http://stackoverflow.com/a/7819626/960757) I haven't noticed any of the problems you describe. – TLama Feb 25 '14 at 19:47
  • Is this using COM? I don't know about OpenOffice - which has been eclipsed by LibreOffice for some time now - but LibreOffice has a command-line option that can convert between any files it can read/write, including PDF, like so: http://kgsspot.blogspot.com/2011/09/convert-doc-to-pdf-in-command-line.html – alcalde Feb 25 '14 at 21:41
  • @alcalde, yes, it is based on OLE automation. Out of curiosity, when you have mentioned LibreOffice, its API should be compatible with OpenOffice, so the code should be portable. – TLama Feb 25 '14 at 22:53
  • Thanks for the comments. TLama, I had previously looked at the post you linked to, but hadn't seen anything significant. Interesting to know that you don't see the problems I see, so I will try that code out. Incidently, I am using Libra Office. I mentioned Open Office as most searches I've done refer to the OO api. – user745323 Feb 26 '14 at 09:17
  • To update ... there is an option "View PDF after export" on the PDF Export dialog in Libra Office. With this not selected everything works fine. Selecting it I get the two problems described above. I just have to find the way to deselect in code, now. – user745323 Feb 26 '14 at 09:49

0 Answers0