Hi I have an issue while doing a page count. Essentially I have some fairly stable code working for a few years now and has been working fine. Lately some of my clients want a contents page so my idea was while I was appending multiple documents together I could count the number of pages before documents were appended and I could store these values and create my own custom content page. Weirdly for some reason I do a page count my document changes. The change that occurs is that my header get carried across to every document by default but when I add the lines shown below my header isn't carried across.
doc.UpdatePageLayout();
int a = doc.PageCount;
My actual code as shown below.
MemoryStream startStream = new MemoryStream(files[0].FileData);
Document doc = new Document(startStream);
int[] count = new int[files.Length];
for (int i = 1; i < files.Length; i++)
{
if (files[i].FileData == null)
{
}
else
{
MemoryStream ms = new MemoryStream(files[i].FileData);
{
}
else
{
MemoryStream ms = new MemoryStream(files[i].FileData);
// Open the document to join.
Document srcDoc = new Document(ms);
Document srcDoc = new Document(ms);
bool pageBreakBefore = files[(i - 1)].PageBreakAfter;
int headerAndFooterCount = srcDoc.FirstSection.HeadersFooters.Count;
bool hasHeaderAndFooter = false;
bool hasHeaderAndFooter = false;
if (headerAndFooterCount > 0)
{
hasHeaderAndFooter = true;
}
{
hasHeaderAndFooter = true;
}
if (pageBreakBefore == true)
{
{
srcDoc.FirstSection.PageSetup.PageWidth = doc.LastSection.PageSetup.PageWidth;
srcDoc.FirstSection.PageSetup.PageHeight = doc.LastSection.PageSetup.PageHeight;
srcDoc.FirstSection.PageSetup.Orientation = doc.LastSection.PageSetup.Orientation;
}
else
{
srcDoc.FirstSection.PageSetup.PageHeight = doc.LastSection.PageSetup.PageHeight;
srcDoc.FirstSection.PageSetup.Orientation = doc.LastSection.PageSetup.Orientation;
}
else
{
srcDoc.FirstSection.PageSetup.SectionStart = SectionStart.Continuous;
srcDoc.FirstSection.PageSetup.PageWidth = doc.LastSection.PageSetup.PageWidth;
srcDoc.FirstSection.PageSetup.PageHeight = doc.LastSection.PageSetup.PageHeight;
srcDoc.FirstSection.PageSetup.Orientation = doc.LastSection.PageSetup.Orientation;
}
doc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);
if (i > 1)
{
if (hasHeaderAndFooter == true)
{
}
else
{
doc.Sections[i].HeadersFooters.LinkToPrevious(true);
}
}
{
doc.Sections[i].HeadersFooters.LinkToPrevious(true);
}
}
}
doc.UpdatePageLayout();
int a = doc.PageCount;
}
}
If the last 2 lines are commented out the document is fine. If the are uncommented I can see the "a" variable is correct in the loop but the document does not render correctly.