Background PDF print
Menu: all PDF print actions (Sales, Purchase, Receipt, Quote, Report → PDF, and similar)
PDF documents are generated in a background worker instead of inside the web server request. Staff still click Print or PDF as before; a short wait spinner appears, then the PDF opens in a new tab.
Heavy PDF rendering (PagedJs / Node) used to hold Apache workers and could slow the whole admin for other users. Background print keeps the browser responsive and frees web workers for normal page loads.
What staff see
- Click Print Mini, Print Large, PDF, or any print action that exports PDF.
- A progress indicator appears while the document is prepared.
- When ready, the PDF opens in a new browser tab (same as before).
- If generation fails, an alert explains the error—try Print again.
There is no change to print layouts, report names, or which buttons appear on each screen.
Special features
- Same UX — print buttons and PDF content are unchanged; only the generation path moved off Apache.
- All PDF reports — sales mini/large, purchase mini/large, receipt, quote, sales return, and Report module PDF exports use the same queue when enabled on the server.
- Fresh data on every print — each Print click creates a new job that reads the current database state (important after confirm payment or invoice changes).
- XLSX unchanged — Excel exports from reports still download directly (not queued).
- Audit log — each print job is recorded in the
report_pdf_jobtable (who, which report, when, success/fail).
Workflows
Print before and after confirm (sales / purchase)
Sales and purchase documents are often printed before order confirm, then again after confirm when invoice codes and status change.
Steps
- Save the sale or purchase and print (ORDER / mini) if needed — PDF reflects data at that moment.
- Confirm payment or confirm the document when your process requires it.
- Print again — the new PDF is built from live data, not a cached file from the first print.
- Compare ORDER#, status, invoice code, and totals on the second PDF against the confirmed record.
Report module PDF export
Steps
- Open Report from the top menu.
- Choose a report, click Show Report, set filters.
- Click PDF — a short “Generating PDF…” page may appear, then the file opens.
- Re-run with new filters anytime; each export is a new generation.
Validation rules
| Rule | Detail |
|---|---|
| Print type reports | Require a record_id (open sale, purchase, receipt, etc.) |
| Re-print after edits | Always click Print again; do not rely on an old browser tab |
| Confirmed vs draft | PDF always matches DB at generation time — confirm before final customer copy if your policy requires it |
| Failed job | Check alert message; retry Print; ask admin if failures repeat |
| XLSX | Not affected by background PDF queue |
Operations (server)
Summary for administrators deploying or troubleshooting BAWAS.
Architecture
Browser → enqueue job (report_pdf_job) → CLI worker → PagedJs PDF → temp file
← poll status ←────────────────────────────────────────────┘
Browser → download PDF → delete temp file (regenerate if file missing on retry)
| Component | Purpose |
|---|---|
report_pdf_job | Job queue and audit log (pending → processing → ready / failed) |
bin/report-pdf-worker.php | CLI entry point; runs outside Apache |
media/temp/pdf-jobs/ | Short-lived PDF files (not deployed by rsync; created on server) |
cp-log/report-pdf-worker.log | Worker stdout/stderr |
Configuration (admin/lib/config.php)
| Setting | Role |
|---|---|
cp.report.asyncPdfEnabled | Master switch (true on UAT/production) |
cp.report.asyncPdfExclude | Optional list of report names to keep synchronous |
cp.report.asyncPdfPhpBin | PHP binary for worker (e.g. /opt/remi/php81/root/bin/php) |
cp.report.asyncPdfHttpHost | Host passed to worker bootstrap |
File lifecycle
- PDF is deleted after it is successfully served to the browser (disk cleanup).
- If the file is gone but the job is still
ready, the next open regenerates from current DB params (samerecord_id). - Database rows in
report_pdf_jobare kept as a log; only files are removed.
Deploy checklist
- Run Doctrine migration for
report_pdf_job. - CI post-deploy:
mkdir -p media/temp/pdf-jobs,chmod +x bin/report-pdf-worker.php. - Gulp rebuilds
admin/js/app.min.json deploy (async polling lives ingeneral-util-service.js). - Verify Node / PagedJs paths in
cp.report.pdfLibPathfor the worker environment.
Troubleshooting
| Symptom | Check |
|---|---|
| Spinner never finishes | report_pdf_job row status; cp-log/report-pdf-worker.log |
| “Could not create PDF job directory” | media/temp/pdf-jobs exists and is writable |
| Wrong data on PDF | Re-print after confirm; do not reuse an old download URL from history |
| PHP warnings in log | Worker sets REQUEST_URI / QUERY_STRING for CLI bootstrap |
Related pages
- Invoice & order print — sales ORDER PDF layout and fields
- Print align unit — purchase print quantity/unit columns
- Reports — analytics hub and PDF export button