Score:0

How to headless update and export to pdf with libreoffice?

uz flag
jjk

I'm perfectly able to export to pdf from the writer GUI after searching and replacing a word via script (unzip odt;sed xml;zip odt).

However exporting via the commandline exports the old word instead of the new: lowriter --headless --convert-to pdf textfile.odt

How can I export via commandline?


How to reproduce:

  1. Create a new calc file
  2. Write foo into cell A1
  3. Save the calc file as /tmp/calc.ods
  4. Create a new writer file
  5. Embed /tmp/calc.ods as linked object into the writer file: Insert > OLE Object > OLE Object > Create from file > Check Link to file
  6. Save the writer file as /tmp/result.odt

Replace foo in the calc file with bar using this shell script:

cd /tmp
mkdir bla
cd bla
unzip ../calc.ods # Unpack the calc file to edit
sed -i 's/foo/bar/g' content.xml #Replace foo with bar
zip -r ../calc.ods . # Pack the calc file back

Now export the writer file to pdf and expect to see the new value (bar) in result.pdf:

lowriter --headless --convert-to pdf /tmp/result.odt

Why does the exported pdf still show the old value (foo)?

ar flag
Add the script to your question.
jjk avatar
uz flag
jjk
The question is **if** any script solves the problem
ar flag
Without the script we can't replicate your problem.
Olivetti avatar
kr flag
Edit: soffice/lowriter lacks the quiet-update option, thus install unoconv. apt install unoconv then unoconv -v --unsafe-quiet-update your-file-with-linked-object.odt
vanadium avatar
cn flag
Provide detail on how you link/embed the file. It appears that the way you work, a copy embedded in the .odt file is used during conversion to PDF.
jjk avatar
uz flag
jjk
@Olivetti That's the answer, thank you
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.