wxPdfDocument SetAutoPageBreak Not Working Topic is solved

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
Everydaydiesel
Earned some good credits
Earned some good credits
Posts: 125
Joined: Wed Oct 28, 2015 9:48 pm

wxPdfDocument SetAutoPageBreak Not Working

Post by Everydaydiesel »

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 4548 times
Can someone please tell me what I am doing wrong.

Thanks in advance
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPdfDocument SetAutoPageBreak Not Working

Post by utelle »

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
Earned some good credits
Earned some good credits
Posts: 125
Joined: Wed Oct 28, 2015 9:48 pm

Re: wxPdfDocument SetAutoPageBreak Not Working

Post by Everydaydiesel »

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
Earned some good credits
Earned some good credits
Posts: 125
Joined: Wed Oct 28, 2015 9:48 pm

Re: wxPdfDocument SetAutoPageBreak Not Working

Post by Everydaydiesel »

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.
Post Reply