Page spill covers header

Hi

I have a word document that generates dynamic tables on each page, so I cannot know the height of a page at compile time. When a page contains too much data to fit on one page, it spills over onto the next, which would be fine except that the content appears on top of the header on the next page. Why does Aspose.Word not detect that the page has a header and place the content below it? Is there a way to do this explicitly? From what I’ve read, it seems impossible to know when the content has spilled over, because of the lack of a page layout engine?

Thanks

Hi,

Thank you for considering Aspose.

Yes, such the measurements are not yet possible, but they are required for rendering the pages whereas building document content should not show the behaviour like that. What are you using for generating the tables? Please post your code and the problematic document to let me properly identify the issue.

Something strange I noticed just now about the header is that when I try and edit it in Word, using View Headers and Footers, the dotted selection box of the header does not completely contain my header content, which is just an image. The code for building the header is below:

double ratio = usableWidth / headerImg.Width;
double imageHeight = headerImg.Height * ratio;

double imageLeft = 0;

docBuilderRef.MoveToHeaderFooter (HeaderFooterType.HeaderPrimary);
docBuilderRef.InsertImage (headerImg, RelativeHorizontalPosition.Margin, imageLeft, RelativeVerticalPosition.Margin, 0, usableWidth, imageHeight, WrapType.None,
WrapSide.Both, false, null);
docBuilderRef.MoveToSection (docRef.Sections.Count - 1);

docBuilderRef.MoveToHeaderFooter (HeaderFooterType.HeaderFirst);
docBuilderRef.InsertImage (headerImg, RelativeHorizontalPosition.Margin, imageLeft, RelativeVerticalPosition.Margin, 0, usableWidth, imageHeight, WrapType.None,
WrapSide.Both, false, null);
docBuilderRef.MoveToSection (docRef.Sections.Count - 1);

Additionally, the spill over content starts directly below this smaller header, so it seems Aspose.Word is doing that correctly, and that I’m building it incorrectly. Do you know why this would be?

My pageSetup, in case it helps, looks like this:

docBuilderRef.PageSetup.Orientation = Orientation.Landscape;
docBuilderRef.PageSetup.SectionStart = SectionStart.NewPage;
docBuilderRef.PageSetup.LeftMargin = 56.7;
docBuilderRef.PageSetup.RightMargin = 56.7;
docBuilderRef.PageSetup.TopMargin = 42.55;
docBuilderRef.PageSetup.BottomMargin = 56.7;
docBuilderRef.PageSetup.HeaderDistance = 20.7;
docBuilderRef.PageSetup.FooterDistance = 22.7;
docBuilderRef.PageSetup.DifferentFirstPageHeaderFooter = true;
docBuilderRef.PageSetup.PaperSize = PaperSize.A4;
docBuilderRef.PageSetup.VerticalAlignment = PageVerticalAlignment.Top;

If possible, please attach the document as well.

I have attached a doc with two examples of the problem.

Thanks

Ok, I solved a bit of the problem by setting the image WrapType to inline, which makes sense I suppose. But now there is a large gap between the bottom of the header and start of the content, but only on pages that start on a section start page. Pages that spill over now start flush against the header. Any ideas how I can get rid of the gap? Setting PageSetup.HeaderDistance and PageSetup.TopMargin don’t do it.

Thanks

Thanks for the detailed explanation of the problem. The cause is simple. Your image is actually located in the header, but it is floating so there’s nothing weird that it is located behind the text. Take a look at the the DocumentBuilder.InsertImage method overloads and use ones that insert inline image. Then you will get the header image not overlapped with text.

Please report if it helps.

Thanks for the reply. Got in just before you. Any ideas why I have the gap now between header and content?

Sure. The gaps are caused by empty paragraphs right after the headers that have 50 pt spacing before them. I have no idea why they are there. Aspose.Word should not implicitly insert them.