Tim Nees

Greenhorn
+ Follow
since Dec 26, 2007
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Tim Nees

Hi Christophe,

thanks for your post.

Ok, if Spring manages the output of the PDF, which prerequest must be
made, that Spring do this?

Thanks

Tim
Hi Christophe,

thanks for your post.

Ok, if Spring manages the output of the PDF, which prerequest must be
made, that Spring do this?

Thanks

Tim
12 years ago
Hi,

i write an application in which a pdf is generated and send to the browser.
The PDF is generated with itext. Generate the pdf and save it works fine, but the following error message is thrown:



My code for the generate and forward of the pdf follows here:


public class MakePDF extends AbstractPdfView{

@Override
protected void buildPdfDocument(Map model, Document document, PdfWriter writer, HttpServletRequest request, HttpServletResponse response) throws Exception {

String linebreak = new String("\n");
Examination_data examination_data = null;
Patient_data patient_data = null;

String filename;

ByteArrayOutputStream baos = new ByteArrayOutputStream();

patient_data = (Patient_data) model.get("patient_data");
examination_data = (Examination_data) model.get("examination_data");

PdfWriter.getInstance(document, baos);

response.setContentType("application/pdf");

filename = (String) examination_data.getFilename();

String split[] = filename.split("\\.");

if (split.length == 1){
filename = filename + ".pdf";
}
else if (split.length == 2){

if (!split[1].equals("pdf")){
split[1] = ".pdf";
filename = split[0] + split[1];
}

}

response.setHeader( "Content-disposition", "attachment; filename=" + filename + "");

document.open();;

/**
* In das PDF Dokument einfuegen
*/
// Name
document.add(new Paragraph(linebreak));
document.add(new Paragraph("Name: "));
document.add(new Paragraph(patient_data.getName()));

// Firstname
document.add(new Paragraph(linebreak));
document.add(new Paragraph("Firstname: "));
document.add(new Paragraph(patient_data.getFirstname()));

// Date of Birth
document.add(new Paragraph(linebreak));
document.add(new Paragraph("Date of birth: "));
document.add(new Paragraph("test"));

// Gender
document.add(new Paragraph(linebreak));
document.add(new Paragraph("Gender: "));
document.add(new Paragraph(patient_data.getGender()));

// Bodysize
document.add(new Paragraph(linebreak));
document.add(new Paragraph("Bodysize: "));
document.add(new Paragraph(patient_data.getBodysize()));

// Weight
document.add(new Paragraph(linebreak));
document.add(new Paragraph("Weight: "));
document.add(new Paragraph(patient_data.getWeight()));
document.add(new Paragraph(linebreak));

// Indication
document.add(new Paragraph(linebreak));
document.add(new Paragraph("Indication:"));
document.add(new Paragraph(linebreak));
document.add(new Paragraph(examination_data.getIndication()));

document.add(new Paragraph(linebreak));
document.add(new Paragraph(linebreak));

// Finding
document.add(new Paragraph(linebreak));
document.add(new Paragraph("Finding:"));
document.add(new Paragraph(linebreak));
document.add(new Paragraph(examination_data.getFinding()));

document.add(new Paragraph(linebreak));
document.add(new Paragraph(linebreak));

// Comment
document.add(new Paragraph(linebreak));
document.add(new Paragraph("Comment:"));
document.add(new Paragraph(linebreak));
document.add(new Paragraph(examination_data.getComment()));

document.add(new Paragraph(linebreak));
document.add(new Paragraph(linebreak));

//Diagnosis
document.add(new Paragraph(linebreak));
document.add(new Paragraph("Diagnosis:"));
document.add(new Paragraph(linebreak));
document.add(new Paragraph(examination_data.getDiagnostics()));

document.close();

response.setContentLength(baos.size());

ServletOutputStream out = response.getOutputStream();

baos.writeTo(out);

out.flush();

}

}



Does anybody have an advice or knows a workaround for this error?

Thanks

Tim
Hi,

i write an application in which a pdf is generated and send to the browser.
The PDF is generated with itext. Generate the pdf and save it works fine, but the following error message is thrown:



My code for the generate and forward of the pdf follows here:


public class MakePDF extends AbstractPdfView{

@Override
protected void buildPdfDocument(Map model, Document document, PdfWriter writer, HttpServletRequest request, HttpServletResponse response) throws Exception {

String linebreak = new String("\n");
Examination_data examination_data = null;
Patient_data patient_data = null;

String filename;

ByteArrayOutputStream baos = new ByteArrayOutputStream();

patient_data = (Patient_data) model.get("patient_data");
examination_data = (Examination_data) model.get("examination_data");

PdfWriter.getInstance(document, baos);

response.setContentType("application/pdf");

filename = (String) examination_data.getFilename();

String split[] = filename.split("\\.");

if (split.length == 1){
filename = filename + ".pdf";
}
else if (split.length == 2){

if (!split[1].equals("pdf")){
split[1] = ".pdf";
filename = split[0] + split[1];
}

}

response.setHeader( "Content-disposition", "attachment; filename=" + filename + "");

document.open();;

/**
* In das PDF Dokument einfuegen
*/
// Name
document.add(new Paragraph(linebreak));
document.add(new Paragraph("Name: "));
document.add(new Paragraph(patient_data.getName()));

// Firstname
document.add(new Paragraph(linebreak));
document.add(new Paragraph("Firstname: "));
document.add(new Paragraph(patient_data.getFirstname()));

// Date of Birth
document.add(new Paragraph(linebreak));
document.add(new Paragraph("Date of birth: "));
document.add(new Paragraph("test"));

// Gender
document.add(new Paragraph(linebreak));
document.add(new Paragraph("Gender: "));
document.add(new Paragraph(patient_data.getGender()));

// Bodysize
document.add(new Paragraph(linebreak));
document.add(new Paragraph("Bodysize: "));
document.add(new Paragraph(patient_data.getBodysize()));

// Weight
document.add(new Paragraph(linebreak));
document.add(new Paragraph("Weight: "));
document.add(new Paragraph(patient_data.getWeight()));
document.add(new Paragraph(linebreak));

// Indication
document.add(new Paragraph(linebreak));
document.add(new Paragraph("Indication:"));
document.add(new Paragraph(linebreak));
document.add(new Paragraph(examination_data.getIndication()));

document.add(new Paragraph(linebreak));
document.add(new Paragraph(linebreak));

// Finding
document.add(new Paragraph(linebreak));
document.add(new Paragraph("Finding:"));
document.add(new Paragraph(linebreak));
document.add(new Paragraph(examination_data.getFinding()));

document.add(new Paragraph(linebreak));
document.add(new Paragraph(linebreak));

// Comment
document.add(new Paragraph(linebreak));
document.add(new Paragraph("Comment:"));
document.add(new Paragraph(linebreak));
document.add(new Paragraph(examination_data.getComment()));

document.add(new Paragraph(linebreak));
document.add(new Paragraph(linebreak));

//Diagnosis
document.add(new Paragraph(linebreak));
document.add(new Paragraph("Diagnosis:"));
document.add(new Paragraph(linebreak));
document.add(new Paragraph(examination_data.getDiagnostics()));

document.close();

response.setContentLength(baos.size());

ServletOutputStream out = response.getOutputStream();

baos.writeTo(out);

out.flush();

}

}



Does anybody have an advice or knows a workaround for this error?

Thanks

Tim
12 years ago