Hi
I am trying to copy header from source document to target , it there is a shape inline followed by the text then the direction of the shape is miss aligned
Please See the screenshot below
Below is the code i am using to copy headers and footers
public void CopyHeaderandFooter(ref Document doc, Document template)
{
DocumentBuilder builder = new DocumentBuilder(doc);
DocumentBuilder template_builder = new DocumentBuilder(template);
//if (doc.Sections.Count != template.Sections.Count)
//{
// builder.MoveToDocumentStart();
// builder.Write(ControlChar.CrLf);
// //builder.InsertBreak(BreakType.SectionBreakContinuous);
//}
foreach (Section template_Section in template.Sections)
{
template_Section.GetChildNodes(NodeType.Any, true);
Section section = null;
int sectionIndex = template.Sections.IndexOf(template_Section);
//Check whether document A conteins section with same index
if (doc.Sections.Count > sectionIndex)
{
//Get correcponding section
section = doc.Sections[sectionIndex];
}
else
{
//Insert empty section
builder.MoveToDocumentEnd();
//builder.Writeln("Break");
builder.InsertBreak(BreakType.SectionBreakContinuous);
section = builder.CurrentSection;
}
//Loop throught all Headers/Footers in the B document
foreach (HeaderFooter hf_template in template_Section.HeadersFooters)
{
//Check whether current section from docA conteins
//Header/Footer with the same type as h/f from docB
if (section.HeadersFooters[hf_template.HeaderFooterType] != null)
{
section.HeadersFooters[hf_template.HeaderFooterType].RemoveAllChildren();
//Append content from h/f B to h/f A
foreach (Node childB in hf_template.ChildNodes)
{
//Import node
Node childA = doc.ImportNode(childB, true, ImportFormatMode.KeepSourceFormatting);
//Appent node to h/f
section.HeadersFooters[hf_template.HeaderFooterType].AppendChild(childA);
}
}
else
{
//Copy whole h/f
Node hf_doc = doc.ImportNode(hf_template, true, ImportFormatMode.KeepSourceFormatting);
var hfType = hf_template.HeaderFooterType;
section.HeadersFooters.Add(hf_doc);
foreach (Paragraph para in hf_template.GetChildNodes(NodeType.Paragraph, true))
{
int idx = hf_template.ChildNodes.IndexOf(para);
if (hf_doc.NodeType == NodeType.Paragraph)
{
Paragraph hf_para = (Paragraph)((HeaderFooter)hf_doc).ChildNodes[idx];
hf_para.ParagraphFormat.Style.Font.Name = para.ParagraphFormat.Style.Font.Name;
hf_para.ParagraphFormat.Style.Font.NameAscii = para.ParagraphFormat.Style.Font.NameAscii;
hf_para.ParagraphFormat.Style.Font.NameBi = para.ParagraphFormat.Style.Font.NameBi;
hf_para.ParagraphFormat.Style.Font.NameFarEast = para.ParagraphFormat.Style.Font.NameFarEast;
hf_para.ParagraphFormat.Style.Font.NameOther = para.ParagraphFormat.Style.Font.NameOther;
}
}
}
}
}
}
Input.docx (386.6 KB)