1

I want to read the pdf file pagewise on JSP page so I have used com.itextpdf.text.pdf.PdfReader to read the content of the pdf file page by page. I used below code on JSP page :-

<%@  page language="java" import="java.io.*,java.util.*,java.lang.*, ,com.itextpdf.text.pdf.PdfReader,com.itextpdf.text.pdf.parser.PdfTextExtractor,
org.apache.commons.io.*,org.apache.http.entity.*"%><%!
%><%

    try {
                PdfReader reader = new PdfReader("D:\\text.pdf");
                int n = reader.getNumberOfPages(); 
                System.out.println("Number of Pages::::" + String.valueOf(n));
                StringBuffer strBuf = new StringBuffer();
                for (int i =1; i<=n;i++){

                    strBuf.append(PdfTextExtractor.getTextFromPage(reader, i));
                    strBuf.append(System.lineSeparator());
                     //Extracting the content from a particular page.
                    if(i<n){
                        strBuf.append(separator);
                    }
                    strBuf.append(System.lineSeparator());
                }
                System.out.println(strBuf.toString());
                reader.close();
            }
            catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
%>

But when I run my application and call this JSP Page then I got exception[Unable to compile class for JSP].

Can anybody help me how do I resolve this issue to compile my JSP page properly?

psisodia
  • 1,117
  • 5
  • 17
  • 36
  • try to remove java code from JSP and add Java class http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files – Himanshu Jan 13 '17 at 09:51
  • 3
    Most probably you don't have the `itextpdf` JAR file in your classpath, it has to be in `WEB-INF/lib` folder of your web application. – Jozef Chocholacek Jan 13 '17 at 13:02

1 Answers1

0

You should import com.itextpdf.kernel.pdf.PdfRreader;

Which comes with kernel-7.1.11 JAR

iamfnizami
  • 163
  • 1
  • 8
  • 1
    By using the tag [tag:itext] but not the tag [tag:itext7] the OP indicated that he uses an iText version 5.x. Also his code clearly uses iText 5.x classes and patterns. – mkl Jun 19 '20 at 15:24