Page 1 of 1

Master/Detail export - Add table names

Posted: Tue Nov 29, 2022 2:23 pm
by philmills

I have a master table with 5 or so detail tables.
From master/detail view, when I export as PDF, the master record along with its detail tables are displayed correctly but the detail tables are missing table names.
How can I get the table names to be included?


Re: Master/Detail export missing table names

Posted: Tue Nov 29, 2022 5:31 pm
by arbei

Export does not export table name, you may customize the ExportPdf class and override the exportHeaderAndFooter() method.


Re: Master/Detail export missing table names

Posted: Mon Dec 05, 2022 4:07 pm
by philmills

exportHeaderAndFooter() contains this:

        $header = "<html><head>\r\n";
        $header .= $this->charsetMetaTag();
        $header .= self::styleTag();
        $header .= "</" . "head>\r\n<body>\r\n";
        $this->Text = $header . $this->Text . "</body></html>";

I need to get the name of the detail table to appear above each detail table. This doesn't seem like the correct function to modify for that.


Re: Master/Detail export missing table names

Posted: Mon Dec 05, 2022 4:24 pm
by philmills

Figured it out:

    public function exportTableHeader()
    {
	$this->Text .= "<h2 style='font-family: Arial, Helvetica, sans-serif*; padding-top: 10px;'>" . $this->Table->tableCaption() . "</h2>"; // Add table caption
        $this->Text .= "<table class=\"ew-table\">\r\n";
		
    }

working


PDF page break (v2023)

Posted: Tue Oct 03, 2023 3:22 am
by philmills

I have a View page with detail records.
When I export to pdf there are page breaks after every detail table, but some detail tables only have a couple of records, which makes for a whole lot of whitespace and scrolling.
So that's not suitable. I need a page break only when absolutely necessary.

I notice that in the dompdf extension you can now define the number of records before a page break should occur. The problem is that my records contain quite long text fields so breaking after X number of records just isn't viable either.

Ultimately I need each table just flowing one after the other, and if the text runs longer than the page, it should continue on the next.

I found that function exportPageBreak() has changed and now contains Config("PAGE_BREAK_HTML") . "\r\n" . // Page break
So I'm guessing this is what needs to be modified.
I already have a class in global which extends ExportPdf so I can add to that. But I can't find any reference to Config("PAGE_BREAK_HTML") anywhere to know what values or syntax to use


Re: v2023 pdf page break issue

Posted: Tue Oct 03, 2023 8:22 am
by mobhar

You may see the PAGE_BREAK_HTML config value simply from the generated src/config.php file:

    ...
    // Page break (Use old page-break-* for better compatibility)
    "PAGE_BREAK_HTML" => '<div style="page-break-after:always;"></div>',
    ...

Re: Master/Detail export missing table names

Posted: Thu Oct 05, 2023 2:18 am
by philmills

I'm struggling with this a little in v2023

I'm using a class to override the pdf export styling:

// override pdf export styling
class MyExportPdf extends ExportPdf {
    // Override exportTableheader()
    public function exportTableHeader() {
        $this->Text .= "<h2 style='font-family: Arial, Helvetica, sans-serif*; padding-top: 10px; page-break-before: avoid; page-break-after: avoid'>" . $this->Table->tableCaption() . "</h2>"; // Add table caption
        parent::exportTableHeader(); // Call the parent method
    }
}
Config('EXPORT_CLASSES.pdf', 'MyExportPdf'); // Replace the default ExportExcel class by your own class
Config('PAGE_BREAK_HTML', '<div style="page-break-after:avoid; page-break-inside: avoid; page-break-before: avoid;"></div>');

I need the caption in the h2 tag to appear directly above the associated table, but its inserting a pagebreak after the h2 tag for some reason, and I can't see where to control that.

can the Config PAGE_BREAK_HTML line be inserted specifically into the exportpdf function on the View page, rather than applying it globally?


Re: Master/Detail export missing table names

