problem generating PDF with iText - I get all Fonts bold...?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Elly
Posts: 19
Joined: Tue Jun 07, 2005 2:26 pm
Location: Germany
Contact:

problem generating PDF with iText - I get all Fonts bold...?

Post by Elly » Fri Apr 07, 2006 9:27 am

Hi,
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();
} 
}
the call:

Code: Select all

ServletOutputStream showout = response.getOutputStream();
response.setContentType( "application/pdf" );
ExportPDF PDFpopup = new ExportPDF(Chart, intImageWidth, intImageHeight, showout);
could someone help me? Thanx in advace!
using JFreeChart 1.0.0 rc1, Java 1.4.2

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Fri Apr 07, 2006 3:38 pm

I really don't know. What are the fonts you are using in your chart? Maybe there is a mapping problem?
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Elly
Posts: 19
Joined: Tue Jun 07, 2005 2:26 pm
Location: Germany
Contact:

probably a bug?

Post by Elly » Tue Apr 25, 2006 3:04 pm

now I implemented my first XY-(Line) Chart and the problem with bold fonts doesn't exist with that chart.
But others (Pie, Bar, Stacked Bar, Area, Line) have all bold fonts in PDF, although the output stream which is also used to display the charts on the page look fine.
Maybe it is a bug?
using JFreeChart 1.0.0 rc1, Java 1.4.2

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Tue Apr 25, 2006 3:57 pm

Can you post a small demo and the iText version number so I can try this out? It would be best to post it in a bug report on the SourceForge project page:

http://sourceforge.net/tracker/?group_i ... tid=115494
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

mickish
Posts: 29
Joined: Tue Jan 08, 2008 11:15 pm
Location: Venice, Florida

Post by mickish » Thu Apr 03, 2008 4:44 pm

This reminds me of my first experience printing charts to PDF:

I had copied a JFreeChart example that set the PDF page size to the width and height of the example chart, which was way too small for my chart.

So technically it wasn't the fonts that were too big. I was asking to draw the correct size fonts into a small chart, so they appeared too large relative the rest of the picture.

Try changing the pagesize of your PDF Document() to com.lowagie.text.LETTER or LETTER.rotate().

Reggie3
Posts: 12
Joined: Mon Mar 10, 2008 5:19 pm

Page Size

Post by Reggie3 » Thu Apr 03, 2008 6:05 pm

Elly,
Like mickish said it might be your page size. It looks like you're setting your pagesize to be the same as the size of your image. Change this line from your code

Code: Select all

Document document = new Document(pagesize, 50, 50, 50, 50); 
to

Code: Select all

Document document = new Document (PageSize.LETTER.rotate(), 50, 50, 50, 50); 
It will give you an appropriately sized chart on a letter sized page.

jbickers
Posts: 1
Joined: Thu Apr 03, 2008 12:32 pm

Post by jbickers » Thu Apr 03, 2008 8:19 pm

I'm having a similar problem to the original poster, and the bold fonts are not just on the chart itself, they are on the rest of the text on the same page. It appears to be a rendering problem because of something that the chart is doing to the graphics state, that Acrobat Reader resets when it goes from one page to another. So it may be a problem with iText rather than jFreeChart, perhaps not cleaning up the graphics state completely?

I have posted a bug report (1933247) with example code, as suggested earlier in the thread.

Locked