wxPdfDocument SetAutoPageBreak Not Working  [SOLVED]

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Everydaydiesel
Experienced Solver
Experienced Solver
Posts: 93
Joined: Wed Oct 28, 2015 9:48 pm

wxPdfDocument SetAutoPageBreak Not Working

Postby Everydaydiesel » Sat Aug 18, 2018 8:42 pm

Hello,

I am trying to figure out the SetAutoPageBreak but it seems that I am not using it properly. Even though the loop goes to 250, the pdf document is only one page

Code: Select all

    wxPdfDocument m_pdfDoc;
    wxPdfFontManager::GetFontManager()->AddSearchPath(wxT("/usr/share/fonts"));
    m_pdfDoc.SetAutoPageBreak(true,10);     // I tried this commented and uncommented but the behavior is the same.
    m_pdfDoc.AddPage(wxPORTRAIT, wxPAPER_A4);
    m_pdfDoc.SetFont(wxT("Helvetica"), wxPDF_FONTSTYLE_REGULAR, 12);
   
    for(int j=0; j < 250; j++)
    {
        m_pdfDoc.Text(10, 5*j, "test " + SSTR(j));
    }


pdf_page_break.png
pdf_page_break.png (49.12 KiB) Viewed 1344 times


Can someone please tell me what I am doing wrong.

Thanks in advance

utelle
Moderator
Moderator
Posts: 831
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPdfDocument SetAutoPageBreak Not Working  [SOLVED]

Postby utelle » Sat Aug 18, 2018 9:15 pm

Everydaydiesel wrote:I am trying to figure out the SetAutoPageBreak but it seems that I am not using it properly. Even though the loop goes to 250, the pdf document is only one page

This is not surprising, because you used method Text of wxPdfDocument to output your text strings to PDF. The signature of this method is

Code: Select all

virtual void wxPdfDocument::Text(double x, double y, const wxString& txt )

That is, it outputs the string txt at the absolute position (x,y) on a page. What should the automatic page break mechanism do in such a case? If position (x,y) is not within the margins of the current page, it will not be within the margins of the next page either. Therefore method Text does not trigger a page break.

Auto page break mode functions properly only for text output methods that do not use an absolute y position. For example, you could use one of the methods Cell, MultiCell, Write, WriteCell, or WriteXML. Explicit line breaks can be added using method Ln.

Regards,

Ulrich

Everydaydiesel
Experienced Solver
Experienced Solver
Posts: 93
Joined: Wed Oct 28, 2015 9:48 pm

Re: wxPdfDocument SetAutoPageBreak Not Working

Postby Everydaydiesel » Sat Aug 18, 2018 10:30 pm

thank you!!!


On last question, is there any way I can preview the pdf in a control (like rendering it inside of a wxPanel)

Everydaydiesel
Experienced Solver
Experienced Solver
Posts: 93
Joined: Wed Oct 28, 2015 9:48 pm

Re: wxPdfDocument SetAutoPageBreak Not Working

Postby Everydaydiesel » Sun Aug 19, 2018 12:51 am

so if I have a pdf (report) that has 4 columns.

How can I print 4 header labels and then align them with the columns for each row?

Lets say i have a column that starts at 10, 100, 150, and 250.


Return to “wxCode”

Who is online

Users browsing this forum: No registered users and 7 guests