on 06-11-2009 8:50 AM
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
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();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Issue solved Marcel
Assigned full points to you!
Regards,
Lisha
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Marcel,
Thanks a lot for this quick response!
Wil try this out and let you know
Regards
Lisha
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
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.