net.sourceforge.plantuml.pdf.PdfConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plantuml-mit Show documentation
Show all versions of plantuml-mit Show documentation
PlantUML is a component that allows to quickly write diagrams from text.
// THIS FILE HAS BEEN GENERATED BY A PREPROCESSOR.
package net.sourceforge.plantuml.pdf;
import java.io.File;
import java.lang.reflect.Method;
import net.sourceforge.plantuml.log.Logme;
public class PdfConverter {
// ::remove folder when __HAXE__
// ::remove folder when __CORE__
public static void convert(File svgFile, File pdfFile) {
if (svgFile.exists() == false) {
throw new IllegalArgumentException();
}
pdfFile.delete();
if (pdfFile.exists()) {
throw new IllegalStateException();
}
try {
// https://stackoverflow.com/questions/12579468/how-to-set-log4j-property-file
System.setProperty("log4j.debug", "false");
final Class> clSVGConverter = Class.forName("org.apache.batik.apps.rasterizer.SVGConverter");
final Object converter = clSVGConverter.newInstance();
final Class> clDestinationType = Class.forName("org.apache.batik.apps.rasterizer.DestinationType");
final Object pdf = clDestinationType.getField("PDF").get(null);
final Method setDestinationType = clSVGConverter.getMethod("setDestinationType", clDestinationType);
setDestinationType.invoke(converter, pdf);
final String[] path = new String[] { svgFile.getAbsolutePath() };
final Method setSources = clSVGConverter.getMethod("setSources", path.getClass());
setSources.invoke(converter, new Object[] { path });
final Method setDst = clSVGConverter.getMethod("setDst", pdfFile.getClass());
setDst.invoke(converter, new Object[] { pdfFile });
final Method execute = clSVGConverter.getMethod("execute");
execute.invoke(converter);
} catch (Exception e) {
Logme.error(e);
throw new UnsupportedOperationException();
}
if (pdfFile.exists() == false) {
throw new IllegalStateException();
}
}
}