Creating your own Document Converter
Esta página aún no está disponible en tu idioma.
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();}The new class must be included in the package com.openkm.plugin.conversion because the application plugins system will load it from there.
Methods description
Section titled “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 |
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: - Converter.TO_PDF - Converter.TO_IMAGE When you choose Converter.TO_IMAGE it will retun an image in PNG format. |
Example of the Document converter implementation
Section titled “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;
/** */@PluginImplementationpublic 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; }}