Generated report begins with a unwanted Carriage Return

Hello Aspose Team
We have requirement where the content of one document is to be inserted at specified location in another docunmet which is going to be the final report in doc/docx format .
The final report generated has the content inserted, however what we have observed that the docment content which is inserted always starts with “Carriagae Return” symbol even though the original document does not contain the “Carriagae Return”.
Please help us to reolve this unwanted additon of “Carriage Return” while inserting the document content in to the final report.
Note: Attached CR.GIF for the reference.
Thanks
Praveen

Hi Praveen,

Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word documents.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a simple Java application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip them and Click ‘Reply’ button that will bring you to the ‘reply page’ and there at the bottom you can include any attachments with that post by clicking the ‘Add/Update’ button.

Hello Tahir
Please find attached zip file containing sample sourcefile with input and output files.
Note that, we have used the sample code listed out in Aspose documentation for replacing the content of one document into another.
In this zip file there is one GIF(image) file showing the screenshot of the generated output file with Paragraph symbol which can be used for the reference.
Inorder to see the Paragraph symbol in the generated output file, please enable the “Paragraph Mark” in MS Word.
Thanks, Looking forward for your suggestions
Praveen

Hi Praveen,

Thanks for your inquiry. In your case, we suggest you please use DocumetBuilder.InsertDocument method as shown below to get the required output and use Aspose.Words for Java 16.11.0. Hope this helps you.

Document doc = new Document(MyDir + "TemplateFile.rtf"); //Input Template File Path
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToBookmark("book27", false, true);

Document docUrl = new Document(MyDir + "sample_input.docx");
builder.insertDocument(docUrl,ImportFormatMode.KEEP_SOURCE_FORMATTING);

doc.save(MyDir + "output v16.11.0.docx");

Hello Tahir

Thanks for the suggestion provided.
It works with version Aspose.Words for Java 16.11.
However we have our existing code which depends on Aspose version 13.7, and because of the new version 16.11 which has many changes included in calling Aspose APIs,we are getting build failure and exception issues when we replace the existing Aspose version with new Aspose version.
As we donot want to touch the existing production code, is there any way or workaround where we can resolve this issue with Aspose version 13.

Kindly suggest.

Thanks
Praveen

Hi Praveen,

Thanks for your inquiry. The insertDocument method inserts the document after current paragraph (in your case, after the paragraph which contains the bookmark).

In this case, we suggest you please join the two paragraphs - bookmark’s paragraph and first paragraph of inserted document. Please check the highlighted code snippet below. Hope this helps you. Please let us know if you have any more queries.

Document doc = new Document(MyDir + "TemplateFile.rtf");
DocumentBuilder builder = new DocumentBuilder(doc);

BookmarkCollection books = doc.getRange().getBookmarks();
Document docUrl = new Document(MyDir + "sample_input.docx");
for (Bookmark book : books)
{

    // book.setText("");
    if (book.getName().equalsIgnoreCase("book27"))
    {
        Paragraph paragraph = (Paragraph)book.getBookmarkStart().getParentNode();
        insertDocument2(paragraph, docUrl);

        if (paragraph.getNextSibling() != null)
        {
            Paragraph nextPara = (Paragraph)paragraph.getNextSibling();

            // Move all content from the nextPara paragraph into the first.
            while (nextPara.hasChildNodes())
                paragraph.appendChild(nextPara.getFirstChild());

            nextPara.remove();
        }
    }
}

doc.save(MyDir + "output.docx");