Posted: Thu Oct 05, 2023 10:57 am
by arbei
  1. Config("PAGE_BREAK_HTML") is used to force page breaks, it is not used for style attributes (which are handled by dompdf itself), you should remove your setting.
  2. <h2> will not cause page breaks, you should remove your style attributes.
  3. The page breaks are for separating the master table and the detail tables. If you don't want them, you should add CSS class "break-before-avoid" (see ewpdf.scss in the extension) to the table header, e.g.
    // Table header
    public function exportTableHeader()
    {
        $this->Text .= "<h2>" . $this->Table->tableCaption() . "</h2>" // Add table caption
        	. "<table class=\"ew-table break-before-avoid\">\r\n";
    }

Re: Master/Detail export - Add table names

Posted: Thu Oct 05, 2023 2:23 pm
by philmills

With your solution the rendered PDF results are as follows:

  1. The detail tables get truncated in the case that the table should run to more than one page. It seems like detail tables are limited to a single page
  2. The caption appears below the previous table, and the table to which it refers is always on the next page, like a page break is being inserted after the caption.

If I change this line to

. "<table class=\"ew-table break-before-avoid  break-after-avoid\">\r\n";

then the detail tables run nicely one after the other, but the records in the detail tables are being truncated instead of contuing on the next page

If i remove this line completely:

. "<table class=\"ew-table break-before-avoid\">\r\n";

the truncation issue goes away, but the page break after h2 caption is still there


Re: Master/Detail export - Add table names

Posted: Thu Oct 05, 2023 4:41 pm
by arbei
  1. If the master or detail table exceeds one page, it cannot be splitted into pages automatically as the height of the content depends on too many factors.
  2. <h2> alone (without any attributes as shown in above example) will not cause any line breaks unless you add page break CSS to the tag yourself.
  3. You must not remove the <table> open tag, it will make the HTML malformed and dompdf might not parse the HTML correctly.

Re: Master/Detail export - Add table names

Posted: Fri Oct 27, 2023 8:00 pm
by philmills

I have this working satisfactorily now

in global this is my modified pdf export and modified PAGE_BREAK_HTML

class MyExportPdf extends ExportPdf {
    // Override exportTableheader()
    public function exportTableHeader() {
	$this->Text .= "<h2 style='font-family: Arial, Helvetica, sans-serif*; padding-top: 10px; page-break-before: avoid; page-break-after: avoid'>" . $this->Table->tableCaption() . "</h2>"; // Add table caption
	//$this->Text .= "<table class=\"ew-table\" >\r\n";  // commenting this out is the ONLY way I have so far found to stop data truncation at the end of each page. 
        parent::exportTableHeader(); // Call the parent method
    }
}

Config('PAGE_BREAK_HTML', '<div style="page-break-after:avoid; page-break-inside: avoid; page-break-before: avoid;"></div>');

I modded also ewpdf changing "always" to "avoid" for these two classses:

.break-before-page {
  page-break-before: avoid;
}
.break-after-page {
  page-break-after: avoid;
}

Now all the tables run one after the other with table headings and no data gets truncated.

Commenting out the <table> tag from exportTableHeader is the only way I have found to stop data from being truncated.
I wonder if it's something to do with the fact that I'm using horizontal setting for pdf export.
I noticed that function exportPageBreak also includes an opening <table> tag in if($this->Horizontal)
that to me looks like one too many tables are being opened, as I don't see another closing table tag...

Can i override ewpdf.css in user styles ?


Re: Master/Detail export - Add table names

Posted: Fri Oct 27, 2023 9:01 pm
by arbei

philmills wrote:

Can i override ewpdf.css in user styles ?

No, but you may change Config("PDF_STYLESHEET_FILENAME") (default is "css/ewpdf.css") to your own .css.


Re: Master/Detail export - Add table names

Posted: Sat Oct 28, 2023 11:07 pm
by philmills

great - thanks
in this case are the min, scss and map files not required?