掲示板
Add "export to PDF/Excel" button in custom portlet
12年前 に Emilio José Lamas Fraga によって更新されました。
Add "export to PDF/Excel" button in custom portlet
Junior Member 投稿: 57 参加年月日: 11/11/29 最新の投稿
Hello everyone!
I´m facing a problem trying to implement a "export to PDF" button in a custom portlet.
I was trying to copy the logical from the Web Content Display portlet (i have an OpenOffice server running and the button works well) but the problem is
that in my portlet i cannot call the action that generates the PDF (com.liferay.portlet.journalcontent.action.ExportArticleAction) because it's in portal-impl, but not in portal-service. I cannot copy the method that creates the PDF neither for the same reason (it uses several imports i can't reach from my portlet)
Any ideas of how to do that?
And -being more general- How can you use in your custom portlets code from packages which are in portal-impl.jar, but not in portal-service.jar?
Thanks in advance!
I´m facing a problem trying to implement a "export to PDF" button in a custom portlet.
I was trying to copy the logical from the Web Content Display portlet (i have an OpenOffice server running and the button works well) but the problem is
that in my portlet i cannot call the action that generates the PDF (com.liferay.portlet.journalcontent.action.ExportArticleAction) because it's in portal-impl, but not in portal-service. I cannot copy the method that creates the PDF neither for the same reason (it uses several imports i can't reach from my portlet)
Any ideas of how to do that?
And -being more general- How can you use in your custom portlets code from packages which are in portal-impl.jar, but not in portal-service.jar?
Thanks in advance!
12年前 に jelmer kuperus によって更新されました。
RE: Add "export to PDF/Excel" button in custom portlet
Liferay Legend 投稿: 1191 参加年月日: 10/03/10 最新の投稿
ExportArticleAction uses com.liferay.portlet.documentlibrary.util.DocumentConversionUtil but that same class can also be accessed via com.liferay.portal.kernel.util.DocumentConversionUtil which is in portal-service.jar. So available to plugins
Additionally you can use PortalClassInvoker to call methods on classes in portal-impl.jar, but that is considered bad style. though sometimes unavoidable
Additionally you can use PortalClassInvoker to call methods on classes in portal-impl.jar, but that is considered bad style. though sometimes unavoidable
12年前 に Emilio José Lamas Fraga によって更新されました。
RE: Add "export to PDF/Excel" button in custom portlet
Junior Member 投稿: 57 参加年月日: 11/11/29 最新の投稿
Hi Jelmer!
That was helpful, thank you so much!, but I´m afraid I'm still stuck...
At this moment, I'm just trying to generate a PDF that contains a simple line of text. I have the next code on my portlet action:
I'm not sure if the StringBuilder structure is necessary, but i'm just following ExportArticleAction, from the journalcontent Portlet.
No errors in console, but the PDF file it's not created. Instead of that, the browser shows a new file full of unencoding characters.
If I change the extension from "pdf" to "txt" in the previous lines like this:
A TXT file is created properly, but containing the HTML code of the portlet which i'm calling the action. No signs from the content of the StringBuilder.
Any ideas? What i'm doing wrong?
That was helpful, thank you so much!, but I´m afraid I'm still stuck...
At this moment, I'm just trying to generate a PDF that contains a simple line of text. I have the next code on my portlet action:
String cadena = "test";
StringBundler sb = new StringBundler(12);
sb.append("");
sb.append("");
sb.append("<meta content="\"");" sb.append(ContentTypes.TEXT_HTML_UTF8); sb.append("\" http-equiv="\"content-type\"">");
sb.append("<base href="\"");" sb.append(themeDisplay.getPortalURL()); sb.append("\">");
sb.append("");
sb.append("");
sb.append(cadena);
sb.append("");
sb.append("");
HttpServletRequest servletRequest = PortalUtil.getHttpServletRequest(request);
HttpServletResponse servletResponse = PortalUtil.getHttpServletResponse(response);
InputStream is = new UnsyncByteArrayInputStream(sb.toString().getBytes(StringPool.UTF8));
FileInputStream fis = (FileInputStream) DocumentConversionUtil.convert(cadena, is, "html","pdf");
response.setWindowState(LiferayWindowState.EXCLUSIVE);
String fileName = "name.pdf";
String contentType = MimeTypesUtil.getContentType(fileName);
ServletResponseUtil.sendFile(servletRequest, servletResponse,fileName, fis,contentType);
I'm not sure if the StringBuilder structure is necessary, but i'm just following ExportArticleAction, from the journalcontent Portlet.
No errors in console, but the PDF file it's not created. Instead of that, the browser shows a new file full of unencoding characters.
If I change the extension from "pdf" to "txt" in the previous lines like this:
FileInputStream fis = (FileInputStream) DocumentConversionUtil.convert(cadena, is, "html","txt");
String fileName = "name.txt";
A TXT file is created properly, but containing the HTML code of the portlet which i'm calling the action. No signs from the content of the StringBuilder.
Any ideas? What i'm doing wrong?
11年前 に Ben Carson によって更新されました。
RE: Add "export to PDF/Excel" button in custom portlet
Junior Member 投稿: 25 参加年月日: 12/01/09 最新の投稿
Hi Emilio,
Did you ever get this figured out? If you did, posting your solution here would be really helpful.
Thanks,
Ben
UPDATE: well I figured out what I was doing wrong. I didn't have OpenOffice services running:
https://www.liferay.com/documentation/liferay-portal/6.1/user-guide/-/ai/openoffi-1
Did you ever get this figured out? If you did, posting your solution here would be really helpful.
Thanks,
Ben
UPDATE: well I figured out what I was doing wrong. I didn't have OpenOffice services running:
https://www.liferay.com/documentation/liferay-portal/6.1/user-guide/-/ai/openoffi-1
11年前 に Harish Kumar によって更新されました。
RE: Add "export to PDF/Excel" button in custom portlet
Expert 投稿: 483 参加年月日: 10/07/31 最新の投稿
I have done this using InputStream instead of FileInputStream like this -
InputStream convertedIS=null;
try {
convertedIS = DocumentConversionUtil.convert("12345", is, sourceExtension, targetExtension);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}