Docx --convert-to pdf succeeds but --convert-to txt creates empty file. Ideas?

With the attached file:
soffice --convert-to pdf in.docx
succeeds, but:
soffice --convert-to txt in.docx
produces a zero-byte (empty) file.

(The attached file is linked to from the Education Endowment Foundation’s “Effective Professional Development” page and the link is titled “Reflecting on PD tool (editable)”. I can’t add another link to this topic post because I am a new user.)

Can anyone help me to understand why this is happening, and whether there is a way round this problem? Thank you!

Reflecting_on_PD_Final_Editable.docx (142.4 KB)

Just a guess: simply because there is no text in the document.

Everything in the document is a Drawing Object, i.e. a geometric shape which does not count as a text, but is equivalent to an image. Converting a shape to plain text gives exactly your result: empty string.

The fact that you styled Heading 1 the label inside the label in the header does not change the behaviour.

IMHO, your document should not have been saved .docx because it rather looks like an Impress/PowerPoint page.

PS: when asking here, always mention OS name, exact LO version and save format (DOCX in the present case).

Thank you for taking the time to reply. I appreciate it.

Interesting. If I open the docx in lowriter, I can copy all the visible text into a text document.

Also, if I use soffice to convert the docx to a pdf and open that pdf in firefox, I can select and copy the text as text (which I can then paste into a text document).

One last test: if I run pdftotext on the pdf created in the previous step, pdftotext correctly extracts all the visible text. (I will attach the text file created by pdftotext to this post.)

You said that “everything in the document is a Drawing Object”. I may be wrong, but I think that there are text objects in that document (if that is what text is called!)

Yes, I see what you mean. It does display more like a presentation slide than a word-processing document. But it’s all I have to work with. I’m just a consumer.

Sure:
OS: Debian 12 (Bookworm)
LO version: 25.2.3

(PS: I’ve just tried to attach the txt file mentioned above to this post, but apparently txt files are not authorised for upload. I wasn’t expecting that! Consequently, I have had to zip it before uploading it.)

text.zip (738 Bytes)

Yes, but through a complex operation: you select an object and several representations are stored in the clipboard. There is of course the full Drawing Object, but also a stripped version containing only the text labels with all the graphical parts dropped. When pasting this clipboard item is requested, the “recipient” chooses which format it accepts.

No. PDF is a display format made of graphical objects laid out at specific (x,y) coordinates in a page (even text, considered as a collection of glyphs). So, converting a drawing to another encoding is typically what PDF output filters do.

Yes. Text boxes are just a category of Drawing Objects. They are transparent rectangles without borders, with only a label. This is not a text stream that Writer flows across lines and pages. The Writer text stream is sequence of characters interspersed with formatting directives. These directives contain no absolute position coordinates (contrary to Drawing Objects which are external to Writer text stream). Position is fully managed by Writer (starting from top of page, filling page in writing direction and allocating new pages when necessary.

An advice for our own work:
When composing yourself a true text-oriented document, avoid text boxes. They are only “decorations” with limited formatting and layout possibilities. If you really want a side block of text, insert a frame. A frame is a full-fledged “independent” sub-document (limited to a single page). But mastering frames is the most difficult art in Writer.

@ajlittoz Again, thank you for your reply, but unfortunately your reply does not help me.

As I said before, I did not create this docx document. I would like to extract the text from it and I can do that if I use soffice to convert the docx to a pdf, and then use pdftotext to extract the text from that pdf. But if I use soffice to convert the docx directly to a txt file, I get an empty txt file.

I guess I’ll just log it as a bug. Thank you again!

And it can’t because there is no way for it. It was only an explanation why it can’t. All graphical material is external to “true-text” management (it is not text according to Writer definition). You found the best workaround: export the whole document to a “homogeneous” graphical form (PDF), then use a PDF-dedicated tool, like a PDF reader or an OCR program to reconstitute a text flow.

I think thai s not a bug. A pure .txt file can not contain any graphical objects. Your sample document has not contain any pure text. It contains only graphical units with textual LABELS.
What and how the LibreOffice should export based on these labels? What order, what indent, what grouping?
.
You can try to write a macro what will examine all of the graphical objects on the pages and then can get the LABELS, and the macro can put the text of the labels into a new, empty textual document. Maybe the order of the “extracted” text will not be proper - if you can not examine the POSITION oo them on the original page.

A workaround tip:
Select all - Copy - open a new CALC document - Paste Special - Paste Special - HTML

The result:
Exported labels.ods (15.1 KB)

Ok, I think that I am beginning to understand. So, does that mean that it is these textual labels that pdftotext is exporting (extracting)? (I know that pdftotext is exporting something, because it produces a pure text file that contains all the text.)

Yes, because a PDF files can not contain pure texts. Thye contain formatted LABELS only. (Yes, it is true for the strings too, what are “pure text” in a .docx, and in the .odt files. When you export a textual file into .pdf format all of textual contents become LABELS in the .pdf file.)