Reputation: 8318
I run a bash script which generates a PDF at the end of a billing run. I used to do that with LaTeX but the users ask for a more MS Office like solution. So I'm thinking of using a LibreOffice document and use LibreOffice on the command line to generate the PDF. That works. But I have no idea how to inject the values I need to change (e.g. the address and the billing information) into that document before I can generate a PDF.
Let's assume the example.odt
document contains this text:
Dear $fist_name,
you own us $amount USD.
Regards
xyz
Since example.odt
is not really easy to edit from a Bash script I'm searching for an other way to inject values for $first_name
and $amount
.
What is the best way to do this?
Upvotes: 1
Views: 1023
Reputation: 8318
The LibreOffice file is a zip archive which can be unzipped with
unzip old.odt -d example
cd example
The content of the file is in the file content.xml
. There is can be changed with sed
or any other tool. After that the .odt
file has to be created again:
zip -r ../new.odt .
After that the PDF can be created with this command (the path is from OS X):
/Applications/LibreOffice.app/Contents/MacOS/soffice --headless
--convert-to pdf:writer_pdf_Export --outdir ~/Desktop/ ~/Desktop/new.odt
Upvotes: 3