cancel
Showing results for 
Search instead for 
Did you mean: 

Using WD APIs in Java Programming

Former Member
0 Kudos

Hi,

First let me explain my scenario:

I have to get the <b>attachments in a PDF document</b>, using a <b>java program</b>. I am using Java perspective of NWDS. I am using the APIs

->IWDPDFDocumentHandler

->IWDPDFDocumentAccessibleContext

->IWDPDFDocument

->IWDPDFDocumentAttachment

in my program.

When I run my java program, I am getting the <b>java.lang.NoClassDefFoundError</b>. Can you please, give me a solution for this problem?

Note : I have added the necessary JAR files to the project.

Thanks,

Prabhakar.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Prabhakar,

Can u send the complete stack trace. where exactly u r getting this problem??

regards

Sumit

Former Member
0 Kudos

Hi Sumit,

Here is the result which I got in the console,

java.lang.NoClassDefFoundError: com/sap/tc/webdynpro/services/exceptions/WDRuntimeException
	at PDFAttachment.readAttachmentFromPDF(PDFAttachment.java:241)
	at PDFAttachmentMain.main(PDFAttachmentMain.java:21)
Exception in thread "main"

Note :

PDFAttachment

- Class

readAttachmentFromPDF

- method

The code is,

String PDFDocName = "podetailswithAttachment.pdf";
				//wdComponentAPI.getMessageManager().reportSuccess("Outside try FileName :"+PDFDocName );
	
				try
				{
					//wdComponentAPI.getMessageManager().reportSuccess("Inside try FileName :"+PDFDocName );
					FileInputStream fileInpStrm = new FileInputStream("C:\"+PDFDocName);
					FileOutputStream fileOutStrm;// = new FileOutputStream()
		
					ByteArrayOutputStream bo = new ByteArrayOutputStream();
					int c;
					while ((c = fileInpStrm.read()) > -1)
					{ 
						bo.write(c);
	 	    		} 
					byte[] pdfSource = bo.toByteArray();
// Line :240	
					IWDPDFDocumentHandler pdfdocHandler =WDPDFDocumentFactory.getDocumentHandler();
					
					IWDPDFDocumentAccessibleContext pdfdocaccContext = pdfdocHandler.getDocumentAccessibleContext();
					pdfdocaccContext.setPDF(bo);
					IWDPDFDocument pdfDocument = pdfdocaccContext.execute();
					IWDPDFDocumentAttachment[] pdfatt =   pdfDocument.getAllAttachments();
	
					//wdComponentAPI.getMessageManager().reportSuccess("Length of the attachments: "+pdfatt.length);
					//pdfdocaccContext.setPDF();
	
				}
				catch(Exception e)
				{
					//wdComponentAPI.getMessageManager().reportSuccess(""+e);
					System.out.println(""+e);
				}

Thanks,

Prabhakar.

Former Member
0 Kudos

When I use this same code in WebDynpro, all those lines are executing properly, except the call to

getAllAttachments()

. There I am getting "

NoSuchMethodError

".

Former Member
0 Kudos

Can you tell us what you want to achieve? The NoSuchMethodError indicates a version mismatch. But I have the impression you try to use some Web Dynpro functionality outside of the Web Dynpro runtime. This will definitely not work.

Armin

Former Member
0 Kudos

Hi,

As I have mention earlier in this thread, my requirement is, to get the attachments in a PDF document, using a java program. Is there any Plugins(API) provided by SAP for that?

Thanks,

Prabhakar.

Answers (0)