Category: | Bug report |
Priority: | Normal |
Status: | Assigned |
Project: | Severity: | Minor |
Resolution: | Open |
|
Component: | Reproducibility: | Always |
Assigned to: |
Hi,
we use JasperReports 5.2.0 in our application and we noticed the following strange behavior:
If we have a report with a chart in it, which was created through drag and drop in Jaspersoft® Studio, the report generated will be fine except if we want to print it through a PDF printer (e.g. PDF24, FreePDF etc.). The problem is that the text will become blurry and the whole page containing the chart will be rendered as an image rather than seperating text from images.
I already tried
- JasperReports Library 6.1.0 (that's why I tagged this bug as for 6.1)
- JFreeChart Library 1.0.19
- the newest versions for the PDF printers
To reproduce this odd behavior, do the following (a PDF printer has to be installed beforehand):
1. Create a report with some fields. I used the standard template "Coffee" (see attached jrxml file).
2. Add a chart into the report.
3. Generate the report with data, such that the report has at least two pages, one without a chart, the other one including the chart, and show it in the JRViewer.
4. Press the print button and select any PDF printer
5. Print and save the file, open it and navigate to the "chart page" and notice the difference to the pages, where no chart is included. The "chart page" is entirely blurry (selectable as an image) whereas the other pages are not.
Now we are limited to the "save" button in the JRViewer to generate PDF files, where the images are seperated from the text when exporting. This is ok as a temporary workaround, but the print button should work as expected - images should be sent as images, text as text to the printer. Rendering a whole page as an image, where a JFreeChart is included, seems senseless.
The odd thing is, that if I code the JFreeChart object programmatically and give it to the report as a Image-parameter or as a bean field of type awt.Image, then the problem does not occur.
Hope I could make myself clear and thanks for your great library.
10 Comments:
Hi,
Can you please attach here one of the PDFs you generate and have this problem?
I suggest you try download the JR project source package and run the /demo/samples/chart sample using Ant.
The generated PDFs in that sample should have charts rendered as SVG, so zooming in them should not show and quality degradation.
Also, printing such PDFs should not pose quality issues either.
I have attached here a PDF from that sample for your convenience. Please try print it on your side and let us know how it goes.
Thanks,
Teodor
Hi Teodor,
attached you'll find a PDF file with the described problem.
Your suggestion: I did as you said. I ran the test target from the ant file and the PDF output was as expected: the chart is seperated from the rest of the text.
BUT if I run the "view" target from Ant, and then PRINT the report as PDF file through any of the PDF printers I have installed, the result is the same: the whole page gets rendered as an image. Attached you'll find the file.
As I already wrote, the "normal" PDF output generated directly through JR is perfectly normal. But if I PRINT the .jrprint file from the JasperViewer through a PDF printer, the page gets blurry. I don't know why, but in the case for the area chart report, I am not able to select any text anymore, even if the page doesn't contain a chart (e.g. page 2).
As a side effect, the PDF file will get larger as needed. From roughly 180 KB it will become over 4.6 MB for the full Area Chart report.
Best regards,
Zafer
One possible cause is the fact that we set a transparent colour as chart/plot/legend background and plot outline colour in DefaultChartTheme. This seems to cause (some) Java print services to print the entire page as an image. PostScript based print services seem to be affected for instance.
I made a test with the PostScript print service included in Sun/Oracle JREs. I replaced all places where DefaultChartTheme.TRANSPARENT_PAINT was used with null, and the .ps page with the chart was no longer a rasterized image and had proper texts on it.
We're going to investigate to see whether using null for chart/etc background is safe in JFreeChart, and if so commit this change as fix.
In the meantime, if you want to test whether the change would fix your problem, you can fetch the sources and edit DefaultChartTheme.java by replacing TRANSPARENT_PAINT with null (or initialize TRANSPARENT_PAINT with null).
Regards,
Lucian
Hi Lucian,
I rebuilt JR with TRANSPARENT_PAINT initialized to null. And I double-checked it, just to be sure, with decompiling DefaultChartTheme.class from the newly built JAR-file.
Sadly the problem still exists, BUT with a different outcome. The AreaChartReport and the report based on the coffee template show no difference at all. But in our application, the report is sometimes rendered as an image (no difference), sometimes rendered as an image on the first page only, and the other pages are seperated from the charts.
I first thought, it is because we use a PieChart in the report together with BarChart in the same report through subreports. But there's another report we can generate in our app, where the page including a PieChart is not rendered as an image. I will do some further tests to see if I can track it down.
Regards,
Zafer
The fix worked for me with your "coffee" report, using cups-pdf as PDF printer. Attaching before and after PDFs.
We'll have to do more tests to understand why the fix didn't work for you. I'm testing with the JR master branch code, which has jfreecharts 1.0.19. Another possible source of difference is obviously the PDF priter itself.
Regards,
Lucian
Hi Lucian,
this is weird, as I tested it with the 6.1.0 src classes from the library project with the variable initialized with null. And also tested against JFreeCharts 1.0.19.
I have the following PDF printers installed:
7-PDF
Bullzip PDF
FreePDF XP
PDF24
PDFCreator
The result is always the same.
My Setup:
Windows 7 Pro (SP1) 64 bit
8GB RAM, Intel Core i7 Processor (3.6GHz)
Java-Version: JRE 1.7.0_55_x32
3rd party libraries we use (apart from jasper reports):
- aopalliance
- AspectJ
- Aspose.Words.jdk16
- Binding-2.0.3
- Commons: Beanutils 1.8.0, Collections 3.2.1 (2.1.1 for JR 5.2.0), DBCP2 2.0.1, Digester 2.1, Logging 1.2, Pool2 2.2,
- Forms 1.2.0
- GentlyWEB-Utils 1.1
- groovy-all-2.0.1
- iText-2.1.7.js2
- Javadbf 0.4.0
- Jaxen 1.1.6
- jbcl
- JCalendar
- JCommon 1.0.23 (1.0.16 for JR 5.2.0)
- JDom 2.0.5
- JFreeChart 1.0.19 (1.0.13 for JR 5.2.0)
- JNA 3.5.2
- JoSQL 2.1
- Log4J 1.2.17
- Looks 2.0.1
- Metadata Extractor 2.3.1
- mysql connector 5.1.32
- Spring 4.1.1: AOP, Aspects, Beans, Context, Core, Expression, JDBC, Tx
- SwingX 0.9.7
- Synthetica Themes
- Validation 2.0.1
- vlcj-3.2.0
- xercesImpl.jar
- xml-apis.jar
Pie charts are not covered by the changes described in comment 4 because pie chart labels have a default transparent shadow (in JFreeChart, not set by JR).
The shadow can be disabled by doing piePlot.setLabelShadowPaint(null) in DefaultChartTheme.createPieChart(). Try adding this line in DefaultChartTheme and see if it has any effect on the reports that have pie charts.
This suggestion seems to have fixed the issue. Setting the labelShadowPaint to null let me print the reports to PDF files without any page being rendered as an image.
Thank you Lucian!