cancel
Showing results for 
Search instead for 
Did you mean: 

Download generated PDF

Former Member
0 Kudos

Hi all,

I am using the FileDownload UI element to download the Interactive Form that the system have generated.

In my view, I have place an Interactive Form and bind it to a dataSource (binary). My FileDownload UI element has the data property binded to the dataSource as well.

The user does not see the pdf file but instead sees the download link to the file.

I am setting the height and width pixel of the interactive form to be 0px.

Is this the correct way of doing this? Appreciate any advice.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

My requirement now is to create a Table UI element which contains a Column with the FileDownload UI element as the Table cell editor.

When i click on the FileDownload UI element the pdf form containing data of that row should be displayed.(via Open/Save/Cancel options)

I tried using the onDemand Streaming technique that was mentioned in the tutorial https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b0e10426-77ca-2910-7eb5-d7d8982c...

However if i use the code of the previous message i am not able to get any output.

Could you guide me as to what code should i put in the getter of the calculated attribute and whether the create0BytesResource() method is required if i am implementing the code of the previous message.

Is there a way that i can achieve the above functionality when using a File Download in table.

Any alternate solution will also be helpful.

Former Member
0 Kudos

Hi all,

I chanced upon this thread.

Link: [;


import com.sap.tc.webdynpro.clientserver.adobe.pdfdocument.api.IWDPDFDocument;
import com.sap.tc.webdynpro.clientserver.adobe.pdfdocument.api.IWDPDFDocumentCreationContext;
import com.sap.tc.webdynpro.clientserver.adobe.pdfdocument.api.WDPDFDocumentFactory;
import com.sap.tc.webdynpro.basesrvc.util.IOUtil;
...

InputStream template = ... //your XDP file as an inputstream
String xmlData = ... //business data you want to merge your form template with
ByteArrayInputStream dataSourceInputStream = new ByteArrayInputStream(xmlData.getBytes());
ByteArrayOutputStream dataSourceOutputStream = new ByteArrayOutputStream();
ByteArrayOutputStream templateSourceOutputStream = new ByteArrayOutputStream();
// convert InputStream to OutputStream
IOUtil.write(template, templateSourceOutputStream);
IOUtil.write(dataSourceInputStream,dataSourceOutputStream);
IWDPDFDocumentCreationContext creationContext = WDPDFDocumentFactory.getDocumentHandler().getDocumentCreationContext();
creationContext.setTemplate(templateSourceOutputStream);
creationContext.setData(dataSourceOutputStream);
creationContext.setDynamic(true); //if you want to create dynamic interactive form
IWDPDFDocument pdfDoc = creationContext.execute();
// create the PDF and store it as ByteArrayInputStream
InputStream pdfInputStream = pdfDoc.getPDFAsStream();

What should be the relative pathname of the xdp and xml path?

How does the xml file knows which field to bind onto the XDP template?

regards.

Former Member
0 Kudos

Managed to resolve it and sharing with the forum.


//template.xdp is kept in src\mimes\Components\<package name>
String templateUrl = WDURLGenerator.getResourcePath(wdComponentAPI.getDeployableObjectPart(),"template.xdp");
InputStream template  = new FileInputStream(templateUrl);
ByteArrayOutputStream templateSourceOutputStream = new ByteArrayOutputStream();
IOUtil.write(template, templateSourceOutputStream);
		
IWDPDFDocumentCreationContext pdfContext =	WDPDFDocumentFactory.getDocumentHandler().getDocumentCreationContext();
		
//map the Datasource node to the XDP template
pdfContext.setData(WDInteractiveFormHelper.getContextDataAsStream(wdContext.nodeDataSource()));
pdfContext.setTemplate(templateSourceOutputStream);

IWDPDFDocument pdf = pdfContext.execute(); //the PDF is created
IWDWebResource pdfResource = WDWebResource.getWebResource(pdf.getPDF(), WDWebResourceType.PDF); 
//pdfResource element is bounded to FileDownload UI element resource property
wdContext.currentContextElement().setPdfResource(pdfResource); 

Former Member
0 Kudos

Hi,

I have a similar requirement where an adobe form needs to be created and instead of displaying the adobe form on the view to the user i need to show the 'Open/Save/Cancel' options (of Windows dialog) so that the user can either open or save the generated pdf.

For this i have created an interactive form UI element. Bound the value node 'TestNode' to dataSource property and value attribute 'pdfsource' of type binary to the pdfSource property of the Interactive Form UI element. Gave height and width as 0px.

Created a FileDownload UI element. Bound the data property to the value attribute 'pdfsource' (created above) and the resource property to a value attribute 'FileResource' of type com.sap.ide.webdynpro.uielementdefinitions.Resource.

Hence the Context is as follows :

Context

|__TestNode <--- VN

|__FileResource <-- VA

|__pdfsource <-- VA

In the wdDoInit() of the view i added the code that you have provided .

However when i deploy and run the application and click on the FileDownload , nothing happens. It seems that the FileDownload link does not get clicked at all.

Could you please provide me with the solution.

Former Member
0 Kudos

Hi,

Managed to solve the issue.

The .xdp file needs to be in the following path:

src\mimes\Components\<package name>

When we create an Interactive Form in the view the .xdp file is saved in the path :

src\configuration\Components\<package name> by default.

Hence i made a copy of the .xdp file and kept it in the mimes path.

Former Member
0 Kudos

Hi SAP noob,

I got a "PDFDocument Processor failed to process Render Request" error when I executed the "IWDPDFDocument pdf = pdfContext.execute(); //the PDF is created" I found this thread and they told that I need a .pfx-file. Did you need or hear something about this.

Regards,

Orlando Covault

Former Member
0 Kudos

Hi noob,

I am trying to use your suggestion about the "IWDPDFDocument pdf = pdfContext.execute();" but I got a "java.net.MalformedURLException: no protocol:" This is my code.

String url = "";

try {

WDPDFDocumentProtectPermission[] permissions =

{

WDPDFDocumentProtectPermission.PRINT_NOT_ALLOWED,

WDPDFDocumentProtectPermission.CHANGES_NOT_ALLOWED };

IWDPDFDocumentCreationContext pdfContext =

WDPDFDocumentFactory

.getDocumentHandler()

.getDocumentCreationContext();

pdfContext.setProtection(null, null, permissions);

pdfContext.setData(doc_content);

String templateUrl =

WDURLGenerator.getResourcePath(

wdComponentAPI.getDeployableObjectPart(),

"template.xdp");

InputStream template = new FileInputStream(templateUrl);

ByteArrayOutputStream templateSourceOutputStream =

new ByteArrayOutputStream();

IOUtil.write(template, templateSourceOutputStream);

pdfContext.setTemplate(templateSourceOutputStream);

IWDPDFDocument pdf = pdfContext.execute();

WDWebResourceType webResType = WDWebResourceType.PDF;

IWDWebResource webResource =

WDWebResource.getWebResource(pdf.getPDF(), webResType);

url = webResource.getURL();

} catch (...all the catch....

return url;

The doc_content is a byte[] that I got in a RFC from a SmartForm. Any idea that what could be wrong

Regards,

Orlando Covault

P.D. I got a new thread under

Edited by: Orlando Covault on Mar 25, 2008 9:04 PM