Inserting line breaks into PDF text using XSLT-FO
Recently I needed to insert a line break into a block of text in a PDF file. The PDF was generated using an XSLT-FO style sheet with an XML input document. The solution wasn't as straight forward as I had expected but it can be done relatively easily.
The XSLT-FO looked like this
<fo:block font-size="9pt" line-height="14pt"> <xsl:value-of select="/PresentationData/TextBlock"/> </fo:block>
The change needed is to add the linefeed-treatment attribute like this
<fo:block font-size="9pt" line-height="14pt" linefeed-treatment="preserve" > <xsl:value-of select="/PresentationData/TextBlock"/> </fo:block>
Then put the line breaks (\n) into the input XML document in .NET.
presentationDataXML.Add(new XElement("PresentationData", new XElement("TextBlock", "line one\nline two")