on 04-12-2006 11:07 AM
Hello All,
I have been following this tutorial <a href="http://sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webdynpro/tutorial%20on%20working%20with%20the%20pdf%20document%20object%20-%2032.htm">http://sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webdynpro/tutorial%20on%20working%20with%20the%20pdf%20document%20object%20-%2032.htm</a> from SDN and is currently stuck.
<u><b>What I'll like to achieve</b></u>
1) User logs on to the system and a table displaying a list of items for approval appears.
2) the user is then able to select a row item from the table and click on 'approve'. In doing so, my application should generate a pdf form in the background and attach it as an email attachment and sent that email to an appointed vendor.
<b><u>Problem</u></b>
As there is no InteractiveForm involved, I do believe I will need to provide the template (.xdp) so that the PDF can be generated. In the tutorial, it suggests doing this (I modified it a little to reflect my own path name):
InputStream templateSourceInputStream = getClass().getClassLoader().getResourceAsStream("d:
usr
sap
pdf
PDF
XBCRPDFPreviewView_InteractiveForm1.xdp");
However, I am given a NullPointerException when I attempt to do that. Does anyone has any idea what may have caused the error ? Thank you.
from
Kwok Wei
Hi Kwok,
The XDP file is stored on the server right ?
Simply, access it using -
File fileXdpTemplate = new File(filePathXdpTemplate);
FileInputStream xdpTemplateInputStream = new FileInputStream(fileXdpTemplate);
IOUtil.write(xdpTemplateInputStream,bytArrXdpOutputStream);
Thanks,
Sam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Sam,
You suggestion works like a charm. One question I'll like to ask you/fellow experts is that in the tutorial, it explicitly says that "the template (referring to the xdp file) must not be accessed through the file system. But it is possible to stream the files through the getResourceAsStream() method corresponding ClassLoader (available through getClass().getClassLoader())."
Can anyone explain why the abve sentence was made when Sam's solution works as well ?
from
Kwok Wei
Hi Kwok Wei Ng
The reason you used the file path is exactly the reason why it didnt work. Using the getClassloader().getResourceStream() you are freed from using any file path , it picks up the xdp file as long as the file is available in the classpath.
A better programming practice to free your code from any absolute references to a file.
Regards
Pran
Thanks for the answer Pran.
What I have done so far is to copy the xdp file to a self defined (somewhere in my d drive)directory in my app server. So based on your explanation, it seems that I should place the xdp file together with my deployed application ? If that is the case, do you know where should Iplace it in ? The src folder ? I tink using a filepath is ,as what you have mentioned, not a good programming practise.
from
Kwok Wei
Hi Kwok Wei ,
According to the convention the any file can be placed in the src/mimes/Components/<component package + component name>/folder of your webdynpro project along with other generated files of your application.
After this you just need to pass the filename to the getResourcestream() method,it automatically picks up the file from the folder.
Regards
Aarthi Mathivanan
Message was edited by: aarthi mathivanan
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.