Search code examples
c#newlinebookmarksgembox-document

GemBox Document adding special chars into a boomark


I am trying to load text into a bookmark into a word document and save. The bookmark can be a large amount of text with new line characters. Here is the code:

String text = "Some text with \n new \n line chars \n";
ComponentInfo.SetLicense(GEMBOX_DOCUMENT_LICENSE_KEY);
DocumentModel document = DocumentModel.Load(fileTemplate);
document.Bookmarks["bm_1"].GetContent(false).LoadText(text);

However the resulting PDF document that saves prints out "Some text with \n new \n line chars \n". What changes do i need to make to text to make it render properly?


Solution

  • I'm not sure what issue you have, I tried the following:

    String text = "Some text with \n new \n line chars \n";
    
    DocumentModel document = DocumentModel.Load("input.docx");
    document.Bookmarks["bm_1"].GetContent(false).LoadText(text);
    
    document.Save("output.pdf");
    

    I have used the following input DOCX:

    input DOCX file

    And I got the following output PDF:

    output PDF file

    Can you send me your input and output files?