Tuesday, July 5, 2016

Integrating XML Publisher and OAF To get Output In PDF file

To generate the output in PDF formats we need the following:

1 Design the OAF BC4J Object.
2) Design the OAF Page and generate the Data XML
3) Design the RTF Template using Data XML
4) Register the Template with Oracle Applications.
5) Integrating the OAF page With XML Publisher.
6) Invoking the report from OAF

Expected Error:-
if TemplateHelper gives error then we need to TemplateHelper class file in "xdo" folder in apps folder in class.



//In AMImpl.java

    public XMLNode  getPrintDataXML()

    {
    
       

     try

     {

       ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

              // Below Created Object For VO
          OAViewObject vo = getPodetailVO(); 
          
          //Below Code To print xml code in jdevloper

       ((XMLNode) vo.writeXML(4, XMLInterface.XML_OPT_ALL_ROWS)).print(outputStream);

       System.out.println(outputStream.toString());
       
       // below to return xml code for this method.
       
          XMLNode xmlNode = (XMLNode) vo.writeXML(4, XMLInterface.XML_OPT_ALL_ROWS);
          return xmlNode;

      }

     catch(Exception e)

     {

      throw new OAException (e.getMessage());

     }


    } 


// In Controller 

              if(pageContext.getParameter("Print") != null)
              {
              
              
              // Get the HttpServletResponse object from the PageContext. The report output is written to HttpServletResponse.
              DataObject sessionDictionary = (DataObject)pageContext.getNamedDataObject("_SessionParameters");
              HttpServletResponse response = (HttpServletResponse)sessionDictionary.selectValue(null,"HttpServletResponse");
              
              
              try {
              
              ServletOutputStream os = response.getOutputStream();

              // Set the Output Report File Name and Content Type
              String contentDisposition = "attachment;filename=krishna.pdf";
              response.setHeader("Content-Disposition",contentDisposition);
              response.setContentType("application/pdf");
              

              // Get the Data XML File as the XMLNode

              XMLNode xmlNode = (XMLNode) am.invokeMethod("getPrintDataXML");


              ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
              xmlNode.print(outputStream);
              ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
              ByteArrayOutputStream pdfFile = new ByteArrayOutputStream();
              

              //Generate the PDF Report.
              TemplateHelper.processTemplate(
              ((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getAppsContext(),
              "FND",// Application Short Name
              "PO_Search_OAF", // Data Template Short Name
              ((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getUserLocale().getLanguage(),
              ((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getUserLocale().getCountry(),
              inputStream,TemplateHelper.OUTPUT_TYPE_PDF,null,pdfFile);
              

              // Write the PDF Report to the HttpServletResponse object and flush.
              byte[] b = pdfFile.toByteArray();
              response.setContentLength(b.length);
              os.write(b, 0, b.length);
              os.flush();
              os.close();
              
              
              }
              catch(Exception e)
              {
              response.setContentType("text/html");
              throw new OAException(e.getMessage(), OAException.ERROR);
              } 
              pageContext.setDocumentRendered(true);


              }

No comments:

Post a Comment