Author Topic: The quality of image in PDF file  (Read 478 times)

macknardy

  • Newbie
  • *
  • Posts: 4
The quality of image in PDF file
« on: May 02, 2019, 21:00:58 PM »
Hi everyone.

I'm using view canvas to import an external image (the extension is png). Until here it's fine.

But when I export the model using JasperReport to PDF file I lose the quality of the image.

Is there something to improve the quality of the image in the PDF file?

Bellow is the code that import the image inside the PDF file.

Code: [Select]
<image scaleImage="RealSize">
    <imageExpression><![CDATA[$F{imagePath}]]></imageExpression>
</image>

Thank you.

Phil Beauvoir

  • Archi Guy
  • Hero Member
  • *****
  • Posts: 1500
  • Archi Guy
    • Archi
Re: The quality of image in PDF file
« Reply #1 on: May 02, 2019, 21:11:37 PM »
I assume you are using this code in your own Jasper Reports template. Can you compare the image quality for this with the standard Jasper template image quality? The quality will be less if the image has been resized to a smaller one in the Canvas.
« Last Edit: May 02, 2019, 21:37:08 PM by Phil Beauvoir »
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

edualvim

  • Newbie
  • *
  • Posts: 4
Re: The quality of image in PDF file
« Reply #2 on: May 21, 2019, 20:11:13 PM »
Hi! I´m working with @macknardy on this automation front, and we're still suffering to solve that...

@Phill is right, we created our own report. Now we tested the same but using the standard Jasper template, but it doesn't print Canvas views.

About resizing the image, this is something we couldn't control, because at first we have to include the "Image" object in the Canvas, and later really set the file image to the object - and this image should variate its dimensions depending on the project we're working on. Anyway, we've tried using different image resolutions, up to very high.

For you to have a picture on what's the purpose of this template: we work on documenting architecture solutions, and we´re trying to automate the generation of these architecture documents. So we should include a regular archimate diagram (Applications/Functions mapping), write some texts (like on Model´s Purpose and Canvas Documentation Main property) and include an external image, usually exported from a Visio document. And doing all this within Archi's Model, have an automation that creates the entire document in PDF.

Our main challenge were exactly where and how to include this external image to Archi´s Model in a way it could be printed together on the PDF. And the Canvas/Image was the closer solution we've found for that.

So, if you mind help us, either analizing the example I´ve attached here(*) to figure out how we implemented that, or suggesting another way to have an external image being included with quality in a report, we'd be very grateful!
(*) We attached Archi Model example template, an example of png (could be any other image) and Jasper XMLs.


*some non-important output texts are in Portuguese in the template.
« Last Edit: May 22, 2019, 19:54:35 PM by edualvim »

Phil Beauvoir

  • Archi Guy
  • Hero Member
  • *****
  • Posts: 1500
  • Archi Guy
    • Archi
Re: The quality of image in PDF file
« Reply #3 on: May 21, 2019, 20:26:34 PM »
And if you use Jasper to export to one of the other formats such as HTML, is the image quality still bad?

