0

I have just started using itext pdf in Java.

I have created pdf using itext in J2EE. It runs properly in Eclipse using Apache 5.5 server but after uploading the to live server, the pdf will not generate. I can't figure out what the problem is.

I have used itext-5.5.3 jars in my web application. My class is as follows:

public class create_pdf {

    public String pdfcreate() throws FileNotFoundException {
        try{
            OutputStream file = new FileOutputStream(new File("C://Windows//temp//hello.pdf"));
            Document document = new Document();  
            Font font = new Font(Font.FontFamily.COURIER, 8, 0, BaseColor.DARK_GRAY);

            PdfWriter writer =PdfWriter.getInstance(document, file);

            document.open();  
            document.add(new Paragraph("E-Ticket",fontheader));
            document.add(new Paragraph("E-Ticket Generated On - "+new Date().toString(),font));
            document.add(new Paragraph("hello",font));
            document.close();
        }
        catch(Exception ex){
            ex.printStackTrace();
        } 
        return null;
    }   

}
Amedee Van Gasse
  • 7,280
  • 5
  • 55
  • 101
Arnav Ray
  • 11
  • 1
  • 4
    Hello and welcome to Stack Overflow! Do you get any errors? – Simon Oct 22 '14 at 12:32
  • Try downloading to `hello.pdf` (aka to the current folder relative path) and see if it works, and post any stacktrace if you have any. – EpicPandaForce Oct 22 '14 at 12:50
  • Is your web application allowed to store a file in "C://Windows//temp//"? Is there already a "hello.pdf" which cannot be replaced? By the way, why double slashes? – mkl Nov 25 '16 at 17:47

1 Answers1

0

Try to change the path. check whether it is valuable path in your server,

OutputStream file = new FileOutputStream(new File("C://Windows//temp//hello.pdf"))

Probably try with the mount folder path of your server or the path you can access . something like /directory_name

See How to offer download of local PDF file in Java? if you are trying to offer download

Community
  • 1
  • 1
Santhosh
  • 8,181
  • 4
  • 29
  • 56
  • actually with this same path i can generate pdf in eclipse.. the only problem is that when i upload my project on the live server with the same code pdf is not generating..... – Arnav Ray Oct 22 '14 at 12:38
  • Yes you can create in your local path . does your server has `c:` path ? – Santhosh Oct 22 '14 at 12:40
  • So you need to provide a valid path in the server to generate the pdf there. Can you show the error you get ? – Santhosh Oct 22 '14 at 12:46
  • thers no way i can see the error .... actually i am working on a live website where i am implementing this functionality...In eclipse there is no problem..it runs smoothly... but after uploading my war file on the server ,cannot create the pdf.. – Arnav Ray Oct 22 '14 at 15:13