locked
Delete blank page in Word RRS feed

  • Question

  • Hi,
    I am using Word automation in my project using C#.
    Everytime i generate a document, a blank page is created at the end of document.
    Could you please anyone tell me how to delete the last blank page in c#
    Thanks in advance
    Friday, December 4, 2009 10:23 AM

Answers

  • As you must be aware of that word pagination is automatic. So your code is creating a new word document and when you dynamically(through code) adding someting on the document using the WordDocument object it comes at the top of the already created word document in the memory.

    I suggest you to create a word document template file (.dot) design it according to your need(I prefer you do it manually) and then manipulate them using code like placing your images.....

    take a look at this post of mine in which i have used mail merge option using a word template....but if I would have done this by creating the word document programatically, it would have added a blank page.

    I hope this helps.


    http://www.midnightprogrammer.net
    • Proposed as answer by Bessie Zhao Friday, December 11, 2009 11:27 AM
    • Marked as answer by Bessie Zhao Tuesday, December 15, 2009 9:48 AM
    Friday, December 4, 2009 10:48 AM

All replies

  • What type of word automation you are using.....Are you automating word document using Mail Merge fields?

    Still you can look up to this thread:

    http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/1fb02ac4-a44d-48b1-9478-da507f4c5276



    http://www.midnightprogrammer.net
    Friday, December 4, 2009 10:25 AM
  • Thanks prashant for your reply.

    I tried with the solution which is given in the link - but in vain.

    Not mail merge. But according to my requirment i have some images stored in local drive. I create a word document, insert a table, insert pictures in the table cells. I do above operations according to some conditions.

    At all the cases, i am getting a blank page at the end of word document.

    Friday, December 4, 2009 10:37 AM
  • As you must be aware of that word pagination is automatic. So your code is creating a new word document and when you dynamically(through code) adding someting on the document using the WordDocument object it comes at the top of the already created word document in the memory.

    I suggest you to create a word document template file (.dot) design it according to your need(I prefer you do it manually) and then manipulate them using code like placing your images.....

    take a look at this post of mine in which i have used mail merge option using a word template....but if I would have done this by creating the word document programatically, it would have added a blank page.

    I hope this helps.


    http://www.midnightprogrammer.net
    • Proposed as answer by Bessie Zhao Friday, December 11, 2009 11:27 AM
    • Marked as answer by Bessie Zhao Tuesday, December 15, 2009 9:48 AM
    Friday, December 4, 2009 10:48 AM
  • Check out this link also

    http://www.midnightprogrammer.net
    • Marked as answer by Bessie Zhao Friday, December 11, 2009 11:27 AM
    • Unmarked as answer by Bessie Zhao Friday, December 11, 2009 11:27 AM
    Friday, December 4, 2009 10:55 AM