Convert office documents to PDF
Converts Word, Excel, PowerPoint and OpenDocument files, and over a hundred other formats, to PDF with LibreOffice.
Convert a document
curl \
--request POST http://localhost:3000/forms/libreoffice/convert \
--form files=@report.docx \
-o report.pdf
The PDF takes the document's name, report.docx.pdf, unless the Gotenberg-Output-Filename header names it. Formats lists every format.
Convert several
Upload several documents to get one PDF each, in a ZIP:
curl \
--request POST http://localhost:3000/forms/libreoffice/convert \
--form files=@report.docx \
--form files=@annex.docx \
-o documents.zip
Merge them
Add a merge stage for one PDF instead:
curl \
--request POST http://localhost:3000/forms/libreoffice/convert \
--form files=@report.docx \
--form files=@annex.docx \
--form 'stages=[
{ "op": "merge" }
]' \
-o documents.pdf
The documents merge in the alphanumeric order of their names, so annex.docx comes first. Name them 1-report.docx and 2-annex.docx to pick the order.
Open a protected document
curl \
--request POST http://localhost:3000/forms/libreoffice/convert \
--form files=@protected.docx \
--form password=secret \
-o report.pdf
Without the password, or with a wrong one, Gotenberg answers 400 and says which. A legacy .doc, .xls or .ppt hides its encryption, so without the password Gotenberg only says LibreOffice couldn't read it.
Set the page size
LibreOffice takes the paperSize, paperWidth, paperHeight and landscape fields of the Chromium routes:
curl \
--request POST http://localhost:3000/forms/libreoffice/convert \
--form files=@report.docx \
--form paperSize=A4 \
-o report.pdf
Without them, each document keeps the page size it defines. Without paperSize, set both paperWidth and paperHeight, or neither. The margins, headers and footers come from the document.
Fit a spreadsheet on one page
A spreadsheet spreads over as many pages as its print settings ask. sales.csv gives three. singlePage puts each sheet on one page:
curl \
--request POST http://localhost:3000/forms/libreoffice/convert \
--form files=@sales.csv \
--form singlePage=true \
-o sales.pdf
Make it archival
LibreOffice writes PDF/A itself with nativePdfa:
curl \
--request POST http://localhost:3000/forms/libreoffice/convert \
--form files=@report.docx \
--form nativePdfa=PDF/A-2b \
-o report.pdf
The remediate stage does the same after the conversion, on any route and for every PDF/A level, and reports what it couldn't fix:
curl \
--request POST http://localhost:3000/forms/libreoffice/convert \
--form files=@report.docx \
--form 'stages=[
{ "op": "remediate", "profile": "PDF/A-2b" }
]' \
-o report.pdf
HTTP/1.1 200 OK
Content-Type: application/pdf
Gotenberg-Remediation-Residual: 0
Gotenberg-Remediation-Rolled-Back: 0
Both PDFs pass Gotenberg's own PDF/A-2b validation. Nothing checks nativePdfa's output, though, and a stage after it, such as stamp-text, can break its conformance. remediate comes after the other stages and reports what's left.
Make it archival and accessible
nativePdfa and nativePdfua together make a PDF/A that is also PDF/UA-1. PDF/UA needs a title, which report.docx lacks, so a set-metadata stage gives it one:
curl \
--request POST http://localhost:3000/forms/libreoffice/convert \
--form files=@report.docx \
--form nativePdfa=PDF/A-2b \
--form nativePdfua=PDF/UA-1 \
--form 'stages=[
{ "op": "set-metadata", "title": "Annual report" }
]' \
-o report.pdf
The PDF passes Gotenberg's validation against both. With nativePdfa: PDF/A-4, LibreOffice claims PDF/UA-2 without meeting it, so Gotenberg answers 400: pair the profiles in remediate instead, which checks the result too. PDF/UA also asks for alt text on images: a document with an image that lacks it makes a PDF that fails PDF/UA validation.
Fill forms
LibreOffice exports a document's form fields as fields a reader can fill, unless exportFormFields is false. Add the set-form stage to fill them in the same request.
Native fields or stages
A field whose name starts with native asks LibreOffice itself. A stage does the same job on the PDF afterwards, the same way for every route: nativeWatermarkText has stamp-text, nativePdfa has remediate.
Add stages
Stages run on the PDFs LibreOffice makes, in order, before Gotenberg answers. A stamp, for example:
curl \
--request POST http://localhost:3000/forms/libreoffice/convert \
--form files=@report.docx \
--form 'stages=[
{ "op": "stamp-text", "text": "DRAFT", "x": 200, "y": 400, "fontSize": 48, "opacity": 0.3, "rotation": 45 }
]' \
-o report.pdf
Or the document's metadata:
curl \
--request POST http://localhost:3000/forms/libreoffice/convert \
--form files=@report.docx \
--form 'stages=[
{ "op": "set-metadata", "title": "Annual report", "author": "Finance" }
]' \
-o report.pdf
Encryption comes last: only optimize and render may follow it.
curl \
--request POST http://localhost:3000/forms/libreoffice/convert \
--form files=@report.docx \
--form 'stages=[
{ "op": "encrypt", "userPassword": "secret" }
]' \
-o report.pdf
A PDF/A or Factur-X can't be encrypted, and an encrypted PDF can't be signed: the order rules answer 400 first.
render previews the document. This request answers the PDF and a thumbnail of its first page:
curl \
--request POST http://localhost:3000/forms/libreoffice/convert \
--form files=@report.docx \
--form 'stages=[
{ "op": "render", "pages": "1", "dpi": 72 }
]' \
-o report.zip
The ZIP holds report.docx.pdf and report.docx_1.png. Stages lists every stage.
Formats
LibreOffice converts the files with these extensions, and skips the others. A request with none answers 400.
.123 .602 .abw .bib .bmp .cdr .cgm .cmx .csv .cwk .dbf .dif .doc .docm .docx .dot .dotm .dotx .dxf .emf .eps .fodg .fodp .fods .fodt .fopd .gif .htm .html .hwp .jpeg .jpg .key .ltx .lwp .mcw .met .mml .mw .numbers .odd .odg .odm .odp .ods .odt .otg .oth .otp .ots .ott .pages .pbm .pcd .pct .pcx .pdb .pdf .pgm .png .pot .potm .potx .ppm .pps .ppsm .ppsx .ppt .pptm .pptx .psd .psw .pub .pwp .pxl .ras .rtf .sda .sdc .sdd .sdp .sdw .sgl .slk .smf .stc .std .sti .stw .svg .svm .swf .sxc .sxd .sxg .sxi .sxm .sxw .tga .tif .tiff .txt .uof .uop .uos .uot .vdx .vor .vsd .vsdm .vsdx .wb2 .wk1 .wks .wmf .wpd .wpg .wps .xbm .xhtml .xls .xlsb .xlsm .xlsx .xlt .xltm .xltx .xlw .xml .xpm .zabw