opendataloader-project/opendataloader-pdf · error · IllegalArgumentException

Unsupported image format '%s'. Supported values: png, jpeg

Error message

Unsupported image format '%s'. Supported values: png, jpeg

What it means

Thrown when --image-format receives a non-empty value that is not one of the accepted formats. The value is trimmed and lowercased, then checked against the imageFormatOptions set (png, jpeg) via Config.isValidImageFormat; any other string is rejected with the offending value echoed back. This is a value-domain error, distinct from the empty-value error which fires earlier in the same block.

Source

Thrown at java/opendataloader-pdf-core/src/main/java/org/opendataloader/pdf/api/cli/CLIOptions.java:472

                                Config.getImageOutputOptions(", ")));
            }
            String output = outputValue.trim().toLowerCase(Locale.ROOT);
            if (!Config.isValidImageOutput(output)) {
                throw new IllegalArgumentException(
                        String.format("Unsupported image output mode '%s'. Supported values: %s",
                                output, Config.getImageOutputOptions(", ")));
            }
            config.setImageOutput(output);
        }
        if (commandLine.hasOption(IMAGE_FORMAT_LONG_OPTION)) {
            String formatValue = commandLine.getOptionValue(IMAGE_FORMAT_LONG_OPTION);
            if (formatValue == null || formatValue.trim().isEmpty()) {
                throw new IllegalArgumentException(
                        "Option --image-format requires a value. Supported values: png, jpeg");
            }
            String format = formatValue.trim().toLowerCase(Locale.ROOT);
            if (!Config.isValidImageFormat(format)) {
                throw new IllegalArgumentException(
                        String.format("Unsupported image format '%s'. Supported values: png, jpeg", format));
            }
            config.setImageFormat(format);
        }
        if (commandLine.hasOption(IMAGE_DIR_LONG_OPTION)) {
            config.setImageDir(commandLine.getOptionValue(IMAGE_DIR_LONG_OPTION));
        }
        if (commandLine.hasOption(IMAGE_RESOLUTION_LONG_OPTION)) {
            try {
                double imageResolution = Double.parseDouble(commandLine.getOptionValue(IMAGE_RESOLUTION_LONG_OPTION));
                if (!Double.isFinite(imageResolution) || imageResolution <= 0) {
                    throw new IllegalArgumentException(
                        "Option --image-resolution requires a finite positive double value.");
                }
                config.setImageResolution(imageResolution);
            } catch (NumberFormatException e) {
                throw new IllegalArgumentException(
                    "Option --image-resolution requires valid double value.", e);

View on GitHub (pinned to a7789b8e77)

Solutions

  1. Use exactly `png` or `jpeg`.
  2. Replace `jpg` with `jpeg`.
  3. Omit --image-format to keep the png default.

Example fix

// before
opendataloader-pdf doc.pdf --image-format jpg
// after
opendataloader-pdf doc.pdf --image-format jpeg
Defensive patterns

Strategy: type-guard

Validate before calling

String f = userValue.trim().toLowerCase(Locale.ROOT);
if (!Config.isValidImageFormat(f)) {
    throw new IllegalArgumentException(
        "Unsupported image format '" + userValue + "'. Use: " + Config.getImageFormatOptions(", "));
}

Type guard

boolean isAcceptableImageFormat(String v) {
    return v != null && Config.isValidImageFormat(v.trim().toLowerCase(Locale.ROOT));
}

Try / catch

try {
    config.setImageFormat(f);
} catch (IllegalArgumentException e) {
    // fall back to default png only if intentional; otherwise surface to user
    config.setImageFormat(Config.IMAGE_FORMAT_PNG);
}

Prevention

When it happens

Trigger: Pass a synonym or extension like `--image-format jpg`, `--image-format tiff`, `--image-format webp`, or a typo like `--image-format pnng`. Note `jpg` is NOT accepted even though it is a common synonym — only `jpeg` is.

Common situations: Developers assume jpg is valid (it is not); migrating from a tool that accepted other formats; case or locale assumptions (the lowercasing is safe, so case is not the issue).

Related errors


AI-assisted analysis of opendataloader-project/opendataloader-pdf@a7789b8e77 (2026-08-14). Data as JSON: /api/errors/c731791fc4e377bb. Report an issue: GitHub.