Hello,
I am attempting to export PDFs using Telerik with breaks for new pages. I start with HTML and convert it to a RadFlowDocument which I then export to a PDF. The whole process works well except for adding page breaks which do not display in the exported PDF.
I have tried a few methods on other posts such as adding an html tag for break points, manually cycling through paragraphs and adding breaks, and finally using the radflowdocumenteditor. Each method has not been able to add breakpoints correctly in the PDF on the export.
Can someone provide me with the correct ways to add page breaks in a RadFlowDocument to export using the PDFFormatProvider.
Here is snippets of code for each method I have tried.
Adding an html tag for page breaks:
<ItemTemplate>
<asp:Label ID="lblLetter" runat="server"></asp:Label>
<%If recordCount > 1 Then%>
<p style="page-break-after: always;"> </p>
<%End If%>
</ItemTemplate>
Result: No breakpoint is displayed in designated area
Cycling through RadFlowDocument and manually adding page breaks:
Html code:
<ItemTemplate>
<asp:Label ID="lblLetter" runat="server"></asp:Label>
<%If recordCount > 1 Then%>
<p>[PAGEBREAK]</p>
<%End If%>
</ItemTemplate>
VB Code for picking up Paragraphs with[PAGEBREAK] keyword:
Dim document As RadFlowDocument = provider.Import(html)
For Each fieldCharacter In document.EnumerateChildrenOfType(Of Paragraph)().ToArray()
For Each inline In fieldCharacter.Inlines.ToList()
If ((TypeOf inline Is InlineBase)) AndAlso ((TryCast(inline, Run)) IsNot Nothing) AndAlso ((CType(inline, Run)).Text = "[PAGEBREAK]") Then
Dim index = fieldCharacter.Inlines.IndexOf(inline)
Dim breakPage = New Break(document)
breakPage.BreakType = BreakType.PageBreak
fieldCharacter.Inlines.Insert(Index, breakPage)
fieldCharacter.Inlines.RemoveAt(Index + 1)
End If
Next
Next
Result: Using debugger, it is hitting the if statement for [PAGEBREAK] paragraphs correctly and assigning the page break, but the final export does not have any page breaks.
Using RadFlowDocumentEditor to add page breaks instead:
Html code:
<ItemTemplate>
<asp:Label ID="lblLetter" runat="server"></asp:Label>
<%If recordCount > 1 Then%>
<p>[PAGEBREAK]</p>
<%End If%>
</ItemTemplate>
VB Code for using editor:
Dim document As RadFlowDocument = provider.Import(html)
Dim editor As RadFlowDocumentEditor = New RadFlowDocumentEditor(document)
For Each fieldCharacter In document.EnumerateChildrenOfType(Of Paragraph)().ToArray()
For Each inline In fieldCharacter.Inlines.ToList()
If ((TypeOf inline Is InlineBase)) AndAlso ((TryCast(inline, Run)) IsNot Nothing) AndAlso ((CType(inline, Run)).Text = "[PAGEBREAK]") Then
editor.MoveToInlineEnd(inline)
editor.InsertBreak(BreakType.PageBreak)
End If
Next
Next
Result: Really confused on this one. I get a page break at the beginning of the document and no where else. Do I need to specify the specific paragraph as well when moving the editor? When I check the values in the debugger, it does appear to be cycling through every paragraph correctly; including the [PAGEBREAK] paragraph.
Thank you for the assistance.
Regards,
Avery