I need to embed PDFs in a portlet - no big whoop - except the PDFs are generated by an IS.
I can DOWNLOAD them just fine using the export bean as there is a share on the IS that the MWS has access to but, obviously, that directory isn’t served up by the MWS.
So…
Is there a way to stream the file to a CONTROL and display it in line rather than have the browser download it?
So I’ve tried passing HTML like the below thru a WS call put the Adobe plug in doesn’t like it. It seemed like a good idea… except I was concerned about maxing out the URI lenght.
THIS IS MY HTML
Anyway, now I’m wondering if I can move the PDF from the IS to the USERS folder in the MWS taxonomy, but I don’t know how to reference it in the server side Java code. Any ideas?
You can construct a portlet action url that would stream the pdf content back to the browser. Then you can just set that portlet action URL as the target of your tag.
For example, in your page bean you could create a new java method that constructs your action URL:
public String getMyPdfActionUrl() {
try {
IPortletURL actionUrl = createActionUrl();
actionUrl.setAXSRFT(true);
actionUrl.setTargetAction("exportPDF_action");
return "fe:" + actionUrl.toString(); //prepend fe: to make url relative to the front end url instead of this webapp context
} catch (Exception e) {
error(e);
return "javscript:void(0)"; //return a do nothing url
}
}
… and the target action that the portlet action url will execute:
@PortletAction
public String exportPDF_action() {
try {
//TODO: get the PDF content from the source and create a file export bean
// See the wm_caf_misc sample from the SDK for examples
IFileExportBean exportBean = [TODO]; //TODO: create this object for your PDF data.
streamFileDataToResponse(exportBean);
} catch (Exception e) {
throw new FacesException(e);
}
return OUTCOME_OK;
}
…and then your html markup would look something like this:
<object data="#{activePageBean.myPdfActionUrl}" type="application/pdf" width="100%" height="100%">
<p>It appears you don't have a PDF plugin for this browser.
No biggie... you can <a href="#{activePageBean.myPdfActionUrl}">click here to
download the PDF file.</a></p>
</object>
Hello experts. I have a similar issue but I couldn’t solve it with your examples. Can you help me?
I have a IS Service that generates the PDF and returns it as a base64 String.
Service is called on Initialize of view. No issues.
I have created the actions:
public String getPDFActionUrl() {
try {
IPortletURL actionUrl = createActionUrl();
actionUrl.setAXSRFT(true);
actionUrl.setTargetAction("exportPDF_action");
return "fe:" + actionUrl.toString(); //prepend fe: to make url relative to the front end url instead of this webapp context
} catch (Exception e) {
error(e);
return "javscript:void(0)"; //return a do nothing url
}
}
In my view, I have an ‘Include HTML’ that refers to an html file in my project that contains. The ‘evaluate’ property is set to ‘true’
<object data="#{ModuloTesteDDTestePDFView.PDFActionUrl}" type="application/pdf" width="100%" height="100%">
<p>It appears you don't have a PDF plugin for this browser.
No biggie... you can <a href="#{ModuloTesteDDTestePDFView.PDFActionUrl}">click here to
download the PDF file.</a></p>
</object>
Removing “fe:” solved the problem, thanks! When should I use it?
Also, PDF controls (print, save, zoom etc) from the object embed are not showing. Should I add some specific parameters to my html page so the user can use those options?
Basically, if the code is inside of a CAF portlet, then the “fe:” prefix is usually not needed.
In general, the “fe:” prefix is only needed when current request is not being serviced by the main MWS servlet context. For example by some standalone CAF page in a (non-MWS) web application.
And the context where the value is used must know how to interpret the string to replace the “fe:” prefix with the real value. The ‘Image’ control and others do that automatically, but if you are using an expression in some other place it likely won’t know what to do with that.