Antialiasing in pdf export
Antialiasing in pdf export
Hello,
I have a problem with antialiasing. When I try to write a chart into a PDF with the jfreechart.draw() method the line in the PDF are not smooths.
Is it possible to have antialiasing in the PDF (using itext) because even with the simplest sample the line are not smooths.
Thanks.
I have a problem with antialiasing. When I try to write a chart into a PDF with the jfreechart.draw() method the line in the PDF are not smooths.
Is it possible to have antialiasing in the PDF (using itext) because even with the simplest sample the line are not smooths.
Thanks.
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Sounds like you are embedding a PNG image in the PDF. You don't have to do that - you can use iText to write PDF (vector) output...see the example in the JFreeChart Developer Guide or Bruno Lowagie's excellent iText in Action.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


unfortunatly even with this simple sample code it doesn't work :
The lines in the pdf are not smooth. I try with the lastest version of itext. What can I do ? Maybe it's the best result in pdf that I can obtain ?
Code: Select all
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.io.File;
import java.io.OutputStream;
import java.io.BufferedOutputStream;
import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.xy.XYDataset;
import com.lowagie.text.Document;
import com.lowagie.text.Rectangle;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfTemplate;
import com.lowagie.text.pdf.FontMapper;
import com.lowagie.text.pdf.DefaultFontMapper;
import com.lowagie.text.pdf.BaseFont;
public class TestChart {
/**
* Saves a chart to a PDF file.
*
* @param file The file.
* @param chart The chart.
* @param width The chart width.
* @param height The chart height.
* @throws DocumentException
*/
public static void saveChartAsPDF(File file,
JFreeChart chart,
int width, int height,
FontMapper mapper) throws IOException, DocumentException
{
OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
writeChartAsPDF(out, chart, width, height, mapper);
out.close();
}
/**
* Writes a chart to an output stream in PDF format.
*
* @param out The output stream.
* @param chart The chart.
* @param width The chart width.
* @param height The chart height.
* @throws DocumentException
*/
public static void writeChartAsPDF(OutputStream out,
JFreeChart chart,
int width, int height,
FontMapper mapper) throws IOException, DocumentException
{
Rectangle pagesize = new Rectangle(width, height);
Document document = new Document(pagesize, 50, 50, 50, 50);
PdfWriter writer = PdfWriter.getInstance(document, out);
document.addAuthor("JFreeChart");
document.addSubject("Demonstration");
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, null);
g2.dispose();
cb.addTemplate(tp, 0, 0);
document.close();
}
/**
* Starting point for the demonstration application.
45
* @throws DocumentException
*/
public static void main(String[] args) throws DocumentException {
try {
// create a chart...
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for(int i = 0 ; i < 30 ; i ++)
{
dataset.setValue(Math.ceil(Math.random() * 100), "vague1", "tranche_"+i);
dataset.setValue(Math.ceil(Math.random() * 100), "vague2", "tranche_"+i);
}
JFreeChart chart = ChartFactory.createLineChart("PDF Test Chart 1",
"X", "Y",
dataset, PlotOrientation.VERTICAL, true, true, false);
// write the chart to a PDF file...
File fileName = new File("c:/tmp/pdf/ChartTest.pdf");
saveChartAsPDF(fileName, chart, 400, 300, new DefaultFontMapper());
}
catch (IOException e) {
System.out.println(e.getMessage());
}
}
}
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
I ran this and the output looks fine to me. What PDF viewer are you using?
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


I'm using Acrobat Reader 5.0. I'm downloading the version 8.1 to test.
Can you send your pdf result to my mail to see if it's a viewer problem or maybe a library problem. (fgeisler@yahoo.fr)
Thanks
Can you send your pdf result to my mail to see if it's a viewer problem or maybe a library problem. (fgeisler@yahoo.fr)
Thanks
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
OK. Ignore the e-mail I just sent you.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Want Information on Editing Features
Hi Sir,
Thanks in Advance............
I am using JFreechart in my project. I have some problems in using it.
I am using BarChart to show data but here requirement is that user should be able to edit selected portion of perticular Bar. Say ....I have to change color of selected portion of perticular bar.........
Is it possible to implement these features using JFreeChart latest version?
Is there any guidelines in Latest JFreeChart Developer Guide?
Its very urgent..........Please Reply soon
Regards
Javed
Thanks in Advance............
I am using JFreechart in my project. I have some problems in using it.
I am using BarChart to show data but here requirement is that user should be able to edit selected portion of perticular Bar. Say ....I have to change color of selected portion of perticular bar.........
Is it possible to implement these features using JFreeChart latest version?
Is there any guidelines in Latest JFreeChart Developer Guide?
Its very urgent..........Please Reply soon
Regards
Javed
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
You should have started a new thread for this topic, it doesn't have anything to do with the original question.
Do you want to edit the data or just change the colour of the selected bar? If it is the latter, take a look at MouseOverDemo1.java, which is included for download with the JFreeChart Developer Guide.
Do you want to edit the data or just change the colour of the selected bar? If it is the latter, take a look at MouseOverDemo1.java, which is included for download with the JFreeChart Developer Guide.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader

