Creating your own Document Converter
To create your own Document Converter it is nessesary to create a new class that implements the Converter interface:
import com.openkm.core.ConversionException;
import net.xeoh.plugins.base.Plugin;
import java.io.File;
import java.io.IOException;
import java.util.List;
/**
*/
public interface Converter extends Plugin {
public static final int TO_PDF = 0;
public static final int TO_IMAGE = 1;
public void makeConversion(File input, String mimeType, File output) throws IOException, ConversionException;
public List<String> getSourceMimeTypes();
public int getConversionType();
}
More information at: Register a new plugin.
The new class must be included in the package com.openkm.plugin.conversion because the application plugins system will load it from there.
Do not miss the tag @PluginImplementation otherwise the application plugin system will not be able to retrieve the new class.
Methods description
Method | Type | Description |
---|---|---|
makeConversion(File input, String mimeType, File output) |
void |
The method converts the file at input to a specified file format at output. |
getSourceMimeTypes() |
List<String> |
Return a list of valid document MIME TYPES allowed to be converted. |
getConversionType() |
int |
Return the value of the MIME TYPE to which the input document will be converted. Allowed values are:
When you choose Converter.TO_IMAGE it will retun an image in PNG format. |
Example of the Document converter implementation
package com.openkm.plugin.conversion;
import com.openkm.core.ConversionException;
import com.openkm.core.MimeTypeConfig;
import com.openkm.util.DocConverter;
import net.xeoh.plugins.base.annotations.PluginImplementation;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
/**
*/
@PluginImplementation
public class SqlToPdfConversion implements Converter {
String[] sourceMimeTypes = new String[] { MimeTypeConfig.MIME_SQL };
@Override
public void makeConversion(File input, String mimeType, File output) throws IOException, ConversionException {
DocConverter.getInstance().src2pdf(input, output, "sql");
}
@Override
public List<String> getSourceMimeTypes() {
return Arrays.asList(sourceMimeTypes);
}
@Override
public int getConversionType() {
return Converter.TO_PDF;
}
}