public class CustomImagesStrategy extends Object implements IImageExportStrategy
Example:
// Set options
DocumentConverterOptions options = new DocumentConverterOptions();
options.setImageExportStrategy(new CustomImagesStrategy(imageFolder, this::renameImageHandler));
// Convert document without saving images
String markdown = MarkdownConverter.convert("document.pdf", options);
// The markdown will contain image references like "file_0_originalName",
// but the actual image files won't be saved
private int index = 0;
// Renaming function
private void renameImageHandler(CustomImageSavingArgs args) {
args.setOutputImageFileName("file_" + index + "_" + args.getImageFileName());
index++;
}
| Modifier and Type | Class and Description |
|---|---|
static interface |
CustomImagesStrategy.CustomImageSavingHandler
Functional interface representing a custom image-saving handler.
|
| Constructor and Description |
|---|
CustomImagesStrategy(String imagesFolder,
CustomImagesStrategy.CustomImageSavingHandler customHandler)
Initializes a new instance of the
CustomImagesStrategy class. |
| Modifier and Type | Method and Description |
|---|---|
CustomImagesStrategy.CustomImageSavingHandler |
getCustomHandler() |
String |
getImagesFolder()
Gets the folder where images will be exported.
|
OutputStream |
getImageStream(ImageExportContext context)
Gets an output stream for writing the exported image to the file system.
|
public CustomImagesStrategy(String imagesFolder, CustomImagesStrategy.CustomImageSavingHandler customHandler)
CustomImagesStrategy class.imagesFolder - The folder where images will be exported.customHandler - The custom handler defining the mechanism for saving images.IllegalArgumentException - if imagesFolder is null.public String getImagesFolder()
getImagesFolder in interface IImageExportStrategypublic OutputStream getImageStream(ImageExportContext context)
If the images folder does not exist, it will be created automatically.
The image will be saved with the filename specified in the ImageExportContext.
getImageStream in interface IImageExportStrategycontext - The image export context containing information about the image being processed.public CustomImagesStrategy.CustomImageSavingHandler getCustomHandler()
Copyright © 2026. All rights reserved.