Showing posts with label jasper. Show all posts
Showing posts with label jasper. Show all posts

Jasper Reports PDF image quality (blurry and poor) solution

Recently I had to create a PDF Jasper Report that contained a lot of small images (I needed to represent checkboxes); however upon generating the PDF the image quality was really awful since for some reason they were been scaled (even though I had configured the report to show them in real size and the image was the same dimensions as its placeholder)

I spent quite some time searching for a solutions, one popular one was to add the following parameter either to the report as a property or in the jasperreports.properties in the CLASSPATH to be picked up by the engine but to no avail.

In the end after searching and reading different threads I found 2 solutions that work :

1. Convert your PNG to SVG

You can convert your PNGs to SVGs either by using something like Adobe Ilustrator or something similar or you can also head up to this website : PNG to SVG converter and follow the instructions

You can then place your SVGs in the appropriate folder in your application where you can pass the path of the image as a parameter when filling the report; you will also have to modify the source of your JRXML like so to use the SVG format in your report :







However this approach stopped working when I upgraded to JasperReports 5.6.1

2. Create a larger version of your PNG

This is the final solution I used since the previous one stopped working when I upgraded

This one is pretty straight-forward just create an image 400% larger than the image place-holder (hopping you have an original image that is bigger otherwise you'll end up loosing quality in the process).

For example if you take the example before where the image place holder dimensions where 15px - 15px I created an image whose dimensions where 60px - 60px and that was it.

Access jasper reports with URL authentication and remove jasper decoration for better integration

To give you some context recently while working on a new small project I needed to include a few Jasper Reports that where hosted in a Jasper Serverrepository. The main requirement was to include these reports in a lightweight application without the JAVA stack but using only HTML+JavaScript

To my knowledge there are 3 ways to accomplish this :

  1. Allow anonymous access to a given URL pattern (I had some troubles working with this approach)
  2. Use Jasper's REST APIand authenticate through it (probably the cleaner way)
  3. Provide credentials in the URL (quick and dirty) :)

For reasons outside the scope of this article I had to use the 3rd option and provide the credentials in the URL.

Note : This is not a clean way to access the repository (especially as you may see the username and password are clear text) but sometimes there no way around it

Jasper server uses spring under the hood to provide authentication/authorization so you can use the standard Java authentication mechanism, which basically consists in providing the following parameters in the URL :

  • j_username
  • j_password
  • j_acegi_security_check (this one is optional depending on the Jasper Server version)

If your Jasper Server is configured using an organization you will need to provide it as long with your credentials using the special syntax j_username=myUsername|myOrganization

So for example if the base url for your report is the following :

http://my-jasperserver/flow.html?_flowId=viewReportFlow&standAlone=true&_flowId=viewReportFlow&ParentFolderUri=%2Freports%2Fsamples&reportUnit=%2Freports%2Fsamples%2FStandardChartsEyeCandyReport

And your credentials are :

  • username : jasperadmin
  • organization : myOrg
  • password: jasperadmin

Your URL will become :

http://my-jasperserver/flow.html?_flowId=viewReportFlow&standAlone=true&_flowId=viewReportFlow&ParentFolderUri=%2Freports%2Fsamples&reportUnit=%2Freports%2Fsamples%2FStandardChartsEyeCandyReport&j_acegi_security_check&j_username=jasperadmin|myOrg&j_password=jasperadmin

One last thing.By default when showing a report you will get all of Jasper Server decoration around it (menubars, links, etc.) you can get rid of this by appending the one of following parameters to the URL (please note that parameters are not the same depending on which version of Jasper you are using : Community or Corporate)

  • Remove jasper decoration in community version : &decorate=no
  • Remove jasper decoration in corporate version : &theme=embed&viewAsDashboardFrame=true

OSX show used ports or listening applications with their PID

On OSX you can display applications listening on a given port using the lsof the commands described below will show listening application...