I have a problem,
I'm generating PDFs with iText on the fly.
It means, the visitor of my site can click on every chart and PDF opens in new window.
I have a problem with it - in the generated PDF everything is written with Bold Font.
The PDF is generated from the outputstream, and that is the same one, which creates output on my site (where everything is OK, I have bold font only in Chart Title).
Here is my code:
Java-Class:
Code: Select all
public class ExportPDF {
public ExportPDF(JFreeChart Chart, int Width, int Height, OutputStream Showout)
{
try {
OutputStream out = new BufferedOutputStream(Showout);
writeChartAsPDF(out, Chart, Width, Height, new DefaultFontMapper());
out.close();
}
catch (IOException e) {
System.out.println(e.getMessage());
}
}
public static void writeChartAsPDF(OutputStream out,
JFreeChart chart,
int width,
int height,
FontMapper mapper) throws IOException {
Rectangle pagesize = new Rectangle(width, height);
Document document = new Document(pagesize, 50, 50, 50, 50);
try {
PdfWriter writer = PdfWriter.getInstance(document, out);
document.addAuthor("Chart");
document.addSubject("Chart");
document.open();
PdfContentByte cb = writer.getDirectContent();
PdfTemplate tp = cb.createTemplate(width, height);
Graphics2D g2 = tp.createGraphics(width, height, mapper);
Rectangle2D r2D = new Rectangle2D.Double(0, 0, width, height);
chart.draw(g2, r2D);
g2.dispose();
cb.addTemplate(tp, 0, 0);
}
catch (DocumentException de) {
System.err.println(de.getMessage());
}
document.close();
}
}
Code: Select all
ServletOutputStream showout = response.getOutputStream();
response.setContentType( "application/pdf" );
ExportPDF PDFpopup = new ExportPDF(Chart, intImageWidth, intImageHeight, showout);