Skip to main content
Version: 9.x

Convert office documents to PDF

Converts Word, Excel, PowerPoint and OpenDocument files, and over a hundred other formats, to PDF with LibreOffice.

POST/forms/libreoffice/convert
filesfile[]required

The documents. LibreOffice converts the formats listed below, and skips the others.

stagesjson

Stages to run on the PDF, in order, such as [{"op":"merge"}]. Upload the files they name under files.

archivesfile[]

ZIP files Gotenberg unpacks: each entry counts as a file uploaded under files.

URLs Gotenberg downloads first, as if you had uploaded the files. Each entry takes a url, and optionally extraHttpHeaders.

passwordstring

Opens a password-protected document.

paperSizestring

A3, A4, A5, B4, B5, Letter, Legal or Tabloid, in any case, for every page. Without it, each document keeps its own page size.

Overrides the width paperSize sets. Without paperSize, set paperHeight too. A length is a number in inches, or a number with a unit: 210mm, 21cm, 595pt, 794px, 50pc.

Overrides the height paperSize sets. Without paperSize, set paperWidth too.

landscapeboolean

Turns the pages sideways.

Default: false

Pages to export, in LibreOffice's syntax: 1-4, 2, 1,3,5-7. The select stage picks pages after the conversion, and takes odd, even and last too.

singlePageboolean

Puts each sheet of a spreadsheet on one page, hidden sheets included, regardless of its paper size and print ranges.

Default: false

Drops the blank pages a text document inserts on its own.

Default: false

Updates the tables of contents and the other indexes before the export.

Default: true

Exports form fields as fields a reader can fill. false prints their values only.

Default: true

Lets several form fields share a name.

Default: false

Exports the document's bookmarks, built from its headings.

Default: true

Also exports the document's own bookmarks, such as Writer bookmarks, as named destinations, which links can target. Headings that build the outline are not bookmarks.

Default: false

Shows the placeholder fields' markings. The exported placeholders do nothing.

Default: false

Exports comments as PDF annotations.

Default: false

Prints comments in the page margin.

Default: false

Adds a presentation's notes pages.

Default: false

Exports the notes pages only, with exportNotesPages.

Default: false

Includes the slides hidden from the slide show.

Default: false

Exports a presentation's slide transitions.

Default: true

Points links to .odt, .ods, .odp and .odg files at .pdf files of the same name.

Default: false

Exports file:// links relative to the document.

Default: false

Embeds the document in the PDF, for archiving. LibreOffice re-saves it as ODF and names it Original.odt, whatever you uploaded.

Default: false

The JPEG quality of the images, from 1 to 100.

Default: 90

Compresses images losslessly, instead of as JPEG. Images the document stores as JPEG keep their data. Only images LibreOffice re-encodes, such as with nativeReduceImageResolution, become lossless.

Default: false

Downsamples images to nativeMaxImageResolution.

Default: false

The resolution nativeReduceImageResolution downsamples to, in DPI: 75, 150, 300, 600 or 1200.

Default: 300

Draws this text on every page. Set it or nativeTiledWatermarkText, not both.

The text color, as #rrggbb.

Default: #7ffe7f

The font size, in points. Without it, the text spans the page.

The angle, in degrees, counter-clockwise: 0 draws the text across the page. Without it, the text runs down a portrait page and across a landscape one.

The font name.

Default: Helvetica

Repeats this text across every page, in a grid. Set it or nativeWatermarkText, not both: the size, color, font and rotation fields apply to nativeWatermarkText only.

Exports PDF/A: PDF/A-1b, PDF/A-2b, PDF/A-3b or PDF/A-4. The remediate stage reaches the other PDF/A levels.

Exports PDF/UA: PDF/UA-1. With nativePdfa, the document needs a title, and PDF/A-4 answers 400: pair them in remediate instead.

Writes a tagged PDF, whose structure screen readers follow, without declaring PDF/UA.

Default: false

The side panel a viewer opens: default, outline or thumbnails.

Default: default

The page a viewer opens at.

Default: 1

How a viewer fits the page: default, fitWindow, fitWidth, fitVisible or zoom.

Default: default

zoominteger

The zoom, in percent, with magnification set to zoom.

Default: 100

How a viewer lays the pages out: default, singlePage, oneColumn or twoColumnRight, two columns with the first page on the right. LibreOffice can't put it on the left.

Default: default

How many bookmark levels a viewer expands, from 1 to 10. -1 expands them all.

Default: -1

Sizes the viewer's window to the first page shown.

Default: false

Centers the viewer's window on the screen.

Default: false

Opens the viewer full screen.

Default: false

Shows the document title, not the file name, in the viewer's title bar. Gotenberg writes it only when the document has a title. A PDF/UA output always shows the title.

Default: true

Hides the viewer's menu bar.

Default: false

Hides the viewer's toolbar.

Default: false

Hides the viewer's window controls.

Default: false

One PDF per document, named after it: report.docx gives report.docx.pdf. Several documents answer a ZIP, unless a merge stage joins them.

The route also takes the headers. An error answers a status and a message: see Errors.

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
Response
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