Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6845965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:33:56+00:00 2026-05-27T00:33:56+00:00

From aspx page, I dynamically add paragraphs to a word document using OpenXml SDK.

  • 0

From aspx page, I dynamically add paragraphs to a word document using OpenXml SDK. In this case, a page break within a paragraph is not allowed. So in case a paragraph starts in middle of page 1 and extends to page2 then it should actually start in Page2. However, if it ends in the same page it is okay.

How to achieve this? Is there a way to set in th document that page break is not allowed within a paragraph? Any input is highly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:33:56+00:00Added an answer on May 27, 2026 at 12:33 am

    In general you can not use the open xml sdk to determine where in a page an element will be displayed, since open xml has no concepts of pages.

    Pages are determined by the client application consuming the open xml document. You can however specify that a paragraph’s lines are kept together.

    <w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
      <w:pPr>
        <w:keepLines />
      </w:pPr>
      <w:bookmarkStart w:name="_GoBack" w:id="0" />
      <w:r>
        <w:lastRenderedPageBreak />
        <w:t>Most controls offer a choice of using the look from the current theme or using     a format that you specify directly. To change the overall look of your document, choose new your document.</w:t>
      </w:r>
      <w:bookmarkEnd w:id="0" />
    </w:p>
    

    w:keepLines in the above examples paragraph properties is the key to making sure a paragraph is not split up between pages, below is the open xml required to generate the above paragrpah:

    using DocumentFormat.OpenXml.Wordprocessing;
    using DocumentFormat.OpenXml;
    
    namespace GeneratedCode
    {
        public class GeneratedClass
        {
            // Creates an Paragraph instance and adds its children.
            public Paragraph GenerateParagraph()
            {
                Paragraph paragraph1 = new Paragraph();
    
                ParagraphProperties paragraphProperties1 = new ParagraphProperties();
                KeepLines keepLines1 = new KeepLines();
    
                paragraphProperties1.Append(keepLines1);
                BookmarkStart bookmarkStart1 = new BookmarkStart(){ Name = "_GoBack", Id = "0" };
    
                Run run1 = new Run();
                LastRenderedPageBreak lastRenderedPageBreak1 = new LastRenderedPageBreak();
                Text text1 = new Text();
                text1.Text = "Most controls offer a choice of using the look from the current theme or using.";
    
                run1.Append(lastRenderedPageBreak1);
                run1.Append(text1);
                BookmarkEnd bookmarkEnd1 = new BookmarkEnd(){ Id = "0" };
    
                paragraph1.Append(paragraphProperties1);
                paragraph1.Append(bookmarkStart1);
                paragraph1.Append(run1);
                paragraph1.Append(bookmarkEnd1);
                return paragraph1;
            }       
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to add javascript reference dynamically from code behind aspx.cs? Like this:
I have an ASPX page that is dynamically creating a gridview from a database
I'm trying to return a transparent GIF from an .aspx page for display within
I am trying to return a JSON object from an aspx page using Jayrock.JSON.
How would one display any add content from a dynamic aspx page? Currently I
I am using this example from microsoft to call web services dynamically using reflection:
I have implemented JQuery FullCalendar by fetching the events dynamically from an aspx page.
I need to pull item quantity from a DB2 database from an aspx page
So I'm trying to load some returned html from an .aspx page but a
As I mentioned here , I'm trying to generate HTML from an ASPX page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.