I want to print a report generated with Symfony and twig worth over 5000 pages. I tried printing with one print command in firefox and chrome but the browser crashes or times out while loading the document.
However, there is another option where I can iterate over an object and for each iteration reload an iframe with new page content and print. How can I do this with one print command without calling the print dialog in each iteration?
This is my scenario:
Option 1:
Symfony Controller:
public function printReports(Request $request, $from, $to) {
// $bills = ....;
$all_bills = $bills->loadAll(['from' => $from, 'to' => $to]);
return $this->render('reports/print.all_bills.html.twig', [
'bill_ids' => $all_bills //$all_bills can result in over 50000 pages
]);
}
Twig Template:
{% extends "base.html.twig" %}
{% block body %}
{% for bill in all_bills %}
{% include 'pages/bills.front.html.twig' with { info: bill.info } %}
{% include 'pages/bills.back.html.twig' with { content: bill.content } %}
{% endfor %}
{% endblock %}
Option 2:
Symfony Controller:
public function printReport(Request $request, $id) {
// $bill = ....;
$bill = $bill->loadById(['id' => $id]);
return $this->render('reports/print.bill.html.twig', [
'bill_id' => $bill //$bill results in 2 pages
]);
}
Twig Template:
{% extends "base.html.twig" %}
{% block body %}
{% include 'pages/bills.front.html.twig' %}
{% include 'pages/bills.back.html.twig' %}
{% endblock %}
jQuery:
let ids = []; // may contain up to 3000 ids which prints 2 pages each
$.each(ids, function (i, id) {
// url to reload the iframe: 'print/bill/{id}'
// reload the frame with each id and print the content of the frame
// on load
});
My Option 1 results in a big file which times out or crashes the browser and my Option 2 will result in multiple iterations over the IDs in javascript/jquery while reloading an iframe.
Summary: