env = env # noqa import re, subprocess, tempfile, os rep = env.ref('fusion_plating_reports.action_report_fp_bol_landscape') dlv = env['fusion.plating.delivery'].search([], order='id desc', limit=1) html, _ = rep.with_context(force_report_rendering=True )._render_qweb_html(rep.report_name, [dlv.id]) out = html.decode() if isinstance(html, bytes) else str(html) # Strip styles/scripts and just count visible text length per major block def find_block(label, txt): i = txt.find(label) if i < 0: return None return txt[i:i+200] print('=== blocks present ===') for label in ['BILL OF LADING','BoL #','SHIPPER','SHIP DATE','CARGO DESCRIPTION', 'CoC','PACKING LIST','is to certify','Shipper (Signature']: print(f' {label!r}:', 'found' if label in out else 'MISSING') # Render PDF, save, and count pages pdf, _ = rep.with_context(force_report_rendering=True )._render_qweb_pdf(rep.report_name, [dlv.id]) path = '/tmp/bol_landscape.pdf' with open(path, 'wb') as f: f.write(pdf) print(f'\nPDF: {len(pdf)/1024:.1f} KB at {path}') n = len(re.findall(rb'/Type\s*/Page[^s]', pdf)) print(f'pages: {n}')