cancel
Showing results for 
Search instead for 
Did you mean: 

Generate form with prefilled data without displaying the form - WDJ

Former Member
0 Kudos

Hi ,

I have a requirement where I have to generate an interactive form that is populated with some data from wd context. My requirement is that I need to download this prepopulated form without displaying it on the browser.

Eg. The wd application loads on the browser, the view of this application contains a link/button/file download element , on click of this element some data gets generated in the background and this data gets stored in an interactive form. A pop-up should now appear giving options to the user to either open or save this form.

Please let me know options to achieve this.

Thanks,

Lisha

Accepted Solutions (1)

Accepted Solutions (1)

marcel_frei
Participant
0 Kudos

The following code may not be the best solution but it does work.

You have to create the variable dataNode as com.sap.tc.webdynpro.progmodel.api.IWDNode. That is the datasource you have defined in your interactive form ui element. The template name has to be the same as configured in your interactive form ui element.

The following code will open the pdf in a new browser window. I you don't want to do that you can leave the part after byte[] pdfbyte = pdfDocument.getPDF(); away and write the bytes to a file instead.

I hope this helps.


String templateName = "myTemplate.xdp";
IWDPDFDocumentHandler documentHandler = WDPDFDocumentFactory.getDocumentHandler();
		IWDPDFDocumentCreationContext creationContext = documentHandler.getDocumentCreationContext();
		creationContext.setDynamic(false);
		creationContext.setInteractive(false);

ByteArrayOutputStream templateSourceOutputStream =
				new ByteArrayOutputStream();
//get template file as InputStream
String filePath = WDURLGenerator.getPublicResourcePath(wdComponentAPI.getDeployableObjectPart(), templateName);
InputStream templateSourceInputStream = new FileInputStream(new File(filePath));
//convert InputStream to OutputStream
IOUtil.write(templateSourceInputStream,
				templateSourceOutputStream);
templateSourceInputStream.close();
  
creationContext.setTemplate(templateSourceOutputStream);
ByteArrayOutputStream dataStream = com.sap.tc.webdynpro.clientserver.adobe.api.WDInteractiveFormHelper.getContextDataAsStream(dataNode);			
creationContext.setData(dataStream);
IWDPDFDocument pdfDocument = creationContext.execute();

byte[] pdfbyte = pdfDocument.getPDF();

final IWDResource resource = WDResourceFactory.createCachedResource(pdfbyte,pdfName,WDWebResourceType.PDF);
//pop up
String url;
url = resource.getUrl(WDFileDownloadBehaviour.AUTO.ordinal());

IWDWindow window = wdComponentAPI.getWindowManager().createNonModalExternalWindow(url,"value");
window.show();

Answers (2)

Answers (2)

Former Member
0 Kudos

Issue solved Marcel

Assigned full points to you!

Regards,

Lisha

Former Member
0 Kudos

Hi Marcel,

Thanks a lot for this quick response!

Wil try this out and let you know

Regards

Lisha

marcel_frei
Participant
0 Kudos

I didn't mention that this works with NW 7.0, don't know if it's also working with NW CE.