https://bugs.documentfoundation.org/show_bug.cgi?id=163863

--- Comment #6 from yarma22 <[email protected]> ---
@fpy thanks for looking into it and for the tip!

However, I tried starting libreoffice in the background as you suggested and
unfortunately it doesn't really solve the problem. Indeed, the background
process seem to stop at a random point in time while the conversion is still
happening.

To be noted that I run the conversion(s) inside a bash script. Here's a sample
script, let's call it `odt2pdf.sh`:

```
generate_pdfs() {
  src_dir="$1"
  dest_dir="$2"

  # Ditch the output
  libreoffice --headless --convert-to pdf --outdir "$dest_dir" "$src_dir"/*.odt
> /dev/null
}

generate_pdfs dir1 PDF
generate_pdfs dir2 PDF
generate_pdfs dir3 PDF
generate_pdfs dir4 PDF
generate_pdfs dir5 PDF
```

Each folder contains several hundred PDF files. Based on your suggestion, I
tried starting libreoffice in the background in 3 different ways (see below).
In each case, the background process stopped running before the end of the
script.

1. Start it before running the script, e.g.:

```
$ libreoffice --headless > /dev/null & pid=$!
[1] 2538114
$ bash odt2pdf.sh
$ kill "$pid"
bash: kill: (2538114) - No such process
```

2. Start it at the beginning of the script, e.g.:
```
libreoffice --headless > /dev/null & pid=$!
generate_pdfs dir1 PDF
generate_pdfs dir2 PDF
generate_pdfs dir3 PDF
generate_pdfs dir4 PDF
generate_pdfs dir5 PDF
kill "$pid"
```
and then:
```
$ bash odt2pdf.sh
odt2pdf.sh: line 16: kill: (2534784) - No such process
```

3. Start it for each ceonversion, e.g.:
```
generate_pdfs() {
  src_dir="$1"
  dest_dir="$2"

  libreoffice --headless > /dev/null & pid=$!
  # No need to ditch the output since it's the background process that takes
care of the output
  libreoffice --headless --convert-to pdf --outdir "$dest_dir" "$src_dir"/*.odt
  kill "$pid"
}
```
and then:
```
$ bash odt2pdf.sh
odt2pdf.sh: line 8: kill: (2534784) - No such process
odt2pdf.sh: line 8: kill: (2534789) - No such process
odt2pdf.sh: line 8: kill: (2535123) - No such process
odt2pdf.sh: line 8: kill: (2535234) - No such process
odt2pdf.sh: line 8: kill: (2535345) - No such process
# Plus a bunch of lines like these since the output of the foreground process
is not ditched
convert dir1/file123.odt as a Writer document -> dir1/PDF/file123.pdf using
filter : writer_pdf_Export
```

FYI, the workaround I've been using since I reported this bug is to split each
folder in batches of 200 documents. The downside is that more instances of
libreoffice than necessary are instantiated, but the overhead is minimal:

```
generate_pdfs() {
  src_dir="$1"
  dest_dir="$2"

  total=$(ls -lc "$src_dir"/*.odt | wc -l)
  i=0
  while (( i < total )); do
    max=200
    ((i = i + max))
    if (( i > total )); then ((max = total + max - i)); fi
    ls "$src_dir"/*.odt | head -n "$i" | tail -n "$max" | \
      bash -c "IFS=$'\n' read -d '' -ra x; lowriter --headless --convert-to pdf
\
        --outdir "$dest_dir" \"\${x[@]}\" > /dev/null"
  done
}
```

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to