Hi, I’ve got an issue when merging documents.
The documents are all just duplicates from the same template but are merged together for printing.
The 1st document doesn’t appear to show the header, but then the subsequent documents do which causes them to be in different positions on the page.
I’m attaching the template, 3 documents and output document and associated code. If you’re able to let me know what the issue is that would be great.
A work around appears to be a modification of the header size stops this from happening, though it still looks funny as the 1st page isn’t showing the header.
To see this I have markers toggled on.
Thanks
Nolan
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing.Printing;
using Aspose.Words;
using HSL.Utils;
using System.IO;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
new Aspose.Words.License().SetLicense("Aspose.Words.DEV.lic");
List inputFiles = new List();
string outputFile = "";
inputFiles.Add(@"D:\Temp\MergeDocumentTest\InputDoc1.docx");
inputFiles.Add(@"D:\Temp\MergeDocumentTest\InputDoc2.docx");
inputFiles.Add(@"D:\Temp\MergeDocumentTest\InputDoc3.docx");
outputFile = @"D:\Temp\MergeDocumentTest\Output.docx";
// Load source documents
Document doc = DocumentLoader.Execute(inputFiles[0]);
for (int i = 1; i < inputFiles.Count; i++)
{
Document appendDoc = DocumentLoader.Execute(inputFiles[i]);
appendDoc.FirstSection.PageSetup.SectionStart = SectionStart.NewPage;
appendDoc.FirstSection.HeadersFooters.LinkToPrevious(false);
doc.AppendDocument(appendDoc, ImportFormatMode.KeepSourceFormatting);
}
if (File.Exists(outputFile))
File.Delete(outputFile);
doc.Save(outputFile);
// PrinterSettings printerSettings = new PrinterSettings();
// printerSettings.PrinterName = @"\Pancho\Xerox DocuCentre-III C2200 B&W";
// printerSettings.Duplex = Duplex.Vertical;
// doc.Print(printerSettings);
}
}
internal class DocumentLoader
{
public static Document Execute(string fileName)
{
switch (Path.GetExtension(fileName))
{
case ".docx":
case ".doc":
case ".dotx":
return new Document(fileName);
default:
return new Document();
}
}
}
}