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

Free Support Forum - aspose.com

Issue with page layout - aspose words

Hi There,

I’m merging two word files with different page layouts & orientation, even though I’m setting the target layout to the sourec but the merged document has different layouts here is the code snippet I’ve used and attached is the merged document for youtr reference.

Aspose.Words.License license = new License();
license.SetLicense("Aspose.Words.lic");
byte[] introMaterialFileBytes = ASTM.PPS.Common.WebUtility.DownloadDoc(introTemplateName);
if (introMaterialFileBytes != null)
{
    Document srcDocTemp = new Document(path + "RFG Introduction.docx");// new Document(new MemoryStream(introMaterialFileBytes));
    destinationFileName = path + destinationFileName;
    Document dstDocTemp = new Document(destinationFileName);
    // dstDocTemp.RemoveAllChildren();
    srcDocTemp.FirstSection.HeadersFooters.LinkToPrevious(false);
    srcDocTemp.FirstSection.PageSetup.SectionStart = SectionStart.NewPage;
    srcDocTemp.FirstSection.PageSetup.ClearFormatting();
    srcDocTemp.FirstSection.PageSetup.PaperSize = dstDocTemp.LastSection.PageSetup.PaperSize;
    srcDocTemp.FirstSection.PageSetup.PageWidth = dstDocTemp.LastSection.PageSetup.PageWidth;
    srcDocTemp.FirstSection.PageSetup.PageHeight = dstDocTemp.LastSection.PageSetup.PageHeight;
    srcDocTemp.FirstSection.PageSetup.Orientation = dstDocTemp.LastSection.PageSetup.Orientation;
    srcDocTemp.UpdatePageLayout();
    dstDocTemp.AppendDocument(srcDocTemp, ImportFormatMode.UseDestinationStyles);
    dstDocTemp.UpdateFields();
    dstDocTemp.UpdatePageLayout();
    dstDocTemp.Save(path + "MdifiedDocument2.docx");
}

Could you please let me know what is going wrong there

Thanks in advance

Naveen Anne.

Hi Gautham,

Thanks for your inquiry. It would be great if you please share following detail for investigation purposes.

  • Please attach your input Word documents.
  • Please

create a standalone/runnable simple application (for example a Console
Application Project
) that demonstrates the code (Aspose.Words code) you used to generate
your output document

  • Please attach the output Word file that shows the undesired behavior.
  • Please
    attach your target Word document showing the desired behavior. You can
    use Microsoft Word to create your target Word document. I will
    investigate as to how you are expecting your final document be generated
    like.

Unfortunately,
it is difficult to say what the problem is without the Document(s) and
simplified application. We need your Document(s) and simple project to
reproduce the problem. As soon as you get these pieces of information to
us we’ll start our investigation into your issue.

Hi Tahir,

Please find the attached code snippetalong with the sample documents

Looking forward for your quick response

Thanks,

Naveen Anne.

Hi Naveen,

Thanks for sharing the detail. Please set the orientation of page first and then set the width/height of page. This will fix the issue which you are facing. Please let us know if you have any more queries.

Document dstDoc = new Document(MyDir + "ProgramCP.docx");
//Document srcDoc = new Document(gDataDir + "TOC.docx");
Document srcDoc = new Document(MyDir + "RFGIntroduction.docx");
srcDoc.FirstSection.PageSetup.SectionStart = SectionStart.NewPage;
srcDoc.FirstSection.PageSetup.Orientation = dstDoc.LastSection.PageSetup.Orientation;
srcDoc.FirstSection.PageSetup.PageWidth = dstDoc.LastSection.PageSetup.PageWidth;
srcDoc.FirstSection.PageSetup.PageHeight = dstDoc.LastSection.PageSetup.PageHeight;
srcDoc.FirstSection.HeadersFooters.LinkToPrevious(true);
srcDoc.UpdatePageLayout();
dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);
dstDoc.UpdateFields();
dstDoc.UpdatePageLayout();
dstDoc.Save(MyDir + "Out.docx");

Hi Tahir,

Thanks for that.It works now.

–Naveen Anne

Hi Naveen,

Thanks
for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.