Sections and pagebreaks in 2012.1

4 posts, 0 answers
  1. Justin Lee
    Justin Lee avatar
    149 posts
    Member since:
    Dec 2009

    Posted 04 May 2012 Link to this post

    Hello,

    I have code that dynamically generates a RadDocument, and then exports it to word or pdf.  It has worked fine for months.  However recently I updated to Q1, 2012, and am having issues with page breaks when exporting.

    Now a page break is inserted after each Section in the export, which is a major problem.  To get around it, I could add all paragraphs/tables to 1 section, but then I lose the ability to insert page breaks where I do need them.

    Here is a simple example of what I'm doing.  When exported, "Test 1" and "Test 2" will be on separate pages.  How do I get rid of these page breaks?
    RadDocument document = new RadDocument();
    Section section = new Section();
    Paragraph paragraph = new Paragraph();
    Span span = new Span();
    span.Text = "Test 1";
    paragraph.Children.Add(span);
    section.Blocks.Add(paragraph);
    document.Sections.Add(section);
     
    section = new Section();
    paragraph = new Paragraph();
    span = new Span();
    span.Text = "Test 2";
    paragraph.Children.Add(span);
    section.Blocks.Add(paragraph);
    document.Sections.Add(section);
     
    document.LayoutMode = DocumentLayoutMode.Paged;
    document.Measure(RadDocument.MAX_DOCUMENT_SIZE);
    document.Arrange(new RectangleF(PointF.Empty, document.DesiredSize));
     
    using (System.IO.Stream output = dialog.OpenFile())
    {
              PdfFormatProvider provider = new PdfFormatProvider();
              provider.Export(document, output);                   
    }

  2. Ivailo Karamanolev
    Admin
    Ivailo Karamanolev avatar
    276 posts

    Posted 07 May 2012 Link to this post

    Hi,

    Since this version, we support multiple sections. Previously, all sections were merged without page breaks, but now they are not merged and remain separate. One limitation is that the only section break type is next page currently. You can still insert page breaks in paragraphs in the same way as previously.
    If you would like to NOT have page breaks between the different parts of the document you're building, you can simply insert all blocks (paragraphs, tables) into the same section.
    Let us know if you need additional assistance.

    Regards,
    Ivailo Karamanolev
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Justin Lee
    Justin Lee avatar
    149 posts
    Member since:
    Dec 2009

    Posted 07 May 2012 Link to this post

    I could use some guidance as to how to insert page breaks then. Previously, I was using document.InsertPageBreak() like so:
    document.Measure(RadDocument.MAX_DOCUMENT_SIZE);
    document.Arrange(new RectangleF(PointF.Empty, document.DesiredSize));
    document.CaretPosition.MoveToLastPositionInDocument();
    document.InsertPageBreak();

    But since I will only be adding 1 section, this method would only insert a page break before or after the section. How do I insert a page break within a Section (or paragraph)?

  5. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 08 May 2012 Link to this post

    Hello Justin,

    The method you used previously:

    document.InsertPageBreak();
    will insert a page break in the current section and should be just what you need.

    Let me dwell a little bit more on the document structure. You can preview a scheme of the document elements in this article.

    The document contains one or more sections. Each section can have one or more pages. For example, you can have a document with two sections, one of which is 3 pages long and the other has 2 pages. The only limitation currently is that the second section will start on a new page. In comparison, in MS Word you can have a section break within a page, thus one page can have content from two sections. This is not supported in RadRichTextBox at this point.

    Page breaks, on the other hand, are part of a Span and are included in a paragraph in a particular section. They are not related to section breaks in any way. You can have a section with 1, 2 or more page breaks anywhere in the content of the section.

    I hope this answers your question. Kind regards,
    Iva Toteva
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top