0

Getting this error while reading pdf any help . I using a link to read the PDF file

ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
PdfReader reader = null; 
PdfImportedPage page = null; 
try { PdfCopy writer = new PdfCopy(document, baos); 
document.open(); 
for (String pdfFile : pdfFiles) { 
  reader = new PdfReader(pdfFile); 
  for (int i = 1; i <= reader.getNumberOfPages(); i++) { 
     page = writer.getImportedPage(reader, i); 
     writer.addPage(page); 
  } 
  reader.close(); } 


  document.close(); 
} catch (Exception e) { System.out.println(e); 
} finally { if (document != null && document.isOpen()) { document.close(); } } 
response.setContentType("application/octet-stream"); 
response.setHeader("Content-disposition", "attachment; filename=Text.pdf"); 
response.setContentLength(baos.size()); 
OutputStream outStream = response.getOutputStream(); 
baos.writeTo(outStream); 
2
  • ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfReader reader = null; PdfImportedPage page = null; try { PdfCopy writer = new PdfCopy(document, baos); document.open(); for (String pdfFile : pdfFiles) { reader = new PdfReader(pdfFile); for (int i = 1; i <= reader.getNumberOfPages(); i++) { page = writer.getImportedPage(reader, i); writer.addPage(page); } reader.close(); } Commented Feb 23, 2014 at 11:20
  • document.close(); } catch (Exception e) { System.out.println(e); } finally { if (document != null && document.isOpen()) { document.close(); } } response.setContentType("application/octet-stream"); response.setHeader("Content-disposition", "attachment; filename=Text.pdf"); response.setContentLength(baos.size()); OutputStream outStream = response.getOutputStream(); baos.writeTo(outStream); Commented Feb 23, 2014 at 11:21

1 Answer 1

2

ClientAbortException is a tomcat exception that happens when the application is sending to the browser but the browser terminates or has terminated the request. This means, your code runs until the very final line and then generates the exception. Maybe the generation takes to long and the browser connection is timing out?

Test the pdf generation and the sending to the browser isolated. If the problem persistest, please also post the surrounding servlet code.

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.