Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

MiniPdf for Java

MiniPdf for Java is a Java 17 library and command-line tool for converting DOCX, XLSX, and PPTX files to PDF without Microsoft Office or LibreOffice.

Install

The library is available from Maven Central:

<dependency>
    <groupId>io.github.mini-software</groupId>
    <artifactId>minipdf</artifactId>
    <version>0.1.6</version>
</dependency>

Maven group IDs may contain hyphens, but Java package names may not. Therefore, the dependency uses io.github.mini-software, while imports use io.github.minisoftware.minipdf.

Library

import io.github.minisoftware.minipdf.MiniPdf;

import java.nio.file.Path;

MiniPdf.convertToPdf(
        Path.of("document.docx"),
        Path.of("document.pdf"));

Use MiniPdf.convertBytesToPdf when the Office document is already in memory. ConversionOptions.withPageSize overrides the output page size.

Register fonts before converting when DOCX, XLSX, or PPTX content needs glyphs that are not available in the standard PDF fonts:

import java.nio.file.Files;
import java.nio.file.Path;

try {
    MiniPdf.registerFont(
            "Noto Sans",
            Files.readAllBytes(Path.of("fonts/NotoSans-Regular.ttf")));
    MiniPdf.convertToPdf(
            Path.of("document.docx"),
            Path.of("document.pdf"));
} finally {
    MiniPdf.clearRegisteredFonts();
}

Registered fonts are process-wide. clearRegisteredFonts removes them when the same process needs a different font set for a later conversion.

CLI

Download the executable JAR with Maven:

mvn dependency:copy `
  -Dartifact=io.github.mini-software:minipdf-cli:0.1.6 `
  -DoutputDirectory=.

Convert a document:

java -jar minipdf-cli-0.1.6.jar input.pptx -o output.pdf

The CLI accepts .docx, .xlsx, and .pptx files. Run it with --help for page-size and font-directory options.

Current Scope

The Java implementation currently provides text-first Office conversion:

  • DOCX paragraphs, tabs, and line breaks
  • XLSX shared strings, inline strings, numbers, and booleans
  • PPTX slide text, native slide dimensions, and one PDF page per slide
  • bounded OOXML ZIP loading and XML external-entity protection

Advanced Office layout, images, charts, and embedded fonts are not yet fully reproduced by the Java renderer.

Build and Test

From this directory:

mvn -B -ntp verify