GemBox Support Forum

Text lines missing after docx conversion to PDF

My application takes documents with text placeholders, fills them in, converts them to PDF, and returns them to the user. In this application, Gembox only handles the conversion step, as the placeholder work was done prior to bringing it in.

For multi-line placeholders, a placeholder such as {Recipient Address} would initially look like this:

<w:t>{Recipient Address}</w:t>

and it is replaced with the following lines of XML:

    <w:t>Zip/Post Code</w:t>

When this is converted to a PDF (standard doc.Save() into a MemoryStream with SaveOptions.PdfDefault), these lines will disappear. This does not happen when converting inside MS Word.

If we use the following XML instead:

<w:t>AddressLine1<w:br/>AddressLine2<w:br/>Country<w:br/>Zip/Post Code<w:br/></w:t>

We retain “AddressLine1” but not the other lines.

Any advice on how to stop this from occurring?


That is not valid content, it doesn’t follow OpenXML specifications.
Try opening that document in some other Word application, like LibreOffice Writer, you’ll notice that the text is missing as well.

In short, the <w:t> element cannot have <w:t> and <w:br> elements as child elements.
Those elements can be placed inside the <w:r> element, so try using the following instead:

<w:r>{Recipient Address}</w:r>

Does this solve your issue?