We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Update Rich Text Content Control with String and New Line Char using Java | Insert Line Break Character in SDT

I am passing a string with \n (like “Hello\nWorld”) to a method that sets the Rich text control in Java but the string is displayed all in one line…any trick here?

	public static void updateRichText(Document doc, StructuredDocumentTag sdt, String txtVal) {
	
		Run run = new Run(doc);
		run.setText(txtVal);
	
		if (sdt.getLevel() == MarkupLevel.INLINE) {
			sdt.removeAllChildren();
			sdt.getChildNodes().add(run);
		} else if (sdt.getLevel() == MarkupLevel.BLOCK) {
			sdt.removeAllChildren();
			Paragraph para = (Paragraph) sdt.appendChild(new Paragraph(doc));
			para.getRuns().add(run);
			sdt.getChildNodes().add(para);
		} else if (sdt.getLevel() == MarkupLevel.CELL) {
			if (sdt.getFirstChild().getNodeType() == NodeType.CELL) {
				Cell cell = (Cell) sdt.getFirstChild();
				cell.removeAllChildren();
				cell.ensureMinimum();
				Paragraph para = ((Cell) sdt.getFirstChild()).getFirstParagraph();
				para.getRuns().add(run);
			}
		}
	}

@mp2,

Please replace \n with ControlChar.LINE_BREAK. Here is how you can use it:

updateRichText(doc, sdt, "Hello" + ControlChar.LINE_BREAK + "World");

that worked like charm…thank you