(It might be a problem with the PDF export library used by Jasper. I'm not an expert on this so perhaps this is something that someone could investigate?)
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

edualvim

  • Newbie
  • *
  • Posts: 4
Re: The quality of image in PDF file
« Reply #4 on: May 22, 2019, 15:29:14 PM »
And if you use Jasper to export to one of the other formats such as HTML, is the image quality still bad?

(It might be a problem with the PDF export library used by Jasper. I'm not an expert on this so perhaps this is something that someone could investigate?)

Good point... if I export to HTML the image quality is good. I've just verified it also transforms the original PNG to a smaller PNG file when creating HTML version, but quality remains good. I suspected of this possibility about PDF exporting library too... Someone have any idea?

Phil Beauvoir

  • Archi Guy
  • Hero Member
  • *****
  • Posts: 1500
  • Archi Guy
    • Archi
Re: The quality of image in PDF file
« Reply #5 on: May 22, 2019, 15:55:15 PM »
There's not much I can do about it as far as I can tell. Perhaps it is related to the algorithm used by Jasper Reports PDF library?

Try a Google search for "jasper report pdf image quality" and you'll find results like this:

https://stackoverflow.com/questions/4657238/jasperreport-scales-images-when-exporting-to-pdf-thus-losing-quality

You could try an experiment to hard code an image into the jrxml file.

In my experiments the larger and higher resolution the original image is, the better.

The Archi Java code to export is simply this:

Code: [Select]
JasperExportManager.exportReportToPdfFile(jasperPrint, file.getPath());

So unless someone knows a parameter or setting, I don't know.
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

Jean-Baptiste Sarrodie

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 647
  • Archi Evangelist and Contributor. Visionary.
    • About me...
Re: The quality of image in PDF file
« Reply #6 on: May 22, 2019, 20:27:55 PM »
Hi,

I've just had a look...

@Phill is right, we created our own report. Now we tested the same but using the standard Jasper template, but it doesn't print Canvas views.

The standard report template does print Canvas views... unless you explicitly ask it not to do so... which you have done by adding the Report:View:Hide property set to true in each Canvas.

About resizing the image, this is something we couldn't control, because at first we have to include the "Image" object in the Canvas, and later really set the file image to the object - and this image should variate its dimensions depending on the project we're working on. Anyway, we've tried using different image resolutions, up to very high.
[...]
Our main challenge were exactly where and how to include this external image to Archi´s Model in a way it could be printed together on the PDF. And the Canvas/Image was the closer solution we've found for that.

Canvas are really the way to go I've done similar things (adding screenshots and other images in Canvas) for the past 5 years without any issue.

So, it seems that your issue is just (at least in your example) that the images in the Canvas are a bit too small (there are already blurry in Archi). Making them bigger in the Canvas allowed me to generate a report which is less blurry (see attachements).

You can get a good idea of the ideal image size by understanding how all this works in Jasper. Jasper report will always generate a report using a resolution of 72 dpi for images. That's the reason why the background and header images provided with default template are 595 pixels wide (595px / 72dpi = 8,26in = 21cm which is the short size of an A4 sheet of paper). Now, jasper will use internal Archi's rendering to get the image before adding it to the report, so to know the size of the generated image you basically have to get the size of you image object inside the view (you can set and show the grid for that) and add 20px on each side (Archi always adds a 10px white borders on exported views). Last, depending on how you decided to use you image in jasper, jasper will either use your image unchanged at 72dpi (so it might be too small or too big) or will scale it down to make it fully visible.

The best image size would be the one which makes sure that it doesn't get resized. If this can't be done,than at least your imported (ie. original) image should be bigger than the available size (jasper report's width minus report's margins in inches, divided by 72dpi) minus 20px (archi's view margins).

If that's still too blurry for you,you can trick jasper by creating a template which uses a very big size (20 or 30 inches) and use bigger fonts accordingly. This will still display as usual on screen (and you can still print it easily as most PDF viewer will scale it down when printing), but internally you'll have more pixels  available because 72dpi on more inches lead to more pixels ;-)

Regards,

JB
« Last Edit: May 23, 2019, 06:37:28 AM by Jean-Baptiste Sarrodie »
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

Phil Beauvoir

  • Archi Guy
  • Hero Member
  • *****
  • Posts: 1500
  • Archi Guy
    • Archi
Re: The quality of image in PDF file
« Reply #7 on: May 22, 2019, 20:34:34 PM »
Thanks, JB, that's very helpful.

One other thing I found when searching Google was this setting:

net.sf.jasperreports.image.dpi=300

This can be added to the "jasperreports.properties" file in the Archi installation path "plugins/com.archimatetool.jasperreports_XXXXXXXXX"

I tried it but it didn't seem to help.
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

edualvim

  • Newbie
  • *
  • Posts: 4
Re: The quality of image in PDF file
« Reply #8 on: May 22, 2019, 22:00:32 PM »
Really, very helpfull, JB! We'll spend some more time exploring the points you suggested. Any new we return here, thanks a lot! Phil too!

edualvim

  • Newbie
  • *
  • Posts: 4
Re: The quality of image in PDF file
« Reply #9 on: May 28, 2019, 20:23:35 PM »
Hi everyone,
After performing lots of tests, exercising Archi configurations and different image formats/resolutions/sizes... our conclusion converged to JB's quote: "the images in the Canvas are a bit too small". At first I thought it was about the size of source image file, but it was about the image object inside Canvas view!  :o

So, even working with very high res images/formats, and manipulating net.sf.jasperreports.image.dpi parameter, but not changing image object, the result in PDF was always... blur...
When I increased the image object dimensions (width/height) in the Canvas... voilà! Bluring has gone!

It seems like, if I place the object too small in Canvas, even associating it to a high res image it downscales the image to fit the object, and later enlarges the object to fit to the PDF page (so the resolution is reduced). And if I do the opposite, the result is satisfactory because, even if the image is too wide, when creating the PDF there wasn't a previous downscaling (probabily an upscalling?).

Great, now we can proceed with our automation project, thank you very much!