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?
Master/Detail export - Add table names
-
- User
- Posts: 565
Master/Detail export - Add table names
-
- User
- Posts: 9419
Export does not export table name, you may customize the ExportPdf class and override the exportHeaderAndFooter()
method.
-
- User
- Posts: 565
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.
-
- User
- Posts: 565
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
-
- User
- Posts: 565
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?
-
- User
- Posts: 9419
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.<h2>
will not cause page breaks, you should remove your style attributes.- 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"; }
-
- User
- Posts: 565
With your solution the rendered PDF results are as follows:
- 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
- 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
-
- User
- Posts: 9419
- 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.
<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.- You must not remove the
<table>
open tag, it will make the HTML malformed and dompdf might not parse the HTML correctly.
-
- User
- Posts: 565
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 ?