Free Support Forum - aspose.com

Insert document(contain table) to other document

After insert document(contain table) to other document and covert to pdf ,
the final pdf document does not contain proper inserted document due to table .

Test.zip (154.4 KB)

@ramveer,

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

  • Your input Word documents.
  • Please create a standalone console 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 will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Already attached input and output document.

@ramveer,

Thanks for your inquiry. We have converted the shared document (InsetingDoc.xml) to PDF using the latest version of Aspose.Words for .NET 18.8. We have not found any issue with output PDF. Please check the attached output PDF. 18.8.pdf (111.8 KB)

If you still face the problem, please share some more detail about your issue along with screenshots of problematic sections of output document. We will investigate the issue and provide you more information on it.

I am not simply convert the doc to pdf .
I am insert the input file to other doc file and then final doc convert to pdf
using the below code:-

builder.insertDocument(input_given_file, ImportFormatMode.KEEP_SOURCE_FORMATTING);

@ramveer,

Thanks for your inquiry. Your ZIP file (Test.zip) contains InsetingDoc.xml. There is no other Word document in this ZIP file that you want to insert into this document. Please ZIP and attach your input, output, and expected output documents along with code example to reproduce this issue at our end. Thanks for you cooperation.

please find attached document .
Input.docx is as input document in which we insert InsetingDoc.xml at position [@ArticleInsert@] (in Input.docx) and get the finalOutput.pdf .Upload.zip (168.4 KB)

@ramveer,

Thanks for sharing the documents. We have tested the scenario using latest version of Aspose.Words for .NET 18.8 with following code example and have not found the shared issue. Please use Aspose.Words for .NET 18.8. We have attached the output PDF with this post for your kind reference. 18.8.pdf (207.3 KB)
.

Document inputdoc = new Document(MyDir + "Input.docx");
FindReplaceOptions options = new FindReplaceOptions();
options.ReplacingCallback = new FindInsertDocument();
                 
inputdoc.Range.Replace("@ArticleInsert@", "", options);
 
inputdoc.UpdateTableLayout();
inputdoc.Save(MyDir + "18.8.pdf");

public class FindInsertDocument : IReplacingCallback
{
    ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e)
    {
        // This is a Run node that contains either the beginning or the complete match.
        Node currentNode = e.MatchNode;
        DocumentBuilder builder = new DocumentBuilder((Document)e.MatchNode.Document);
                
        builder.MoveTo(currentNode);
        builder.InsertDocument(new Document(MyDir + "InsetingDoc.xml"), ImportFormatMode.KeepSourceFormatting);
        return ReplaceAction.Skip;
    }
             
}

I am using the below code with aspose-words-18.8-jdk16.jar

if(tempStr1.equals(tempStr2)){
builder.moveTo(para);
RunCollection runs=para.getRuns();
Iterator itr = runs.iterator();
while(itr.hasNext()){
Run run=(Run)itr.next();
run.remove();
}
builder.insertDocument(new Document(MyDir + “InsetingDoc.xml”), ImportFormatMode.KEEP_SOURCE_FORMATTING);
doc.updateTableLayout();
}

but still issue is not resoved.

@ramveer

Thanks for your inquiry. Please attach the following resources here for testing:

  • 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 will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Please find the below executable code and attached document.Upload.zip (241.1 KB)

 public static void demo(String MyDir) throws Exception{    	
    	 Document doc = new Document(MyDir + "Input.docx");
    	 DocumentBuilder builder=new DocumentBuilder(doc);
    	
        for(Section section : doc.getSections()){
            NodeCollection paraNodes=section.getChildNodes(NodeType.PARAGRAPH,true);
            Iterator paraNodesItr=paraNodes.iterator();
            while(paraNodesItr.hasNext()){
                Paragraph para = (Paragraph)paraNodesItr.next();
                
                String tempStr1= para.getRange().getText().trim();
                String tempStr2= "@@ARTICLE12345@@";
                if(tempStr1.equals(tempStr2)){
                    builder.moveTo(para);
                    RunCollection runs=para.getRuns();
                      Iterator itr = runs.iterator();
                      
                      while(itr.hasNext()){
                          Run run=(Run)itr.next();
                          run.remove();
                       }
                       
                     builder.insertDocument(new Document(MyDir + "InsetingDoc.xml"), ImportFormatMode.KEEP_SOURCE_FORMATTING);
                     doc.updateTableLayout();
                     doc.updatePageLayout();
                }
                
            }

        }
        
        doc.save(MyDir+"Final001.pdf"); 
        System.out.println("Done--- " + MyDir);  
    }

@ramveer

Thanks for sharing the detail. Please note that Aspose.Words mimics the behavior of MS Word. If you insert the document (“InsetingDoc.xml”) at the same location of “input.docx” using MS Word, you will get the same output.

In your case, we suggest you please set the text wrapping of the table as “None”. It is “Round” in InsetingDoc.xml. This document contains some empty columns (table’s cell). Please remove them from table also to get the desired output. Following code example shows how to set the text wrapping of table.

Document doc2 = new Document(MyDir + "InsetingDoc.xml");
for (Table table : (Iterable<Table>) doc.getChildNodes(NodeType.TABLE, true)) {
    table.setTextWrapping(TextWrapping.NONE);
}