I am working on implementing a report generation solution using TCPDF. Some of my reports are small (2-3 pages), but the user has the opportunity to select several reports at once and request all of them.
I am currently creating one PDF file containing all reports, each report starts on a new page and uses page grouping so that pagination is restarted for each report. When it works, it works fine, but after I select too many reports, the code is reset and I get an empty PDF file.
UPDATE: I should have mentioned that creating a separate PDF request is a requirement from the client. They want a PDF summary to easily switch between reports within the same PDF when they have selected many reports.
My questions:
What is the most efficient way to create this PDF file without ending with an empty PDF file? I cannot find if there is a size limit that TCPDF can handle.
Should I use ob_start () in PHP or create a large string as I am fine?
My reports were originally HTML, so I am posting this TCPDF. However, would TCPDF performance be better if I used other methods for outputting information (e.g. Cell, MultiCell, etc.)?
Here is a snippet of my code that outputs a PDF. The $ pdf object is configured according to the corresponding TCPDF examples included in the library:
foreach ($students_info as $student_info) { $info = $student_info->fetch_object(); // get query result object // put in the student information $pdf->set_student_info($info->lastName, $info->firstName, $info->rank, $info->idNum); $pdf->startPageGroup(); // start a page group to handle paging for multiple students $pdf->AddPage(); // add a page $html = "<style>"; $html .= file_get_contents(/*some style sheet*/); $html .= file_get_contents(/*some other style sheet*/); $html .= "</style>"; $html .= start_report_div($i); $html .= '<table class="report_table">'. '<tbody>'. '<tr><td>'; $html .= display_report_title($report); $html .= display_student_info($db, $info); $html .= display_academic_comments_body($db, $info->studentID, $info->sessionID); $html .= display_signature_block($report); $html .= '</td></tr>'. '</tbody>'. '</table>'; $html .= end_report_div(); $pdf->writeHTML($html, // the content true, // put a newline after text false, // paint background, false = transparent true, // reset last cell height false, // add left padding '' // align ); $html = ''; // reset for next student $pdf->lastPage(); // pointer to last page in case we are doing more than one student }
source share