Search code examples
c#memorystreamgembox-document

Unable to display the content loaded from MemoryStream in a particular paragraph in Gembox.Document


I have a document that is made up of different paragraphs

<p> paragraph 1<p/>
<p> paragraph 2<p/>
<p> paragraph 3 content is from an uploaded pdf document <p/>
<p> paragraph 4<p/>
<p> paragraph 5<p/>

Content of paragraph 3 is from a previously uploaded pdf document loaded as a MemoryStream.

How do I ensure that the content of paragraph 3 is placed between paragraphs 2 and 4?

currently, I am able to load it before paragraph 1 or after paragraph 5, using

var document = new DocumentModel();
 //
 // other paragraphs and sections
 //
        
var financialAnalysisDocument = DocumentModel.Load(data.FinancialAnalysisDocumentStream, loanOption);

document.Content.End.InsertRange(financialAnalysisDocument.Content;

Solution

  • Try this:

    document.Sections[0].Blocks[1].Content.End.InsertRange(financialAnalysisDocument.Content);
    

    However, because the financialAnalysisDocument.Content is a ContentRange of the whole DocumentModel, this will result in inserting Section elements between "paragraph 2" and "paragraph 4".

    I'm not sure if that is what you want, so perhaps this would be a better fit for your needs:

    document.Sections[0].Blocks[1].Content.End.InsertRange(
        financialAnalysisDocument.Sections[0].Blocks.Content);