Repair malformed PDF files by testing trimmed byte ranges, rebuilding valid output, and exporting the best recovered document.