{"record":{"id":"8e7b96234264f002","repo":"go-gitea/gitea","slug":"unable-to-render-the-pdf-file","errorCode":null,"errorMessage":"Unable to render the PDF file","messagePattern":"Unable to render the PDF file","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"web_src/js/render/plugins/inplace-pdf-viewer.ts","lineNumber":15,"sourceCode":"import type {InplaceRenderPlugin} from '../plugin.ts';\n\nexport function newInplacePluginPdfViewer(): InplaceRenderPlugin {\n  return {\n    name: 'pdf-viewer',\n\n    canHandle: (filename: string, _mimeType: string): boolean => filename.toLowerCase().endsWith('.pdf'),\n\n    async render(container: HTMLElement, fileUrl: string): Promise<void> {\n      const PDFObject = await import('pdfobject');\n      // TODO: the PDFObject library does not support dynamic height adjustment,\n      // TODO: it seems that this render must be an inplace render, because the URL must be accessible from the current context\n      container.style.height = `${window.innerHeight - 100}px`;\n      if (!PDFObject.default.embed(fileUrl, container)) {\n        throw new Error('Unable to render the PDF file');\n      }\n    },\n  };\n}\n","sourceCodeStart":1,"sourceCodeEnd":20,"githubUrl":"https://github.com/go-gitea/gitea/blob/43ace7cc8ad5fa20027b1ca5b3ab5f1134972ed5/web_src/js/render/plugins/inplace-pdf-viewer.ts#L1-L20","documentation":"Thrown by Gitea's in-place PDF render plugin when viewing a .pdf blob in the repository file viewer. It dynamically imports the pdfobject library and calls PDFObject.default.embed(fileUrl, container); pdfobject returns false (rather than throwing) when it detects the browser cannot display PDFs inline, and the plugin converts that false into this error.","triggerScenarios":"PDFObject.embed returns false: the browser lacks a built-in PDF viewer (or has it disabled, e.g., pdfjs.disabled in Firefox), the container element is hidden/zero-sized at embed time, or the browser refuses inline embedding for the blob/file URL (strict CSP framing rules, downloaded-marked content).","commonSituations":"Browsers or enterprise policies that disable the embedded PDF viewer; mobile browsers with no inline PDF support; strict Content-Security-Policy on a custom Gitea deployment blocking the object/embed pdfobject creates; very old browsers without PDF plugin support.","solutions":["Open the 'Raw' / 'Download' link for the PDF instead of the in-place viewer — the file itself is fine, only inline rendering failed","Enable the browser's native PDF viewer (Firefox: about:preferences > Applications > pdfjs enabled; check group policy on managed browsers)","Adjust CSP on the Gitea deployment so object/embed for the PDF blob URL is allowed","If this is a custom build, verify the pdfobject dependency is present and the container has non-zero height before render"],"exampleFix":"// before\nif (!PDFObject.default.embed(fileUrl, container)) {\n  throw new Error('Unable to render the PDF file');\n}\n\n// after (fall back to a plain download link instead of erroring)\nif (!PDFObject.default.embed(fileUrl, container)) {\n  container.textContent = '';\n  const a = document.createElement('a');\n  a.href = fileUrl;\n  a.textContent = 'Open PDF in a new tab';\n  a.target = '_blank';\n  a.rel = 'noopener';\n  container.append(a);\n  return;\n}","handlingStrategy":"fallback","validationCode":"// Best-effort capability probe before rendering\nconst canRenderPdfInline = (): boolean =>\n  typeof navigator !== 'undefined' && navigator.pdfViewerEnabled !== false;","typeGuard":"const supportsInlinePdf = (): boolean =>\n  (navigator as Navigator & {pdfViewerEnabled?: boolean}).pdfViewerEnabled === true;","tryCatchPattern":"try {\n  await plugin.render(container, fileUrl);\n} catch (e) {\n  // fall back to a raw link; the file itself is downloadable regardless of inline support\n  container.replaceChildren(createAnchor(fileUrl));\n}","preventionTips":["Always pair PDFObject.embed's boolean result with a download-link fallback, since it returns false rather than throwing","Give the container explicit non-zero height before calling embed","On managed deployments, check group policies that disable the browser PDF viewer, and CSP that blocks object/embed for blob URLs"],"tags":["pdf","browser-support","rendering","csp","gitea-frontend"],"backgroundTag":null,"analyzedSha":"43ace7cc8ad5fa20027b1ca5b3ab5f1134972ed5","analyzedAt":"2026-08-15T09:36:00.065Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}