Troubleshooting

PDF Issues

PDF invalid in Edge

Microsoft Edge can reject PDFs that are streamed directly from a POST request, showing an "invalid or corrupted file" error. This is a known Edge behaviour and does not mean the PDF itself is broken — the same file opened in Chrome or Adobe Acrobat will work fine.

Fix 1 — Add binary encoding header
In the payslip and badge download handler in class-mbs-admin.php, ensure this header is included:

header('Content-Transfer-Encoding: binary');

This tells Edge to treat the response as raw binary data rather than trying to interpret it.

Fix 2 — Save via temp file
Instead of streaming the PDF directly, write it to a temporary file in wp-content/uploads/mbs-temp/ and redirect to that URL. Edge handles a direct file URL reliably. The temp file is cleaned up automatically after one hour.

Workaround for users
Ask users to right-click the download link and choose Save link as, then open the saved file. Or simply use Chrome instead of Edge for payslip downloads.

Corrupt PDF output

If the PDF is corrupted for all browsers (not just Edge), stray output before the PDF headers is the most likely cause. Any PHP warning, notice or even a blank line before the <?php tag in any included file will corrupt the binary stream.

  • Turn off WP_DEBUG_DISPLAY in wp-config.php — error output to screen will corrupt the PDF
  • Check that no included PHP file has a space or blank line before <?php or after the closing ?> tag
  • Add if (ob_get_length()) ob_clean(); immediately before sending PDF headers

Blank or empty PDF

If the PDF downloads but is blank:

  • Check that the employee has a photo — the badge PDF requires a photo. Without one, the badge area may render empty.
  • Check that the company logo URL in Settings points to a valid, publicly accessible image.
  • Check the PHP error log for TCPDF errors — font file missing or a GD library issue can cause TCPDF to produce a blank page.