Page 1 of 1

wxPdfDocument SetAutoPageBreak Not Working

Posted: Sat Aug 18, 2018 8:42 pm
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 4556 times
Can someone please tell me what I am doing wrong.

Thanks in advance

Re: wxPdfDocument SetAutoPageBreak Not Working

Posted: Sat Aug 18, 2018 9:15 pm
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

Re: wxPdfDocument SetAutoPageBreak Not Working

Posted: Sat Aug 18, 2018 10:30 pm
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)

Re: wxPdfDocument SetAutoPageBreak Not Working

Posted: Sun Aug 19, 2018 12:51 am
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.