Hi
I have a servlet which execute the hello word example but when I try to open
the generated pdf I get message from adobe reader:
"Adobe Reader could not open 'test.pdf' because it is either not a supported
file type or because the file has been damaged (for example, it was sent as an
email attachment and wasn't correctly decoded)."
Here is my code:
PDDocument document = new PDDocument();
PDPage page = new PDPage();
document.addPage( page );
PDFont font = PDType1Font.HELVETICA_BOLD;
PDPageContentStream contentStream = new PDPageContentStream(document, page);
contentStream.beginText();
contentStream.setFont( font, 12 );
contentStream.moveTextPositionByAmount( 100, 700 );
contentStream.drawString( "Hello World" );
contentStream.endText();
contentStream.close();
// get the web applications temporary directory
File tempDir = (File) getServletContext().getAttribute(
"javax.servlet.context.tempdir" );
// create a temporary file in that directory
File tempFile = File.createTempFile( "test", ".pdf", tempDir );
try {
document.save(tempFile.getAbsolutePath());
} catch (COSVisitorException e) {
e.printStackTrace();
}
document.close();
Thanks.
Guy Kroizman.