Skip to content

[18.0][attachment_preview] Add Office format preview via LibreOffice conversion#603

Open
dnplkndll wants to merge 1 commit intoOCA:18.0from
ledoent:18.0-add-office-preview
Open

[18.0][attachment_preview] Add Office format preview via LibreOffice conversion#603
dnplkndll wants to merge 1 commit intoOCA:18.0from
ledoent:18.0-add-office-preview

Conversation

@dnplkndll
Copy link
Copy Markdown

Summary

Extends attachment_preview to support DOCX, XLSX, PPTX, DOC, XLS, PPT, and ODG preview in addition to the existing PDF + ODF support.

How it works

  • New HTTP endpoint: GET /attachment_preview/office_to_pdf?model=&field=&id=&filename=
  • On request, converts the binary field content to PDF using LibreOffice headless (libreoffice --headless --convert-to pdf)
  • Returns the PDF to ViewerJS for in-browser rendering
  • Gracefully returns HTTP 503 if LibreOffice is not installed — no preview button appears for Office files on deployments without LibreOffice

Changes

File Change
controllers/main.py New LibreOffice conversion HTTP controller
static/src/js/utils.esm.js OFFICE_EXTENSIONS added to canPreview(); getUrl() routes Office extensions through conversion endpoint with ?type=pdf for ViewerJS
static/src/js/web_views/fields/binary_field.esm.js Passes filename to showPreview() so conversion endpoint receives correct extension

Requirements

  • LibreOffice must be installed in the Odoo environment for Office preview to function
  • No new Python dependencies (uses stdlib subprocess, tempfile)
  • Existing PDF + ODF preview unaffected

Test plan

  • Upload a .docx file to a record with a binary field → preview button (↗) appears
  • Click preview → ViewerJS opens with converted PDF content
  • Upload a .xlsx / .pptx → same behavior
  • On an Odoo instance without LibreOffice → preview button does not appear for Office files (503 response causes button to stay hidden)
  • Existing PDF preview unaffected
  • Existing ODS/ODT preview unaffected

🤖 Generated with Claude Code

…ffice

Extends attachment_preview to support DOCX, XLSX, PPTX, DOC, XLS, PPT,
and ODG in addition to the existing PDF + ODF format support.

New endpoint: GET /attachment_preview/office_to_pdf
  Accepts ?model=<model>&field=<field>&id=<id>&filename=<name>
  Converts the binary field content to PDF using LibreOffice headless,
  then streams the PDF to ViewerJS for in-browser rendering.
  Returns HTTP 503 gracefully if LibreOffice is not installed.

Changes:
- controllers/main.py: new HTTP controller with LibreOffice conversion
- utils.esm.js: OFFICE_EXTENSIONS added to canPreview(); getUrl() routes
  Office files to the conversion endpoint
- binary_field.esm.js: passes filename for correct extension detection
- tests: controller unit tests covering success, FileNotFoundError,
  TimeoutExpired, and non-zero exit code paths

Closes OCA#603
@dnplkndll dnplkndll force-pushed the 18.0-add-office-preview branch from 8702c2f to d9a4a06 Compare March 30, 2026 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant