Hi,
I am attaching a simple word document without any header, footer or table of content. The generated output document always displays BLANK (empty) as first page. Any idea?
---------- sample code -----
Document subDoc = new Document(sourceDocumentFullPath);
builder.MoveToDocumentStart();
foreach(Section srcSection in subDoc)
{
Node dstSection = builder.Document.ImportNode(srcSection, true,
ImportFormatMode.KeepSourceFormatting);
builder.Document.AppendChild(dstSection);
}
builder.MoveToDocumentEnd();
Thanks for your request. Could you please attach your input and output documents here? I will investigate the issue and provide you more information.
Best regards,
I am using the DocumentBuilder (builder) to build the output doc as you can see in my code. Would I be able to modify my code by using what you have suggested to resolve the issue? If so, can you shed some light? Thanks again.
–Shopon
Please ignore my previous reply. I think just adding the line
‘subDoc.Sections[0].PageSetup.SectionStart = SectionStart.Continuous;’ in my code works. Please let me know if just doing that will cause issue in the future.
Thanks you.
–Shopon
Hi, things are looking much better. Still have a minor issue unresloved. Adding the following line
‘subDoc.Sections[0].PageSetup.SectionStart = SectionStart.Continuous;’ gets rid of the BLANK first page; but also get rid of the HEADER and FOOTER only from the first page. Please reply.
Thanks.
–Shopon
Thanks for your prompt response. It got rid of the blank first page; but also got rid of the HEADER and FOOTER from the first page. Please response. Thanks in advance.
–Shopon
Can you please use the attached file (test.doc) as source file and check if the generated output file have the BLANK first page as well as the header and footer on the first page is not missing.
Thanks.
–Shopon
Thank you for additional information.
Unfortunately I, as Andrey could not reproduce your problem on my side. Please specify which version of Aspose.Words you’re using. The current version of our product 9.7.0.0. You can download it from: https://releases.aspose.com/words/net
Hi, just downloaded and tested the latest (9.7) as you suggested; but still having the same issue. I won’t be able to give my manager green signal to purchase the license unless this works. Please test one more time to check if i am missing anything.
The following block of code works fine.
---------
Document subDoc = new Document(sourceDocumentFullPath);
builder.Document = subDoc;
builder.MoveToDocumentEnd();
----
But the issue with the code above is that it will overwrite the existing document in the builder with the current one.
Thanks.
–Shopon
Hi
Thank you for additional information. Could you please create simple application which will allow me to reproduce the problem on my side? I will check it on my side and provide you more information.
Best regards,
Hi, it seems to me that there is a PageBreak automatically gets inserted at the begining of the document.
“subDoc.Sections[0].PageSetup.SectionStart = SectionStart.Continuous” gets rid of the PageBreak; but somehow does not overwrite the Header and Footer which is why Header and Footer for the first page is missing while BlankPage is gone.
I also tried the use the following block of code without any sucess (blankpage):
-------------
Document subDoc = new Document(sourceDocumentFullPath);
builder.Document.AppendDocument(subDoc, ImportFormatMode.KeepSourceFormatting);
-------------
Only code works is builder.Document = subDoc;(again we will have issue with multiple attachments!!)
Is there a way we can remove the first page from the doc? Any further inputs toward the resolution?
Thanks.
–Shopon
Hello
Thank you for additional information. Let me clarify, documents are appended at the section level therefore the PageSetup.SectionStart property of the Section object defines how the content of the current section is joined in relation to the previous section. If the PageSetup.SectionStart property is set to SectionStart.NewPage for the first section in the source document then the content in this section is forced to start on a new page. Conversely if the property is set to SectionStart.Continuous then the content is allowed to flow on the same page directly after the previous section’s content. But there are still two sections in the output document. Each section in MS Word has its own Header/Footer, that is why you can see first page without Header/Footer.
To resolve the problem you should copy Header/Footer.
Please try using the following code for testing.
// Open document
Document dstDoc = new Document();
Document subDoc = new Document("C:\\Temp\\test.doc");
DocumentBuilder builder = new DocumentBuilder(dstDoc);
builder.Document.FirstSection.PageSetup.Orientation = subDoc.FirstSection.PageSetup.Orientation;
builder.Document.FirstSection.PageSetup.PageWidth = subDoc.FirstSection.PageSetup.PageWidth;
builder.Document.FirstSection.PageSetup.PageHeight = subDoc.FirstSection.PageSetup.PageHeight;
subDoc.Sections[0].PageSetup.SectionStart = SectionStart.Continuous;
builder.Document.AppendDocument(subDoc, ImportFormatMode.KeepSourceFormatting);
// Copy Header/Footer from the second Section to the first Section
foreach(HeaderFooter headerFooter in dstDoc.Sections[1].HeadersFooters)
{
dstDoc.Sections[0].HeadersFooters.Add(headerFooter.Clone(true));
}
Thanks for the detail. I will try your suggession when get a chance.
Just tried the following two different solutions suggessted by one of the user. Both of them work as I expected. Please response only if you think those solutions will cause further issue later.