So I found an example on the internet how to save a javafx chart to a pdf, so I tried it out:
final AreaChart<Number, Number> arechart = new AreaChart<>(new NumberAxis(0, 3, 0.5), new NumberAxis(0, 3, 0.5));
xAxis.setLabel("average quality");
yAxis.setLabel("average quantity");
sc.setTitle("Producerdata");
XYChart.Series series1 = new XYChart.Series();
series1.setName("Water 11");
producer.getProducts().forEach((pr) -> {
if (pr.getName().equals("Water 11")) {
series1.getData().add(new XYChart.Data(pr.getPercentQual(), pr.getAmount()));
}
});
XYChart.Series series2 = new XYChart.Series();
series2.setName("Water E40");
producer.getProducts().forEach((pr) -> {
if (pr.getName().equals("Water E40")) {
series2.getData().add(new XYChart.Data(pr.getPercentQual(), pr.getAmount()));
}
});
arechart.getData().addAll(series1, series2);
PDDocument newPDF=new PDDocument();
PDPage chartPage = new PDPage();
newPDF.addPage(chartPage);
WritableImage image = arechart.snapshot(new SnapshotParameters(), null);
BufferedImage bf= SwingFXUtils.fromFXImage(image, null);
PDImageXObject pdImageXObject = LosslessFactory.createFromImage(newPDF, bf);
PDPageContentStream contentStream = new PDPageContentStream(newPDF, chartPage);
contentStream.drawImage(pdImageXObject, 150, 500, pdImageXObject.getWidth() , pdImageXObject.getHeight() );
contentStream.close();
newPDF.close();
newPDF.save(new File("C:\\Users\\chelsfan\\Desktop\\TestingNetbeans\\PDFS\\chart.pdf"));
Now the problem I am struggling with is that when I save the javafx area diagramm to the pdf, the chart looks kinda blurry.
For e.g:
If I zoom 100% to the pdf the diagramm "dissapears": If I zoom out to 75% percent or zoom in to 125% the diagramm looks blurry:
Now my question is, if there is some way to make the chart in the pdf looking sharper, because in the programm the chart looks normal (not blurry,looks sharp)?