掲示板
Liferay 6.1 : Unable to Generate PDF File
11年前 に Ravi Kiran によって更新されました。
Liferay 6.1 : Unable to Generate PDF File
Junior Member 投稿: 98 参加年月日: 11/12/12 最新の投稿
Hi ,
I am uisng Liferay 6.1 MVCPOrtlet .
I am using iText API for the PDF Generation .
I am not sure why this is not generating the PDF File ??
Please see the code below
package com;
import java.io.FileOutputStream;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.ProcessAction;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.liferay.portal.util.PortalUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
public class SecondPort extends MVCPortlet {
@ProcessAction(name = "registerUser")
public void registerUser(ActionRequest acrequest, ActionResponse acresponse) throws Exception
{
try
{
String text = "You didn't enter any text";
HttpServletResponse response = PortalUtil
.getHttpServletResponse(acresponse);
response.setHeader("Expires", "0");
response.setHeader("Cache-Control",
"must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma", "public");
response.setContentType("application/pdf");
response.setContentLength(2333);
HttpServletRequest request = PortalUtil.getHttpServletRequest(acrequest);
Document document = new Document();
PdfWriter.getInstance(document,new FileOutputStream("hello.pdf"));
document.open();
Paragraph p = new Paragraph();
p.add("Hi");
document.add(p);
document.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
I am uisng Liferay 6.1 MVCPOrtlet .
I am using iText API for the PDF Generation .
I am not sure why this is not generating the PDF File ??
Please see the code below
package com;
import java.io.FileOutputStream;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.ProcessAction;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.liferay.portal.util.PortalUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
public class SecondPort extends MVCPortlet {
@ProcessAction(name = "registerUser")
public void registerUser(ActionRequest acrequest, ActionResponse acresponse) throws Exception
{
try
{
String text = "You didn't enter any text";
HttpServletResponse response = PortalUtil
.getHttpServletResponse(acresponse);
response.setHeader("Expires", "0");
response.setHeader("Cache-Control",
"must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma", "public");
response.setContentType("application/pdf");
response.setContentLength(2333);
HttpServletRequest request = PortalUtil.getHttpServletRequest(acrequest);
Document document = new Document();
PdfWriter.getInstance(document,new FileOutputStream("hello.pdf"));
document.open();
Paragraph p = new Paragraph();
p.add("Hi");
document.add(p);
document.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
11年前 に Hitoshi Ozawa によって更新されました。
RE: Liferay 6.1 : Unable to Generate PDF File
Liferay Legend 投稿: 7942 参加年月日: 10/03/24 最新の投稿
You just seem to be developing a servlet instead of a portlet. That simply implies you don't know to to generate pdf using itext.
Please go to itext forum and post your message there because you problem is clearly not with liferay.
Please go to itext forum and post your message there because you problem is clearly not with liferay.