Approach to get a PDF output on button click in R12.2.X is different from the lower version of R12. Let understand what exactly a requirement is.
Requirement: User wants a button in OAF page, which on click gives a PDF output.
Note:
1: In this article we will learn to get PDF output using a VO, and in the next article I will provide a solution how to integrate a XDO/BI publisher report in OAF page
2: This article requires a developer to a have better understanding of OAF concept.
Frequently ask question:
Question 1: If it is possible to call a report in 11i from OAF page, why can’t we use the same approach?
Answer: In R12.2.X, report server cannot be invoked from OAF page due to weblogic server as oracle corporation moving toward Oracle fusion
Question 2: Are there any changes at server level?
Answer: Yes, in R12.2.X, BI publisher take place of XML publisher. So when you compare the folder on server in R12.1 and R12.2 under path $JAVA_TOP/oracle/apps/xdo, you can easily identify the difference.
Question 3: Having so many roadblocks, what’s the solution?
Answer: Guys !! You are on right place. Let me explain you the foundation for our solution using below PPT.
gen_pdf_01.jpg
From above screenshot it clear enough that we are going to use RTF template and also XML data.
But now the question arises from where we get the XML data. So the answer is VO or any other source which generates XML data.
In this article I will use VO as my data source and in my next article will use XDO/BI publisher to get XML data, as we all know that it not possible for huge computation in OAF VO.
Step 1: Create an OAF page with button and attach controller to page
Step 2: create VO and AM. Then attach VO to AM
Below are the VO code
Select eno,ename,salary from emp;
Step 3: Create an RTF and place it to local folder in C: drive
Step 4: Write below code in Application module
public XMLNode getEmpDataXML()
{
try
{
OAViewObject vo = (OAViewObject)findViewObject("xxEmpVO1");
// Exceute VO
vo.executeQuery();
XMLNode xmlNode = (XMLNode)vo.writeXML(4, XMLInterface.XML_OPT_ALL_ROWS);
return xmlNode;
} catch (Exception e)
{
throw new OAException(e.getMessage() + "Custom Error");
}
}
Step 5: Write below code in controller, prcocessFormRequest method
public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processFormRequest(pageContext, webBean);
//Get Session and Response
OAApplicationModule am= (OAApplicationModule)pageContext.getApplicationModule(webBean);
DataObject sessionDictionary = (DataObject)pageContext.getNamedDataObject("_SessionParameters");
HttpServletResponse response = (HttpServletResponse)sessionDictionary.selectValue(null,"HttpServletResponse");
// Set the Output Report File Name and Content Type
String contentDisposition = "attachment;filename=EmpOutput.pdf";
response.setHeader("Content-Disposition",contentDisposition);
response.setContentType("application/pdf");
if(pageContext.getParameter("PrintPDFBtn") != null) {
try{
ServletOutputStream os = response.getOutputStream();
//Calling RTF Processor
//RTF Processor generate XSL
RTFProcessor rtfProcessor = new RTFProcessor("C:\\EMPTemplate.rtf");
ByteArrayOutputStream xlsOutputStream = new ByteArrayOutputStream();
rtfProcessor.setOutput(xlsOutputStream);
rtfProcessor.process();
// Get the XML Data as the XMLNode from VO
XMLNode xmlNode = (XMLNode) am.invokeMethod("getEmpDataXML");
ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
ByteArrayInputStream xmlInputStream = new ByteArrayInputStream(localByteArrayOutputStream.toByteArray());
//Calling FO Processor
//FO processor take XML data and RTF as XSL and generate PDF output
FOProcessor processor = new FOProcessor();
ByteArrayOutputStream pdfOutputStream = new ByteArrayOutputStream();
processor.setData(xmlInputStream); //set xml input Stream
ByteArrayInputStream xlsInputStream = new ByteArrayInputStream(xlsOutputStream.toByteArray());
processor.setTemplate(xlsInputStream); //set xsl input file
processor.setOutput(pdfOutputStream);
processor.setOutputFormat(FOProcessor.FORMAT_PDF);
try{
processor.generate();
}catch(XDOException e){
e.printStackTrace();
}
// Write the PDF Report to the HttpServletResponse object and flush.
byte[] b = pdfOutputStream.toByteArray();
response.setContentLength(b.length);
os.write(b, 0, b.length);
os.flush();
os.close();
pdfOutputStream.flush();
pdfOutputStream.close();
}
catch(Exception e){
throw new OAException("Deepak kessarwaani="+e.getMessage(), OAException.ERROR);
}
}
}
Step 6: Run a page and on button click you will get PDF output
Comments
I am trying it but not able to locate class files like,
RTFProcessor and FOProcessor.
Can you please tell me import path for these classes.
Looking forward for your response.
Thanks,
Abbas Qureshi
webpage or even a blog from start to end.
preceding technologies, it's remarkable article.
I've joined your rss feed and look forward to seeking more of your great post.
Also, I have shared your website in my social networks!
do so! Your writing taste has been surprised me. Thank you, very great article.
RSS feed for comments to this post