Inserting a new line as value for a docproperty

Hello,
I’m using the newest version of Aspose.Words for Java now (I used .NET before, but we switched)
There is this document with docproperties, and I have a method that assigns values to docproperties.
In some cases, the value of a docproperty needs to be a new line. This is because in my document, two docproperties may be placed right after eachother on the same line, like this:

When this docproperty2 has no value, then docproperty1 can just get a value, and docproperty3 can also just get a value on the next line (it is crucial that it is on the next line). No problems here…

However, when docproperty 2 does have a value, then it needs to be placed in between docproperty 1 and docproperty 3. This means that docproperty 1 needs to end with (or just plainly be) a ‘new line’ value, because we should then end up in the following situation:

When I try using the “\n” string as a value for the docproperty1, it only works if I put text behind the \n. For example: “Lalala \n Lalala” shows up as:
Lalala
Lalala
Of course this makes sense because now I am not telling the docproperty that it should be a new line, but I’m assigning a string with a new line in it to the value of the docproperty. Nevertheless, I thought this method could work. However, “Lalala \n” shows up as Lalala without an enter behind it. And a plain “\n” just does nothing at all then.
I guess there would be a better way than using \n, but I don’t know how to do it… Can you help me out?
Greetings,
Jip

Hi
Thanks for your request. I think you can achieve this using bookmark. Just insert bookmark between DOCPROPERTY fields and if the second property value is not empty insert paragraph break at the bookmark. See the following code:

Document doc = new Document("C:\\Temp\\in.doc");
DocumentBuilder builder = new DocumentBuilder(doc);
String author = "Alexey Noskov";
String category = "My Category";
String company = "Aspose";
// Set values of DocumentPropertied
doc.getBuiltInDocumentProperties().setAuthor(author);
doc.getBuiltInDocumentProperties().setCategory(category);
doc.getBuiltInDocumentProperties().setCompany(company);
if (!category.isEmpty())
{
    // Move documentBuilder cursor to the bookamrk between DOCUMENTPROPERTY fields and inset break
    builder.moveToBookmark("separator");
    builder.insertBreak(BreakType.PARAGRAPH_BREAK);
}
// Update fields and save document
doc.updateFields();
doc.save("C:\\Temp\\out.doc");

Hope this helps.
Best regards.