Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word document - 2nd page - creating some empty space at the top?

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
We're generating (creating, saving and printing) MS Word documents from Visual Studio .NET C# code.
The challenge we've just been set is to have the second page start lower down the page than the first.
That is, the first page will start quite high on the document. If the report flows onto a second page then we want this to start about a quarter of a way down the page.
How can we do this ?
Such that the second and subsequent pages start lower down than the first ?

Any pointers / advice would be greatly appreciated.
Thanks in advance
Steve
 
Steve,
This will probably be the simplest suggestion you will receive. You can't use page margins, as they apply to the whole document. But, wouldn't simple carriage returns on the beginning of all pages after the first one do the job? Like I said, this is definitely not the most elegant solution but it may just work. Add a couple of Environment.NewLine characters to the beginning of each page after the first one and see how it goes.

JC

Jesus Christ! I was unaware of all the smileys available here at tek-tips.
[rockband]
 
This simple suggestion begs answer to a simple question - how do I determine when I'm on the second page within the MS Word document ?
The document is being generated, saved and printed via code.
Steve
 
Steve,
I haven't worked with Word but I've done some projects in Excel and experienced the same problem. I have to warn you that this isn't the best solution but it might shed some light. This is what I do:

1 - I create an Excel document manually, add enough data (rows) data to it until the document spans for over a page, and notice the row where Excel adds an automatic page break.

2 - Based on this row, I then create a constant that represents the number of rows that fit in an Excel page.

3 - Then, in code, when I create the Excel document, I add page breaks manually (but I guess I could let Excel do it itself. I just like to be in control). This allows me to keep track of each page and treat each page individually.

Thus, the idea is that you know before hand how much data fits per page. I haven't used Word and thus I don't know exactly what mechanism you could use to get this information. In Excel it's very simple because I simply count the number of rows.

In any case, if you could come up with a way, in Word, to determine how much data fits per page, you will be able to know which page you're in. I think Word has columns and rows as well, although it may not be so obvious. But, if you find, for example, that x amount of rows fit per page, then all you'll need to do is count how many rows your code has added in the current page, and add a manual page break when the limit is reached. At this point, you'll know you're in a new page which will need the extra NewLine characters at the beginning.

Of course, it may not be as easy with you, if your Word document has different fonts or different font sizes in different pages. A lot more data, for example, will fit per page when the font size is 8 than when its 18. If you have different font sizes in the same page, then that's even more difficult.

Like I said, this technique isn't the most elegant one, but it has proved efficient enough for me in Excel. Hope it sheds some light to you.

JC

Oh Wow!!! I was unaware of all the smileys available here at tek-tips.
[rockband]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top