Page break - HtmlFormatProvider + PdfFormatProvider

5 posts, 0 answers
  1. william
    william avatar
    6 posts
    Member since:
    Dec 2016

    Posted 03 Feb Link to this post

    Hello,
    I'm having trouble breaking a new page using HtmlFormatProvider and PdfFormatProvider

    My code

    var html = "<h1>firstpage</h1><?hard-pagebreak?><h1>secondpage</h1>";
    HtmlFormatProvider prov = new HtmlFormatProvider();
    RadFlowDocument document = prov.Import(html);
     
    var provider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();
    var ouput = provider.Export(document);
    File.WriteAllBytes(@"D:\a.pdf", ouput);

     

    What am I doing wrong ?

     

     

  2. Tanya
    Admin
    Tanya avatar
    583 posts

    Posted 08 Feb Link to this post

    Hello William,

    The page breaks are not supported in the model of the HTML documents. If you would like, you can import the desired document with the HtmlFormatProvider and add a page break to the content using the Break element.

    Hope this is helpful.

    Regards,
    Tanya
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. william
    william avatar
    6 posts
    Member since:
    Dec 2016

    Posted 08 Mar Link to this post

    Do you have any examples of how I can do this?
    I need to replace <?hard-pagebreak?> with a new page
  4. william
    william avatar
    6 posts
    Member since:
    Dec 2016

    Posted 09 Mar Link to this post

    I solved my problem using with the following code

     

    private void PrepareHtml()
    {
        editor.Content = editor.Content.Replace("<?hard-pagebreak?>", "<b>[PAGEBREAK]</b>");
    }
     
    private void InsertPageBreak(RadFlowDocument document)
    {
        foreach (var fieldCharacter in document.EnumerateChildrenOfType<Paragraph>().ToArray())
        {
            foreach (var inline in fieldCharacter.Inlines.ToList())
            {
                if (((inline is InlineBase)) && ((inline as Run) != null) && (((Run) inline).Text == "[PAGEBREAK]"))
                {
                    var index = fieldCharacter.Inlines.IndexOf(inline);
                    var breakPage = new Break(document);
                    breakPage.BreakType = BreakType.PageBreak;
     
                    fieldCharacter.Inlines.Insert(index, breakPage);
                    fieldCharacter.Inlines.RemoveAt(index + 1);
                }
            }
        }
    }
  5. Tanya
    Admin
    Tanya avatar
    583 posts

    Posted 13 Mar Link to this post

    Hi William,

    Yes, replacing the HTML tags with keywords which are later replaced by the Break element should do the trick. You can take a look at the Break help article to check the different types of breaks you can use and their properties.

    Regards,
    Tanya
    Telerik by Progress

Back to Top