2

I build a web application.

I would like to read files from server, then generate PDF file ( with itText) then save it to the server.

I don't know how to locate the files from the server then save the file to the server.

I read from my PC and write data to my PC perfectly.

The above code works properly but just on my computer not at server.

String jspPath = "C:\\Users\\dave\\Desktop\\eclipse\\project\\";
    String fileName = "CV.txt";
InputStreamReader ir = new InputStreamReader(new FileInputStream(jspPath+filename), "UTF-8");

// Then generate the PDF with iText //and

FileOutputStream fs = new FileOutputStream(jspPath+"generated.pdf");
    PdfWriter pdfWriter = new PdfWriter(fs);
    PdfDocument pdfdoc = new PdfDocument(pdfWriter);

JSP path references to my folder not the link with the generated pdf.

I would like :

  1. put CV.txt to the server and read it.

  2. Generate pdf ( it will work).

  3. Save the generated PDF to server

  4. A link to the generated PDF which i can download.

Thanks in Advance

2
  • What kind of server are you referring to? Linux? Windows? Commented Aug 13, 2016 at 1:24
  • 1
    show the code that you had deployed on server and what kind of os which would be helpful. Commented Aug 13, 2016 at 6:13

1 Answer 1

3

Here are few things which might help you.

  1. You can use FormData to pass text file from Frontend to Backend. Use ajax post call to pass data.

you will have entire file on backend in the RequestContext parameter as FileItem object. you can start reading file using InputStreamReader.

  1. than convert it into pdf file.

  2. you can save pdf file to java temporary directory

String temporaryDir = System.getProperty("java.io.tmpdir");

this will return path for java temporary directory and you can delete this pdf file later

  1. you will have to create ResponseBuilder with content-type='application/pdf' to download as a pdf file and return it to the UI. read this post

Hope this information helps you to solve your issue!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.