{"record":{"id":"ae9d8df93f69933b","repo":"gchq/CyberChef","slug":"input-does-not-appear-to-be-a-pdf-file","errorCode":null,"errorMessage":"Input does not appear to be a PDF file.","messagePattern":"Input does not appear to be a PDF file\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/RenderPDF.mjs","lineNumber":77,"sourceCode":"        // Convert input to raw bytes\n        switch (inputFormat) {\n            case \"Base64\":\n                input = fromBase64(input, undefined, \"byteArray\");\n                break;\n            case \"Raw\":\n            default:\n                input = Utils.strToByteArray(input);\n                break;\n        }\n\n        // Check PDF signature\n        if (\n            input[0] !== 0x25 || // %\n            input[1] !== 0x50 || // P\n            input[2] !== 0x44 || // D\n            input[3] !== 0x46    // F\n        ) {\n            throw new OperationError(\"Input does not appear to be a PDF file.\");\n        }\n\n        return input;\n    }\n\n    /**\n     * Displays the PDF using HTML for web apps.\n     *\n     * @param {byteArray} data\n     * @returns {html}\n     */\n    async present(data) {\n        if (!data.length) return \"\";\n\n        const base64 = toBase64(data);\n        const dataURI = \"data:application/pdf;base64,\" + base64;\n\n        return `<iframe src=\"${dataURI}\" style=\"width:100%;height:100%;border:1px solid #ccc;\"></iframe>`;","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/RenderPDF.mjs#L59-L95","documentation":"Thrown by RenderPDF.run when the first four bytes of the input are not the PDF signature '%PDF' (0x25 0x50 0x44 0x46). CyberChef does not deeply parse the file; it only checks the magic bytes before passing data to the renderer.","triggerScenarios":"Input that is not a PDF; a PDF whose header is preceded by leading whitespace/BOM bytes; Base64 input decoded with the wrong format option; truncated file missing the header.","commonSituations":"Feeding a Word/image/HTML file; pasting Base64 without setting the format to Base64; files with a leading BOM or garbage before %PDF; corrupted downloads.","solutions":["Confirm the file begins with bytes 25 50 44 46 ('%PDF').","Set the input format to 'Base64' if the data is still encoded.","Strip leading whitespace/BOM so %PDF is at offset 0.","Re-download a complete, uncorrupted PDF."],"exampleFix":"// before\n//   input: base64 text 'JVBERi0...' with format Raw -> first byte 'J' != 0x25\n// after\n//   input format: Base64  (decodes to %PDF...)","handlingStrategy":"validation","validationCode":"if (input[0]!==0x25||input[1]!==0x50||input[2]!==0x44||input[3]!==0x46) throw new Error('Not a PDF (missing %PDF header)');","typeGuard":"const isPdf = b => b.length>=4 && b[0]===0x25 && b[1]===0x50 && b[2]===0x44 && b[3]===0x46;","tryCatchPattern":"try { renderPdf(input); } catch (e) { if (/PDF file/.test(e.message)) decodeOrRedownload(); else throw e; }","preventionTips":["Set input format to Base64 for encoded PDFs.","Strip leading BOM/whitespace so %PDF is at offset 0.","Verify the file is actually a PDF."],"tags":["pdf","render","validation","magic-bytes"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}