Verified Owner
Top Fields Constructors Methods
org.jabref.toolkit.commands

pack-priv Class PdfExtractReferences

extends Object
implements Callable<Integer>
Class Inheritance
All Implemented Interfaces
java.util.concurrent.Callable
Annotations
@NullMarked
@Command
name:extract-references
description:Extract references from the "References" section of one or more PDFs and output them as BibTeX.
Imports
java.io.IOException, java.net.URI, java.nio.file.Files, .Path, java.util.ArrayList, .HashSet, .List, .Set, java.util.concurrent.Callable, org.jabref.logic.importer.FetcherException, .ParserResult, org.jabref.logic.importer.fileformat.pdf.CitationsFromPdf, org.jabref.logic.l10n.Localization, org.jabref.logic.preferences.CliPreferences, org.jabref.logic.util.URLUtil, org.jabref.logic.util.io.FileUtil, org.jabref.toolkit.converter.ExtractionModeConverter, org.jabref.toolkit.exception.ExportServiceException, .ImportServiceException, org.jabref.toolkit.service.ExportService, org.jspecify.annotations.NullMarked, .Nullable, org.slf4j.Logger, .LoggerFactory, picocli.CommandLine

Field Summary

Modifier and TypeField and Description
protected ExportService
private @Nullable String
private List<String>
private static final Logger
private @Nullable ExtractionMode
private @Nullable Path
private @Nullable Path
private String
protected Pdf
private JabKit.SharedOptions

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public Integer
call()

Implements java.util.concurrent.Callable.call.

Computes a result, or throws an exception if unable to do so.

private static Path
defaultBibFile(String input, Path resolvedFile)

Target for the "one .bib next to each source PDF" default.

private static String
displayName(String input)

The input as shown to the user: URLs are redacted so that embedded credentials do not end up on the console or in the log.

private static boolean

Returns:

true if the directory exists afterwards, false if it could not be created
ensureDirectoryExists
(Path directory)

Creates directory (and any missing parents) if it doesn't exist yet.

pack-priv void
private static String
outputBaseName(String input, Path resolvedFile)

Base name (without extension) for an input's output file.

private static Path
outputDirTarget(Path outputDir, String baseName, Set<Path> takenTargets)

Target inside --output-dir for one input.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

exportServiceback to summary
protected ExportService exportService
grobidUrlback to summary
private @Nullable String grobidUrl
Annotations
@Option
names:--grobid-url
description:Override the configured Grobid server URL for this call (only valid with --mode=GROBID).
inputFilesback to summary
private List<String> inputFiles
Annotations
@Parameters
paramLabel:FILE
description:PDF(s) to extract references from, each a file or an http(s)/ftp URL.
arity:1..*
LOGGERback to summary
private static final Logger LOGGER
modeback to summary
private @Nullable ExtractionMode mode
Annotations
@Option
names:--mode
converter:ExtractionModeConverter
description:Extraction mode: ${COMPLETION-CANDIDATES} (LLM is experimental). Defaults to GROBID if Grobid is enabled in preferences, otherwise RULE_BASED.
outputDirback to summary
private @Nullable Path outputDir
Annotations
@Option
names:--output-dir
description:Directory to write one .bib file per input PDF into (default: alongside each source PDF).
outputFileback to summary
private @Nullable Path outputFile
Annotations
@Option
names:--output
description:Write output to this file. Only valid when a single input file is given (e.g. --output=out.bib).
outputFormatback to summary
private String outputFormat
Annotations
@Option
names:--output-format
description:Output format (e.g. bibtex)
defaultValue:bibtex
pdfback to summary
protected Pdf pdf
Annotations
@ParentCommand
sharedOptionsback to summary
private JabKit.SharedOptions sharedOptions
Annotations
@Mixin

Constructor Detail

PdfExtractReferencesback to summary
pack-priv PdfExtractReferences()

Method Detail

callback to summary
public Integer call() throws ImportServiceException, ExportServiceException

Implements java.util.concurrent.Callable.call.

Doc from java.util.concurrent.Callable.call.

Computes a result, or throws an exception if unable to do so.

Annotations
@Override
defaultBibFileback to summary
private static Path defaultBibFile(String input, Path resolvedFile)

Target for the "one .bib next to each source PDF" default. A downloaded URL has no local source directory to sit next to, so its output goes into the working directory instead of silently into the temporary directory holding the download.

displayNameback to summary
private static String displayName(String input)

The input as shown to the user: URLs are redacted so that embedded credentials do not end up on the console or in the log.

ensureDirectoryExistsback to summary
private static boolean ensureDirectoryExists(Path directory)

Creates directory (and any missing parents) if it doesn't exist yet.

Returns:boolean

true if the directory exists afterwards, false if it could not be created

initFieldsback to summary
pack-priv void initFields()
outputBaseNameback to summary
private static String outputBaseName(String input, Path resolvedFile)

Base name (without extension) for an input's output file. For a URL the name is taken from the URL itself, not from the randomly named temporary file it was downloaded to, so that output names are stable across runs.

outputDirTargetback to summary
private static Path outputDirTarget(Path outputDir, String baseName, Set<Path> takenTargets)

Target inside --output-dir for one input. Inputs from different directories can share a file name, so a name already taken in this run gets a counter appended - paper.bib, paper-2.bib, ... - instead of the later input silently overwriting the earlier one's references.

Only names taken within the same run are avoided: a batch that is run again replaces its own previous output rather than piling up numbered copies of it.