cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with emailing dynamically generated PDF (InteractiveForm UI element)

former_member183915
Active Contributor
0 Kudos

Hi Experts ,

I have a requirement according to which i need to generate PDF dynamically using webdynpro java and email the dynamically generated PDF.

I am facing issue while emailing the dynamically genarated pdf.

It gives me an exception :

nested exception is: javax.mail.MessagingException: IOException while sending message; nested exception is: java.io.IOException: no data

This is because its unable to get the binary data (byte array) of the dynamically generated PDF which is required to send mail.

Could some one suggest me how to fetch the binary data of the dynamically generated PDF.

For dynamic PDF generation i am using dynamic generation of UI element InteractiveForm UI Element

In case of static PDF (i.e. the PDF genarated by inserting the InteractiveFrom Ui element on the view using the insert child option) we do set the pdf source property of Interactive Form UI element to a context variable attribute of type binary but my problem is ,how to set the PDF source of a dynamically generated Interactive form UI element to a context variable attribute of type binary ..

Any help would be highly appreciated.

Regards ,

Navya

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member183915
Active Contributor
0 Kudos

Hi ,

I tried the solution provided.

It worked for me.

Thanks for the quick reply.

I had missed out one point i.e. placing the .xdp file in the components folder .

I have assigned appropriate points.

Regards ,

Navya.

Former Member
0 Kudos

You don't need the UI-Element to generate the PDF, you can use some API. The source could look like

ByteArrayOutputStream templateSourceOutputStream = new ByteArrayOutputStream();

// This would need to have the Templatefile in the Mimes-Directory of the Webdynpro-Component

String templateUrl = WDURLGenerator.getResourcePath(wdComponentAPI.getDeployableObjectPart(), "<MY_TEMPLATE>.xdp");

InputStream templateSourceInputStream = new FileInputStream(templateUrl);

IOUtil.write(templateSourceInputStream, templateSourceOutputStream);

IWDPDFDocumentCreationContext pdfContext = WDPDFDocumentFactory.getDocumentHandler().getDocumentCreationContext();

pdfContext.setData(WDInteractiveFormHelper.getContextDataAsStream(wdContext.<MY_PDF_DATA_NODE>()));

pdfContext.setTemplate(templateSourceOutputStream);

pdfContext.setInteractive(false);

IWDPDFDocument pdf = pdfContext.execute();

if (pdf != null) {

byte[] pdfArray = pdf.getPDF();

// now going to send

}

former_member183915
Active Contributor
0 Kudos

Hi Frank ,

the code to generate PDF dynamically is written in the WdDoModifyView section of the view as the PDF need to be generated dynamically., i.e. by adding InteractiveForm UI elements at runtime.

I tried the code suggested by you but i gave mean exception.

errorjava.io.FileNotFoundException:

(The system cannot find the path specified)

Kindly let me know where i am going wrong .

Below is the code that i had written in a separate method m_mail().

This would take as input the name of the dynamically generated data node and is called from the wdDoModifyView section of the view



 public void m_mail( java.lang.String p_dynamicnodeName )
{

			ByteArrayOutputStream templateSourceOutputStream = new ByteArrayOutputStream();
		//	   This would need to have the Templatefile in the Mimes-Directory of the Webdynpro-Component
			String templateUrl = WDURLGenerator.getResourcePath(wdComponentAPI.getDeployableObjectPart(), "AdobeView1_InteractiveForm.xdp");
				
			InputStream templateSourceInputStream = new FileInputStream(templateUrl);
			IOUtil.write(templateSourceInputStream, templateSourceOutputStream);
			IWDPDFDocumentCreationContext pdfContext = WDPDFDocumentFactory.getDocumentHandler().getDocumentCreationContext();
			pdfContext.setData(WDInteractiveFormHelper.getContextDataAsStream(wdContext
			.nodeCtx_vn_dynmcnd()
			.getChildNode(p_dynamicnodeName, IWDNode.NO_SELECTION)));
			pdfContext.setTemplate(templateSourceOutputStream);
			pdfContext.setInteractive(false);
				
			IWDPDFDocument pdf = pdfContext.execute();
			if (pdf != null) {
			 pdfArray = pdf.getPDF();
			}

}

Kindly let me know where am i going wrong.

Regards ,

Navya