First of all, download and open Delphi OOo, an excellent toolbox to
use Delphi with LibreOffice. You can
find Delphi OOo here.
Then, use this piece of code to open a template, search and replace text and generate a PDF file:
fileProp3, fileProp4, oReplace, myTemplate: Variant;
myFile3, myFile4: String;
...
myFile3:= convertToURL('D:\template.ott');
fileProp3:= CreateProperties(['AsTemplate', true]);
myTemplate := StarDesktop.LoadComponentFromURL(myFile3, '_blank', 0, fileProp3);
oReplace := myTemplate.createReplaceDescriptor;
oReplace.setSearchString('field1');
oReplace.setReplaceString('New content!');
myTemplate.ReplaceAll(oReplace);
fileProp4:= CreateProperties(['FilterName', 'writer_pdf_Export']);
myFile4:= convertToURL('C:\new_document.pdf');
myTemplate.storeToURL(myfile4, fileProp4);
Delphi 7, LibreOffice 3.4.2, Windows XP SP 3.