@Override protected Graphics2D getGraphics2D(Symbolizer s) { Graphics2D g2 = pTemp.createGraphics(width, height); g2.addRenderingHints(mt.getRenderingHints()); return g2; }
@Override protected void initGraphics2D(List<Symbolizer> symbs, Graphics2D g2, MapTransform mt) { g2Levels = new HashMap<Integer, Graphics2D>(); baseG2 = pdfTemplate.createGraphics(width, height); //HashMap<Integer, Graphics2D> g2Level = new HashMap<Integer, Graphics2D>(); List<Integer> levels = new LinkedList<Integer>(); /** * Create one buffered image for each level present in the style. This * way allows to render all symbolizer in one pass without encountering * layer level issues */ for (Symbolizer s : symbs) { //Graphics2D sG2; // Does the level of the current symbolizer already have a graphic2s ? if (!levels.contains(s.getLevel())) { // It's a new level => register level levels.add(s.getLevel()); } } Collections.sort(levels); for (Integer level : levels) { Graphics2D sg2 = (Graphics2D) baseG2.create(); sg2.addRenderingHints(mt.getRenderingHints()); g2Levels.put(level, sg2); } }
public static void saveAsPdf(JFreeChart chart, String FILENAME , int width, int height) { File parent = new File(new File(FILENAME).getParent()); if( !parent.exists() ) { if( !parent.mkdirs() ) throw new RuntimeException("Can't make directory path"); } Document document = new Document(new Rectangle(width, height)); try { FileOutputStream file = new FileOutputStream(FILENAME); PdfWriter writer = PdfWriter.getInstance(document, file); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(width, height); Graphics2D g2d = tp.createGraphics(width, height, new DefaultFontMapper()); Rectangle2D r2d = new Rectangle2D.Double(0, 0, width, height); chart.draw(g2d, r2d); g2d.dispose(); cb.addTemplate(tp, 0, 0); document.close(); g2d.dispose(); } catch(Exception e) { e.printStackTrace(); } }
public static void saveAsPdf(LegendTitle legend, String FILENAME , int width, int height) { Document document = new Document(new Rectangle(width, height)); try { FileOutputStream file = new FileOutputStream(FILENAME); PdfWriter writer = PdfWriter.getInstance(document, file); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(width, height); Graphics2D g2d = tp.createGraphics(width, height, new DefaultFontMapper()); Rectangle2D r2d = new Rectangle2D.Double(0, 0, width, height); legend.draw(g2d, r2d); g2d.dispose(); cb.addTemplate(tp, 0, 0); document.close(); g2d.dispose(); } catch(Exception e) { e.printStackTrace(); } }
public static void saveChartAsPDF(OutputStream out, JFreeChart chart, int width, int height) throws DocumentException { Rectangle pagesize = new Rectangle(width, height); Document document = new Document(pagesize, 50, 50, 50, 50); PdfWriter writer = PdfWriter.getInstance(document, out); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(width, height); Graphics2D g2 = tp.createGraphics(width, height, new DefaultFontMapper()); Rectangle2D r2D = new Rectangle2D.Double(0, 0, width, height); chart.draw(g2, r2D); g2.dispose(); cb.addTemplate(tp, 0, 0); document.close(); }
PdfContentByte cb = ((PdfWriter) writer).getDirectContent(); PdfTemplate tp = cb.createTemplate(w, h); Graphics2D g2 = tp.createGraphics(w, h); if (scale > 0) g2.scale(scale, scale);
Graphics2D g2dLayer = layerTemplate.createGraphics(width, height); cb.beginLayer(mapLayer);
@SuppressWarnings("deprecation") @Override public void paint(RenderingContext renderingContext, ITextOutputDevice outputDevice, BlockBox blockBox) { PdfContentByte cb = outputDevice.getWriter().getDirectContent(); float width = (float) (this.cssWidth / outputDevice.getDotsPerPoint()); float height = (float) (this.cssHeight / outputDevice.getDotsPerPoint()); PdfTemplate template = cb.createTemplate(width, height); Graphics2D g2d = template.createGraphics(width, height); PrintTranscoder prm = new PrintTranscoder(); TranscoderInput ti = new TranscoderInput(this.svg); prm.transcode(ti, null); PageFormat pg = new PageFormat(); Paper pp = new Paper(); pp.setSize(width, height); pp.setImageableArea(0, 0, width, height); pg.setPaper(pp); prm.print(g2d, pg, 0); g2d.dispose(); PageBox page = renderingContext.getPage(); float x = blockBox.getAbsX() + page.getMarginBorderPadding(renderingContext, CalculatedStyle.LEFT); float y = (page.getBottom() - (blockBox.getAbsY() + this.cssHeight)) + page.getMarginBorderPadding(renderingContext, CalculatedStyle.BOTTOM); x /= outputDevice.getDotsPerPoint(); y /= outputDevice.getDotsPerPoint(); cb.addTemplate(template, x, y); }
Graphics2D g2d = pdfTemplate.createGraphics(doc.getPageSize().getWidth(), doc.getPageSize().getHeight(), new DefaultFontMapper()); try { if(job.render(g2d, i)) {