cancel
Showing results for 
Search instead for 
Did you mean: 

How to add image in PDF using JspDyn and what is the path to keep images

Former Member
0 Kudos

Hi anyone help me out to get this issue solved...

I'm creating PDF on the fly but I'm unable to get the image in it. It says Invalid path if i give the path like this Image image =new Image( request.getWebResourcePath() + /images/MyLogo.gif","picture Mylogo.gif");

And also I have tried like this

com.lowagie.text.Image img = com.lowagie.text.Image.getInstance("MyLogo.gif"); document.add(img);

I have kept the image in /images folder.

Still i'm facing path problem....

Please guide me to resolve this issue..

Regards,

Joseph

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

you can try like this..

<%

IResource rs = componentRequest.getResource(IResource.IMAGE, "../mimes/mypicture.gif");

image.setSrc(rs.getResourceInformation().getURL(componentRequest));

%>

Regards,

Karthick

detlev_beutner
Active Contributor
0 Kudos

Hi Karthick,

none of your suggestions will work, for the scenario is that the image is needed on server side for building a PDF with it, not to pass a URL reference to client side!

Best regards

Detlev

Former Member
0 Kudos

Hi Detlev,

I've also tested it and its not getting the image.

Can you give me some sample code to achieve this.

Regards,

Karthick

detlev_beutner
Active Contributor
0 Kudos

Hi Karthick,

req.getPrivateResourcePath returns for example:

<i>C:\usr\sap\J2E\JC00\j2ee\cluster\server0\apps\sap.com\irj\servlet_jsp\irj\root\WEB-INF\portal\portalapps\TestPortalApplication</i>

Now add your images path and image name to this path and you can access the file as per standard Java IO.

That's what has been needed in this thread.

Hope it helps

Detlev

Former Member
0 Kudos

Hi Detlev,

Can you make it some more clear with sample code, how to create and put image in a specific folder on the server and how to access that image.

Thanks,

Joseph

detlev_beutner
Active Contributor
0 Kudos

Hi Joseph,

the code is given above, it's as easy as described. If you put your image into your NWDS portal project under dist/PORTAL_INF/images (create that last folder), just add "images/yourImage.gif" to the path retrieved. This is the scenario if you only want to access the image on server side. If you also want to offer the image from client side (not described in your question), put it under dist/images and use getPublicResourcePath() instead for server side access.

Hope it helps

Detlev

Former Member
0 Kudos

Hi Detlev,

I have tried the two options you said...but same problem persists..."no such directory/path exists"

Any other suggestion please..

Thanks,

Joseph

Former Member
0 Kudos

Hi Joseph,

Your images will be stored under..

NWDS path :

dist/images/your_image.gif

Server path:

E:\usr\sap\DP4\JC04\j2ee\cluster\server0\apps\sap.com\irj\servlet_jsp\irj\root\portalapps\your_par_name\images\your_image.gif

you can access the image from this server path..

->

request.getPrivateResourcePath() will give you the path upto ..

E:
usr
sap
DP4
JC04
j2ee
cluster
server0
apps
sap.com
irj\servlet_jsp
irj
root
WEB-INF
portal
portalapps\

come back 2 directories back upto..

root\your_par_name\your_image_name

Try this and let me know.

Hope it helps.

Regards,

Karthick

detlev_beutner
Active Contributor
0 Kudos

Hi Joseph, hi Karthick,

the path you have decribed, Karthick, to put and to retrieve the image, is the one to be used when using <i>getPublicResourcePath()</i>, not when using getPrivateResourcePath().

When using getPrivateResourcePath(), put - as already described - the image under dist/PORTAL_INF/images.

@Joseph: It definitely works! Please debug your code if it still doesn't, tell us what getXXXResourcePath returns, check the path on your system etc pp. "Does not work" is <i>always</i> an error description almost nobody can work on...

Hope it helps

Detlev

Former Member
0 Kudos

Hi Karthik,

Thanks for you valuable suggestions.

I have done this in another way by putting the image in the server and by accessing the URL , I got the image in PDF.

Regards,

Joseph

Former Member
0 Kudos

Hi Detlev,

Thanks for you valuable suggestions.

I have done this in another way by putting the image in the server and by accessing the URL , I got the image in PDF.

Regards,

Joseph

Former Member
0 Kudos

Hi Joseph,

You have to Keep your image under dist/images/MyLogo.gif.

In your jsp access the image like this.

javascript:

var imgSrc = '<%= componentRequest.getWebResourcePath() %>/images/MyLogo.gif;

<img src="imgSrc" />

Hope it helps.

Regards,

Karthick

detlev_beutner
Active Contributor
0 Kudos

Hi Joseph,

see https://media.sdn.sap.com/javadocs/NW04/SPS15/ep/com/sapportals/portal/prt/component/IPortalComponen... (or getPrivate...()).

Starting with this, you can access the file.

Hope it helps

Detlev

PS: Please consider rewarding points for helpful answers on SDN. Thanks in advance!