use of org.apache.xmlgraphics.java2d.GraphicContext in project grafikon by jub77.
the class DrawOutput method processPdf.
private void processPdf(Collection<Image> images, OutputStream stream, DrawLayout layout) throws OutputException {
PDFDocumentGraphics2D g2d;
try {
g2d = new PDFDocumentGraphics2D();
g2d.setGraphicContext(new GraphicContext());
FopFactory fopFactory = PdfTransformer.createFopFactory();
FOUserAgent userAgent = fopFactory.newFOUserAgent();
FontConfig fc = userAgent.getRendererConfig(MimeConstants.MIME_PDF, new PDFRendererConfigParser()).getFontInfoConfig();
FontManager fontManager = fopFactory.getFontManager();
DefaultFontConfigurator fontInfoConfigurator = new DefaultFontConfigurator(fontManager, null, false);
List<EmbedFontInfo> fontInfoList = fontInfoConfigurator.configure(fc);
FontInfo fontInfo = new FontInfo();
FontSetup.setup(fontInfo, fontInfoList, userAgent.getResourceResolver(), fontManager.isBase14KerningEnabled());
g2d.setFontInfo(fontInfo);
g2d.setFont(new Font("SansCondensed", Font.PLAIN, g2d.getFont().getSize()));
List<Dimension> sizes = this.getSizes(images, g2d);
Dimension size = this.getTotalSize(sizes, layout);
g2d.setupDocument(stream, size.width, size.height);
this.drawImages(sizes, images, g2d, layout);
g2d.finish();
} catch (IOException | FOPException e) {
throw new OutputException(e.getMessage(), e);
}
}
use of org.apache.xmlgraphics.java2d.GraphicContext in project dkpro-lab by dkpro.
the class ChartUtil method writeChartAsPDF.
/**
* Exports a JFreeChart to a scalable PDF file.
*
* @param chart JFreeChart to export
* @param aOS stream to write to.
* @param aWidth width of the chart in pixels
* @param aHeight height of the chart in pixels
* @throws IOException if writing the svgFile fails.
*/
public static void writeChartAsPDF(OutputStream aOS, JFreeChart chart, int aWidth, int aHeight) throws IOException {
// Create an instance of the SVG Generator
PDFDocumentGraphics2D pdfGenerator = new PDFDocumentGraphics2D(true, aOS, aWidth, aHeight);
pdfGenerator.setDeviceDPI(PDFDocumentGraphics2D.NORMAL_PDF_RESOLUTION);
pdfGenerator.setGraphicContext(new GraphicContext());
pdfGenerator.setSVGDimension(aWidth, aHeight);
pdfGenerator.setClip(0, 0, aWidth, aHeight);
pdfGenerator.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON);
pdfGenerator.setRenderingHint(KEY_INTERPOLATION, VALUE_INTERPOLATION_BILINEAR);
chart.setBackgroundPaint(Color.white);
chart.getPlot().setBackgroundPaint(Color.white);
// draw the chart in the SVG generator
chart.draw(pdfGenerator, new Rectangle(aWidth, aHeight));
pdfGenerator.finish();
}
Aggregations