Please disable your adblock and script blockers to view this page

Search this blog

Showing posts with label pdf. Show all posts
Showing posts with label pdf. Show all posts

Monday 17 April 2017

Show saved file (pdf/text/html/xml/image) content on page from database (BLOB) in ADF Application

Hello All

Previously I have posted about uploading and saving files in database blob column now this post is about showing saved file content on page using ADF Faces inline frame component

In this post I am extending same previous application, Now see how we can implement this
There are few more steps to go , See the additional steps to show file content on page-

Wednesday 1 February 2017

Export ViewObject data to PDF file using Apache PDFBox

Hello All
Hope you all are doing well :)

This post is about exporting view object data in a pdf file directly from af:table , export to excel is built in feature of ADF but exporting data in PDF requires little bit of extra effort
So here for this requirement I am using Apache PDFBox library , previously I have posted about using this API to create PDF file from text data
I know many of you will not visit that link ;) So a quick overview

Thursday 22 January 2015

Show uploaded file (pdf/text/html/xml/image) content on page -Oracle ADF

Hello all
In previous post
Uploading and downloading files from absolute server path in Oracle ADF (12.1.3)
we saw that how can we upload any file to absolute server path and download same from there.
Uploading part is done using simple java code to write file to specified folder and downloading part is done using <af:fileDownloadActionListener>

Now in this post i am going to show that how can we display a file on page directly without downloading it.
So for this i am using same sample application that i have used in previous post , you can download it from here

See the additional steps to show file content on page-
  • Create a servlet to parse file into output stream , this output stream will be used to show file content further.
    To create servlet right click on viewController project select New--->From Gallery-->Web Tier-->Servlet

  • See servlet source code to parse file into outputStream

  • import;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class PreviewFileServlet extends HttpServlet {
        private static final String CONTENT_TYPE = "text/html; charset=UTF-8";
        public void init(ServletConfig config) throws ServletException {
         * @param request
         * @param response
         * @throws ServletException
         * @throws IOException
        public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            String path = (request.getParameter("path"));
            OutputStream os = response.getOutputStream();
            //If path is null
            if (path.equalsIgnoreCase("No")) {
                path = "D:\\Document\\ItemImage\\Item.jpg";
            if (request.getParameter("path") == "") {
                path = "D:\\Document\\ItemImage\\Item.jpg";
            InputStream inputStream = null;
            try {
                File outputFile = new File(path);
                inputStream = new FileInputStream(outputFile);
                BufferedInputStream in = new BufferedInputStream(inputStream);
                int b;
                byte[] buffer = new byte[10240];
                while ((b =, 0, 10240)) != -1) {
                    os.write(buffer, 0, b);
            } catch (Exception e) {
            } finally {
                if (os != null) {
                if (inputStream != null) {

  • Now open page in editor and drop an af:inlineFrame from component palette . inlineFrame is used to create a frame to show any external page or document just like as HTML iframe , it is loaded from source attribute
    So here i am using servlet as source attribute for this inlineFrame

  • <af:inlineFrame id="if2"
                                                        source="/previewfileservlet?path=#{bindings.Path.inputValue == null ? 'No' : bindings.Path.inputValue}"
                                                        inlineStyle="height:350px;width:800px;" sizing="preferred"/>

    here path of document is added to pageDef bindings that is passed to servelt as parameter

  • Now run this application and check it

    View Text File-
          View PDF File-

Thanks, Happy Learning :)

Post Related to file handling in Oracle ADF- 

Show saved file (pdf/text/html/xml/image) content on page from database (BLOB) in ADF Application
Uploading and showing image file from absolute server path -Orace ADF
Exporting viewObject data in text file using af:fileDownloadActionListener in Oracle ADF (12.1.3)
Creating pdf file using Apache PDFBox API in ADF Faces and opening it in new window -Oracle ADF
Download file from url using Oracle ADF & Java- Download Manager
Reading html source of a webpage (url) using Oracle ADF (af:richTextEditor) & Java

Friday 9 August 2013

Creating pdf file using Apache PDFBox API in ADF Faces and opening it in new window -Oracle ADF

Apache PDFBox library is an open source java tool for working with PDF documents, go to for API docs and download jar (pdfbox-app-1.8.2) from there.

  •  Now create a fusion web application and add jar to view controller project's library and class-path
  •  To convert text to pdf format, i have used an input text and bind it to bean (to get value)
  •  Now see the button code that converts text to pdf file format using Apache PDFBox

  •         PDDocument document = new PDDocument();
            PDPage page = new PDPage();
            // Create a new font object selecting one of the PDF base fonts
            PDFont font = getFontDef();
            // Start a new content stream which will "hold" the to be created content
            PDPageContentStream contentStream = new PDPageContentStream(document, page);
            // Define a text content stream using the selected font, moving the cursor and drawing the text "Hello World"
            contentStream.setFont(font, 10);
            contentStream.moveTextPositionByAmount(50, 700);
            // Make sure that the content stream is closed:
            // Save the results and ensure that the document is properly closed:
            try {
            } catch (COSVisitorException e) {

  • now your pdf is generated in fixed path, and if user want to open it immediately , try to do this

  •         if ((new File("D:\\Hello World.pdf")).exists()) {
                Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler D:\\Hello World.pdf");
            } else {
                System.out.println("File is not exists");

  • this code invokes File Protocol using Runtime class
  • Run this application and see-
 Click on generate button-

For more details and functionality visit Apache PDFBox site
Sample ADF Application-Download