Auto-convert PDF (.docx → .pdf)
Auto-convert PDF (.docx → .pdf)
Phần tiêu đề “Auto-convert PDF (.docx → .pdf)”Sau khi render .docx từ template, convert sang PDF để:
- Gửi KH (PDF không sửa được, giữ format perfect)
- Ký điện tử (roadmap Q4 2026)
- In / archive lâu dài
Parkone dùng LibreOffice CLI (open source, free) để convert.
Setup 1 lần (Admin)
Phần tiêu đề “Setup 1 lần (Admin)”1. Install LibreOffice trong container Odoo
Phần tiêu đề “1. Install LibreOffice trong container Odoo”odoo:19 base image không có LibreOffice. Extend Dockerfile:
FROM odoo:19USER rootRUN apt-get update && apt-get install -y --no-install-recommends \ libreoffice \ fonts-liberation \ fonts-open-sans \ fonts-noto-cjk \ && rm -rf /var/lib/apt/lists/*USER odooAdd vào deploy/Dockerfile.odoo cùng với docxtpl:
FROM odoo:19USER rootRUN pip install --break-system-packages --no-cache-dir docxtpl && \ apt-get update && apt-get install -y --no-install-recommends \ libreoffice \ fonts-liberation fonts-open-sans fonts-noto-cjk && \ rm -rf /var/lib/apt/lists/*USER odoo2. Rebuild image
Phần tiêu đề “2. Rebuild image”docker compose --env-file deploy/managed.env \ -f deploy/docker-compose.managed.yml build odoodocker compose --env-file deploy/managed.env \ -f deploy/docker-compose.managed.yml up -d odoo3. Verify
Phần tiêu đề “3. Verify”docker exec parkone-odoo which libreofficedocker exec parkone-odoo libreoffice --headless --version# → LibreOffice 7.x.xConvert flow
Phần tiêu đề “Convert flow”1. Sau khi render .docx (từ wizard)
Phần tiêu đề “1. Sau khi render .docx (từ wizard)”File .docx attached vào record.
2. Click ”📑 Convert to PDF”
Phần tiêu đề “2. Click ”📑 Convert to PDF””Nút bên cạnh attachment. Wizard mini:
- Filename: default replace
.docx→.pdf - Quality: Standard / High (Standard = balance size/quality)
3. Backend chạy
Phần tiêu đề “3. Backend chạy”libreoffice --headless \ --convert-to pdf:writer_pdf_Export \ --outdir /tmp/pdf-convert-<uuid> \ /tmp/pdf-convert-<uuid>/input.docxMất 2-5 giây cho doc 10 trang. 20+ trang có thể 10-15s.
4. PDF attach vào record
Phần tiêu đề “4. PDF attach vào record”- Đọc file PDF từ
/tmp/pdf-convert-<uuid>/output.pdf - Save vào
ir.attachmentlink với record - Original
.docxgiữ nguyên (không xoá)
Record giờ có 2 attachments: .docx + .pdf.
Quality options
Phần tiêu đề “Quality options”--convert-to pdf- Font embedded
- Images JPEG 75% quality
- File size ~200-500 KB per doc 10 trang
- Print quality OK
- Screen readable
Default. Dùng cho HĐ / Báo giá thông thường.
--convert-to 'pdf:writer_pdf_Export:{"UseLosslessCompression":true,"Quality":90}'- Font embedded
- Images 90% quality
- File size 500 KB - 2 MB
- In quality tốt
Dùng cho HĐ VIP hoặc gửi in ấn.
--convert-to 'pdf:writer_pdf_Export:{"SelectPdfVersion":1}'- PDF/A-1b compliant
- Font fully embedded
- Không JS / external resource
- File size lớn hơn Standard 20-30%
- Legal archive OK
Dùng cho HĐ cần lưu trữ dài hạn / theo tiêu chuẩn ISO.
Watermark
Phần tiêu đề “Watermark”Add watermark “DRAFT” hoặc “CONFIDENTIAL”:
- Trong template
.docxoriginal — Insert → Watermark trong Word - Save template
- Render → PDF sẽ có watermark
Watermark áp cho toàn document, không per-page selective.
Password protect PDF
Phần tiêu đề “Password protect PDF”- Wizard convert → tick “Password protect”
- Nhập password (min 6 chars)
- Convert command:
--convert-to 'pdf:writer_pdf_Export:{"Password":"<pw>"}'
- PDF output cần password để mở
Gửi password cho KH qua kênh khác (SMS / Zalo) — không email cùng file.
Digital signature (roadmap)
Phần tiêu đề “Digital signature (roadmap)”Q4 2026: tích hợp VnEID / DocuSign để ký PDF điện tử tự động.
Hiện tại Đại phải:
- Download PDF
- Ký giấy → scan
- Upload lại
Hoặc dùng external service (DocuSign) — attach signed PDF vào record.
Batch convert
Phần tiêu đề “Batch convert”Convert nhiều .docx cùng lúc:
- Filter list attachments trên record → tick nhiều .docx
- Menu Action → “Convert all to PDF”
- Backend loop convert từng file
- Output: N PDFs attached
Mất N × 3 seconds. Async — Đại có thể làm việc khác trong lúc chờ.
PDF preview inline
Phần tiêu đề “PDF preview inline”Sau khi convert, click PDF attachment → mở inline preview trong browser (Odoo built-in PDF viewer):
- Zoom / pan
- Page navigation
- Download
Không cần external app.
Font issues
Phần tiêu đề “Font issues”Nếu template dùng font Việt (Times New Roman, Arial, Be Vietnam Pro):
- Verify font install trong container:
docker exec parkone-odoo fc-list | grep -i "Vietnam" - Nếu miss → install custom font (xem OnlyOffice → Font support)
Font missing → PDF render fallback → dấu hỏi chấm ♀ thay vì tiếng Việt.
Convert speed benchmark
Phần tiêu đề “Convert speed benchmark”| Doc size | Convert time |
|---|---|
| 5 pages, text-only | 1-2s |
| 10 pages, few images | 3-5s |
| 20 pages, many images | 8-15s |
| 50 pages, tables + images | 20-40s |
Nếu > 40s → xem xét async job (Odoo cron) thay vì on-click.
Async convert (advanced)
Phần tiêu đề “Async convert (advanced)”Cho doc lớn (50+ trang):
- Wizard convert với option “Background job”
- Odoo tạo
queue.job(needs queue_job module) - Return immediately, notify user “Đang convert, sẽ ping khi xong”
- Worker convert async
- Khi xong → notification pop-up + attach PDF
Cần Admin install queue_job module + config worker.
Convert xong PDF trắng / lỗi format
Phần tiêu đề “Convert xong PDF trắng / lỗi format”- Verify
.docxmở được trong Word bình thường - Verify font install
- Test manual:
docker exec parkone-odoo libreoffice --headless --convert-to pdf /tmp/test.docx
PDF quá lớn (>10 MB) — email bounce
Phần tiêu đề “PDF quá lớn (>10 MB) — email bounce”- Convert với Standard (default), không High
- Compress ảnh trong .docx trước convert
- Nếu vẫn lớn — Google Drive link thay attach
Muốn PDF có bookmark theo heading
Phần tiêu đề “Muốn PDF có bookmark theo heading”- Word template có Heading 1/2/3 styles
- Convert command auto-generate bookmarks (default LibreOffice behavior)
Convert bị timeout
Phần tiêu đề “Convert bị timeout”- Container timeout default 60s
- Increase: env
LIBREOFFICE_CONVERT_TIMEOUT=180 - Or async convert (xem trên)