How to insert an image into a BIRT report with an URL properly?

回眸只為那壹抹淺笑 提交于 2019-12-11 03:43:18

问题


I inserted an image from the web into a BIRT report using an URL in Eclipse, but it doesn't work. It displays a little red X on the Layout screen, and if I choose Run/View Report/As PDF it says "The resource of this report item is not reachable."

What is the problem here? I have googled for hours but found nothing.

Thanks in advance for any help!


回答1:


Try adding image from web which you can access via your browser. That way you'll assure yourself you don't have problems with accessing your image via URI.

For example add this URL

http://hajduk.hr/sadrzaj/slike-za-vijesti/640x320/2010-06-08-jerkovic.jpg

and you see the image in your report:

Other way to include your image as embedded image in report file. On this snippet

you can see how to add image to your report file. After you do it, bind your image element which displays little red icon with your embedded image. Do this by double clicking the image element on report and from dialogue which will popup chose embedded image.

From this second snippet, you see that you can include image from Shared resources which comes in handy if you have more reports with same image on it. For instance logo of your client, your company logo etc.




回答2:


Using Dynamic Images in Birt Report

Steps:

1) Create class

class BirtReport {
   public byte[] imageLogo;
}

2) Convert your image into bytes

public byte[] readImagesBytes(String url) {
     byte[] imageBytes = new byte[5024];
     try {
            // Apachae IOUtils
            imageBytes = IOUtils.toByteArray(new URL(url));
     } catch (IOException e) {
            imageBytes = new byte[0];
     }

     return imageBytes;
}

BirtReport birtReport = new BirtReport();
birtReport.imageLogo = readImagesBytes("http://www.underconsideration.com/brandnew/archives/google_2015_logo_detail.png");


3) In the Birt Report create Data Set

   BirtReportData with Blog type of imageLogo


Create the Data Set with imageLogo of Blog Data Type in Birt Report. Convert the image into bytes from server side. 
I have solved "The resource of this report item is not reachable" error


来源:https://stackoverflow.com/questions/25264555/how-to-insert-an-image-into-a-birt-report-with-an-url-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!