Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Fri Sep 23, 2016 11:51 am

Hello

I am a new user of spire PDF (ASP NET / VB.NET)

I succeed to create a PDF document with a grid on several pages.
I did not find how to add a page break.
By example, after 10 rows, I would like that the grid resume on the next page.

With my fist try, there is page break but the first 10 rows are repeated on the seconde page with the end of the data.

page 1 : row 1 to 10
page 2 and next : row 1 to end

Code: Select all
    Protected Sub Bt_grid_Click(sender As Object, e As EventArgs) Handles Bt_grid.Click

        Dim monPDF As New Spire.Pdf.PdfDocument()
        Dim section = monPDF.Sections.Add
        Dim unePage As PdfPageBase = Nothing
        Dim result As PdfLayoutResult = Nothing

        Dim nbcolonnes As Integer = 10

        Dim grid As New PdfGrid()

        section.PageSettings.Orientation = PdfPageOrientation.Landscape

        unePage = section.Pages.Add()

        Grid.Columns.Add(2)     ' 2 colonnes

        Dim nb_ligne_entete As Integer = 2

        Dim entete(nb_ligne_entete) As PdfGridRow


        'entête du tableau
        Dim entete2 As PdfGridRow

        For i As Integer = 0 To nb_ligne_entete - 1                ' 2 lignes d'entête sans bordure, pas forcément nécessaire
            entete(i) = grid.Headers.Add(1)(i)
   
        Next

        entete2 = grid.Headers.Add(1)(2)            ' entêtes des données la ligne suivante

        entete(0).Cells(0).Value = "entete 0 row 0"
        entete(0).Cells(1).Value = "entete 1  row0"
        entete(1).Cells(1).Value = "entete 1 row 1"


        grid.RepeatHeader = True

        'loop to fill the grid :

        For i As Integer = 1 To 200

            Dim contenuRow As PdfGridRow = grid.Rows.Add()


            contenuRow.Cells(0).Value = "Valeur " & i

            ' here, i want to add a page / pager break
            If i = 10 Then
                result = grid.Draw(unePage, New PointF(1, 1))
                unePage = section.Pages.Add()
            End If

        Next

        result = grid.Draw(unePage, New PointF(1, 1))

        monPDF.SaveToHttpResponse("Grille.pdf", HttpContext.Current.Response, HttpReadType.Save)


    End Sub         
         


My question : how add a page break ?



Thanks.

stef_b
 
Posts: 3
Joined: Fri Sep 23, 2016 9:53 am

Mon Sep 26, 2016 3:09 am

Dear stef_b,

Thanks for your inquiry and sorry for late reply as weekend.
Sorry that it is not possible to add a page break. In this case, we suggest you add a new page first, and then draw the rest of grid on the new page.
If there is any question, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Mon Sep 26, 2016 6:08 am

Hello,

Yes, adding a new page is the solution but I do not succeded to do that.

But, in my example, after adding a page with
Code: Select all
              result = grid.Draw(unePage, New PointF(1, 1))
                unePage = section.Pages.Add()


The fisrt rows are too on the seconde page (please see grille.pdf in attachement)

I do not find the right way to do that.

Many thanks if you can help me.

stef_b
 
Posts: 3
Joined: Fri Sep 23, 2016 9:53 am

Mon Sep 26, 2016 8:29 am

Dear stef_b,

Thanks for your prompt reply.
You need to create two grids, the first one only have 10 rows and then draw it on first page. And then add a new page, create a new grid and then draw it on second page.
Here is sample code for your reference:
Code: Select all
            ...
            grid.RepeatHeader = true;
            //loop to fill the first grid :
            for (int i = 1; i <= 10; i++)
            {
                PdfGridRow contenuRow = grid.Rows.Add();
                contenuRow.Cells[0].Value = "Valeur " + i;
            }
            result = grid.Draw(unePage, new PointF(1, 1));
            unePage = section.Pages.Add();

            PdfGrid grid2 = new PdfGrid();
            grid2.Columns.Add(2);
            ...
            grid2.RepeatHeader = true;
            //loop to fill the second grid :
            for (int i = 11; i <= 200; i++)
            {
                PdfGridRow contenuRow = grid2.Rows.Add();
                contenuRow.Cells[0].Value = "Valeur " + i;
            }
            grid2.Draw(unePage, new PointF(1, 1));

Hope this can help you. If this doesn't meet your requirement, please provide us your target document. And then we will provide you corresponding code.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Mon Sep 26, 2016 12:30 pm

Hello,

Good news : your answer help me solve my problem. The trick was to add a new grid, that I did not understood by myself.

Thank you very much !


Here is the code, it could be useful for other (sorry : in VB )
Code: Select all
        Dim monPDF As New Spire.Pdf.PdfDocument()
        Dim section = monPDF.Sections.Add
        Dim unePage As PdfPageBase = Nothing

        Dim nbcolonnes As Integer = 2
        Dim sansGrille = New PdfBorders()

        Dim gridTMP As New PdfGrid()


        'For header without border lines
        sansGrille.All = New PdfPen(Color.Transparent)

        Dim nb_ligne_entete As Integer = 2
        For i As Integer = 1 To 200  '200 rows to display

            If i = 1 Or i = 11 Then   ' after 10 row, adding a new grid


                If i = 11 And i > 0 Then
                    gridTMP.Draw(unePage, New PointF(1, 1))

                End If

                Dim grid As New PdfGrid()

                section.PageSettings.Orientation = PdfPageOrientation.Landscape

                unePage = section.Pages.Add()

                grid.Columns.Add(2)
                grid.RepeatHeader = True        'repeat header for new page without new grid

                gridTMP = grid


                ' header has to be repeat on every new grid :
                Dim entete2 As PdfGridRow
                Dim entete(nb_ligne_entete) As PdfGridRow

                For k As Integer = 0 To nb_ligne_entete - 1                ' 2 lignes d'entête sans bordure, pas forcément nécessaire
                    entete(k) = gridTMP.Headers.Add(1)(k)
                    For j As Integer = 0 To nbcolonnes - 1
                        entete(k).Cells(j).Style.Borders = sansGrille    'no border line
                    Next
                Next

                entete2 = gridTMP.Headers.Add(1)(2)            ' this header has border line

                entete(0).Cells(0).Value = "entete 0 row 0"
                entete(0).Cells(1).Value = "entete 1  row0"
                entete(1).Cells(1).Value = "entete 1 row 1"
                entete2.Cells(0).Value = "colonne 0"


            End If


            Dim contenuRow As PdfGridRow = gridTMP.Rows.Add()


            contenuRow.Cells(0).Value = "Valeur " & i

        Next

        gridTMP.Draw(unePage, New PointF(1, 1))


        monPDF.SaveToHttpResponse("Grille.pdf", HttpContext.Current.Response, HttpReadType.Save)

stef_b
 
Posts: 3
Joined: Fri Sep 23, 2016 9:53 am

Tue Sep 27, 2016 1:25 am

Dear stef_b,

Thanks for sharing your VB code.
Welcome to write to us again for further question.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.PDF