We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Appending sections with images screwes up table formatting

Hello,


I am evaluating Aspose Words .Net for a routine we need to implement which would merge multiple word documents into one. I am using sample code as provided on-line and it works well for the most part. I am experiencing difficulties when attempting to merge two attached documents. Document #1 contains an image, and Document #2 contains a fancy word table. When I merge the two, table’s formatting becomes skewed. Can anyone shed any light on why this is happening.

I’ve attached documents, the resulting output document, as well as a sample project which demonstrates the problem.

Here is the code as well for quick review:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Aspose.Words;
using System.IO;

namespace IC.Tinker.AsposeWord.DocMerge
{
public partial class fMergeDocuments : Form
{
private static string TEST_FOLDER = @“S:\general\IFRS Phase III\Document Assembly\Test Notes”;
private static string OUTPUT_REPORT_NAME = @“Aspose Concatenation”;

public fMergeDocuments()
{
InitializeComponent();
}

private void btnMergeDocs_Click(object sender, EventArgs e)
{
// Retrieve files for processing.
string[] files = Directory.GetFiles(TEST_FOLDER, “.doc”, SearchOption.TopDirectoryOnly); // Retrieve both .doc and .docx files.

// Create an “empty” document. Note that like in Microsoft Word,
// the empty document has one section, body and one paragraph in it.
Document dstDoc = new Document(files[0]);

// Concatonate files with a heading and page break in between
for (int i = 1; i < files.Length; i++)
AppendDoc(dstDoc, files[i]);

// Save the finished document.
dstDoc.Save(TEST_FOLDER + OUTPUT_REPORT_NAME + “.docx”, SaveFormat.Docx);
dstDoc.Save(TEST_FOLDER + OUTPUT_REPORT_NAME + “.doc”, SaveFormat.Doc);
System.Diagnostics.Process.Start(TEST_FOLDER + OUTPUT_REPORT_NAME + “.doc”);
}

///
/// A useful function that you can use to easily append one document to another.
///
/// The destination document where to append to.
/// The source document.
public void AppendDoc(Document dstDoc, string srcDocName)
{
Document srcDoc = new Document(srcDocName);

// Make the section continuous with the note heading.
srcDoc.FirstSection.PageSetup.SectionStart = SectionStart.NewPage;
// Loop through all sections in the source document.
// Section nodes are immediate children of the Document node so we can just enumerate the Document.
foreach (Section srcSection in srcDoc)
{
// Because we are copying a section from one document to another,
// it is required to import the Section node into the destination document.
// This adjusts any document-specific references to styles, lists, etc.
//
// Importing a node creates a copy of the original node, but the copy
// is ready to be inserted into the destination document.
Node dstSection = dstDoc.ImportNode(srcSection, true, ImportFormatMode.UseDestinationStyles);

// Now the new section node can be appended to the destination document.
dstDoc.AppendChild(dstSection);
}
}
}
}

Thanks,
Irfan

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. I managed to reproduce the problem on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved.

Also, to merge documents you can use Document.AppendDocument method. This can simplify your code:

// Get file names of documents.

string[] fileNames = Directory.GetFiles(@"Test001\");

// Append all docuemtn to the first one.

Document dstDoc = new Document(fileNames[0]);

for (int i = 1; i < fileNames.Length; i++)

{

Document srsDoc = new Document(fileNames[1]);

srsDoc.FirstSection.PageSetup.SectionStart = SectionStart.NewPage;

dstDoc.AppendDocument(srsDoc, ImportFormatMode.KeepSourceFormatting);

}

// Save output document.

dstDoc.Save(@"Test001\out.doc");

dstDoc.Save(@"Test001\out.docx");

Best regards.

Thanks Alexey.

Hi,

Your destination document (the one with the image) has a document default line spacing that is big. On the other hand there is no line spacing specified explicitly in the source document with tables. When AW copies content with no line spacing formatting into a document with huge line spacing default (for the document), the content is shown like it has huge line spacing. This changes the layout of your tables.

There is currently no workaround for this in Aspose.Words. You need to edit the destination document (styles.xml) to modify the default line spacing or you can try appending your image to the document that contains the tables.

The issues you have found earlier (filed as 13239) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(40)

The issues you have found earlier (filed as WORDSNET-2098) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan