Automating & delivering reports
PDF export
Turning a finished workbook into a PDF, on Windows or on a Linux server.
Start with the full guides
The long-form treatment of pdf export, with the reasoning the shorter pages assume.
Step-by-step how-tos
One task each, with code you can copy, run and adapt.
- How-toAdd Bookmarks and a Cover Page to an Excel PDF ExportFinish a multi-sheet Excel PDF export like a real report: read the sheet bookmarks LibreOffice already writes, prepend a cover page with a contents list built with reportlab, rebuild a nested bookmark tree with pypdf, number pages so the cover is not page 1, open the PDF with the bookmarks panel showing, and test the result.
- How-toAdd Headers, Footers and Page Numbers to an Excel PDFMake an exported PDF look like a document — set headers and footers with openpyxl, repeat the title row on every page, and control margins and page breaks before converting.
- How-toCheck a PDF Export for Cut-Off ColumnsCatch the PDF exports nobody wants to receive before they are sent: detect columns that spill onto extra pages, numbers printed as ### because a column is too narrow, and text shrunk below a readable size by fit-to-page, by reading the PDF back with pdfplumber, then fix the page setup with openpyxl and confirm the check passes.
- How-toConvert an Excel File to PDF with PythonConvert .xlsx to PDF in Python with LibreOffice headless and subprocess: set page layout via openpyxl, run soffice safely with a timeout, plus a Windows COM path.
- How-toConvert Excel to PDF on Linux with LibreOfficeHeadless LibreOffice converts a workbook to PDF with no Excel, licence or desktop session — with the profile, timeout and page-setup details that make it reliable in a container.
- How-toConvert Only Selected Sheets of a Workbook to PDFExport the summary without the raw data — build a trimmed copy of the workbook, or use LibreOffice's export filter, and control the order sheets appear in the PDF.
- How-toCreate a PDF Report from Excel Data with ReportLabTurn Excel data into a designed PDF report with ReportLab, without Excel or LibreOffice: read and summarise the workbook with pandas, lay out a title, summary text and a native vector chart, build a table with formatted numbers, wrapped text, zebra stripes, bold subtotals and a header row that repeats on every page, add a "page X of Y" footer, and check the result with pypdf.
- How-toExport an Excel Report to PDF/A for ArchivingExport Excel reports to PDF/A from Python with LibreOffice for long-term archiving: choose between PDF/A-1b, 2b and 3b, pass the export option on the command line, set the document title and author, check the result for the PDF/A identification, output intent and embedded fonts, and avoid the post-processing steps that silently break conformance.
- How-toFit an Excel Sheet to One Page Wide When Exporting to PDFStop wide Excel reports from spilling columns onto extra PDF pages — set fit-to-width with openpyxl, predict how small the text will get before converting, and when it gets too small, use landscape, narrower margins, hidden helper columns or a two-page-wide layout with repeated labels. Every layout measured in a LibreOffice PDF export.
- How-toMerge Several Excel PDF Exports into One FileCombine the PDFs exported from several Excel workbooks into one document with pypdf — a bookmark per report, page labels such as "North 2", a title and an open bookmarks panel — and know what merging loses: accessibility tags and continuous page numbers. When those matter, combine the workbooks first and convert once.
- How-toPassword-Protect a PDF Exported from ExcelEncrypt the PDF your Excel report becomes: AES-256 with pypdf after conversion, or encryption set directly in the LibreOffice export filter (and why it is weaker), the difference between open and permissions passwords, one password per recipient, verifying the file really is locked, and what PDF permissions can and cannot stop.
- How-toSign a PDF Report Digitally with PythonAdd a cryptographic signature to a PDF exported from an Excel report with pyHanko, so readers can prove who issued it and that nobody changed it afterwards: load a certificate from a PKCS#12 file, sign with a reason and location, add a visible signature box, validate the result in Python and with pdfsig, and see exactly what a one-byte change does to it.
- How-toTurn PDF Report Pages into ImagesRender the pages of a PDF exported from an Excel report as PNG or JPEG images with pypdfium2, which installs with pip and needs no Poppler: choose the resolution for screen, email or print, trim the white margins, make small thumbnails for a report index, and compare file sizes and formats — with pdftoppm as the command-line alternative.
- How-toFill PDF Forms from Excel Rows with PythonFill a fillable PDF form — an expense claim, an order form, a government template — once per spreadsheet row with pypdf: list the form's field names, map sheet columns to fields, format numbers and dates as text, tick checkboxes with the right state name, flatten the result so it cannot be edited, and verify every filled file.
- How-toGenerate One PDF per Excel RowTurn every row of a sheet into its own PDF — customer statements, certificates, remittance advices — either drawn directly with reportlab or by filling an Excel template per row and converting all of them in one LibreOffice call; with safe file names, a combined print file, and a check that each PDF contains the right customer and amount.
- How-toGenerate Customer Account Statements from a LedgerProduce a statement workbook for every customer from one receivables ledger with pandas and XlsxWriter: opening balance brought forward, the period transactions with a running balance, closing balance, an ageing summary built by allocating payments to the oldest invoices, a statement layout with formats, and reconciliation checks against the ledger.
- How-toGenerate Word Documents from Excel Rows with PythonDo a mail merge in Python: one Word letter, statement or certificate per row of a spreadsheet, filled from a .docx template. Replace placeholders even when Word has split them across formatting runs, fill header, footer and table placeholders, add a row per line item, format money and dates, catch unfilled fields and convert the results to PDF.
- How-toPrint Mailing Labels from an Excel Address ListTurn an Excel address list into a print-ready PDF of mailing labels with pandas and reportlab: describe a label sheet such as Avery L7160 or 5160 by its measurements, tidy addresses by dropping blank lines, shrink long lines to fit, start on a partly used sheet, print an alignment test, and check every address landed inside its label.
- How-toRender an Excel Range as an Image with PythonTurn a formatted block of cells — a KPI table, a summary, a small report — into a PNG for an email body, a chat message or a slide: LibreOffice on Linux via a print area and a PDF, cropped with Pillow at any resolution; xlwings to_png on Windows with Excel; and when a pure-Python rendering is enough.
- How-toInsert Page Breaks Between Groups with openpyxlMake each region, customer or department start on a new printed page: find where each group ends, add manual row breaks with openpyxl, repeat the header on every page, add column breaks for wide sheets, clear old breaks, do the same with XlsxWriter, and prove the result by rendering a PDF and checking which group starts each page.
- How-toPrint an Excel Workbook from Python with win32comSend workbooks to a printer from a Python script on Windows: prepare the page setup so the printout is right (fit to width, landscape, repeated header rows, print area) with openpyxl or COM, list printers and pick one, call PrintOut for whole workbooks, single sheets or page ranges, print many files in a loop without dialogs, and fall back to LibreOffice or PDF when Excel is not available.
Follow it through a track
Prefer an ordered route? These tracks cover pdf export along the way, in the order that builds on itself.
Related topics
Subjects that keep turning up on the same pages as this one, most overlap first.
PDF export is part of Automating & delivering reports.