excel2pdf

package module
v2.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2026 License: MIT Imports: 9 Imported by: 0

README

excel2pdf

Converts an Excel file to PDF, compatible with both Windows and Linux. Uses either LibreOffice or Microsoft Excel, with LibreOffice given priority if installed.

var excelPath = `file.xlsx`

func main() {
    pdfFilePath,err := excel2pdf.ConvertExcelToPdf(excelPath)
	fmt.Println(pdfFilePath, err)
}

Documentation

Overview

Package excel2pdf converts Excel (.xlsx) files to PDF.

It supports Windows, Linux, and macOS. On Windows, LibreOffice is preferred if installed, with automatic fallback to Microsoft Excel. On Linux and macOS, LibreOffice is required.

Concurrency

Up to [defaultMaxConcurrency] Excel-to-PDF conversions may run concurrently. Callers that exceed this limit will block until a slot becomes free. Call SetMaxConcurrency once at startup to adjust the limit before launching any goroutines.

PDF merge operations (CombinePdfs) are exclusive: only one may run at a time. If another merge is already in progress, ErrExcel2PdfIsProcessing is returned immediately.

Example

excel2pdf.SetMaxConcurrency(4)

pdfPath, err := excel2pdf.ConvertExcelToPdf("report.xlsx")
if err != nil {
	log.Fatal(err)
}
fmt.Println("PDF written to", pdfPath)

Index

Constants

This section is empty.

Variables

View Source
var ErrExcel2PdfIsProcessing = errors.New("a process is currently running using the resource")

ErrExcel2PdfIsProcessing is returned by CombinePdfs when another merge operation is already in progress.

View Source
var ErrLibreofficeNotInstalled = errors.New("LibreOffice is not installed")

ErrLibreofficeNotInstalled is returned on Linux and macOS when LibreOffice cannot be located on the system.

Functions

func CombinePdfs

func CombinePdfs(pdfFiles []string, outputPdfFile string) (pdfFile string, err error)

CombinePdfs merges one or more PDF files into a single PDF written to outputPdfFile and returns the output path.

Only one merge may run at a time. If another call is already in progress, ErrExcel2PdfIsProcessing is returned immediately.

func ConvertExcelToPdf

func ConvertExcelToPdf(excelFile string) (pdfFile string, err error)

ConvertExcelToPdf converts an Excel file to PDF and returns the path of the generated PDF file.

On Windows, LibreOffice is used when available; otherwise Microsoft Excel is used. On Linux and macOS, LibreOffice must be installed.

Up to the concurrency limit set by SetMaxConcurrency conversions may run in parallel. If that limit is already reached, the call blocks until a slot becomes available.

func SetMaxConcurrency

func SetMaxConcurrency(n int)

SetMaxConcurrency sets the maximum number of ConvertExcelToPdf calls that may run concurrently. It must be called before any concurrent conversions begin; it is not safe to call while conversions are in flight.

n must be at least 1; values above the number of logical CPUs are unlikely to improve throughput and will increase memory pressure. The recommended range is 3–4 when Microsoft Excel or LibreOffice is the converter.

Types

This section is empty.

Directories

Path Synopsis
Command example demonstrates batch conversion of Excel files to a single PDF.
Command example demonstrates batch conversion of Excel files to a single PDF.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL