<%@ page import="org.apache.pdfbox.pdmodel.PDDocument" %>
<%@ page import="org.apache.pdfbox.pdmodel.PDPage" %>
<%@ page import="org.apache.pdfbox.pdmodel.edit.PDPageContentStream" %>
<%@ page import="org.apache.pdfbox.pdmodel.font.PDFont" %>
<%@ page import="org.apache.pdfbox.pdmodel.font.PDType1Font" %>
<html>
<head>
<title>ThaiCreate.Com JSP Tutorial</title>
</head>
<body>
<%
try {
PDDocument document = new PDDocument();
PDPage pdf = new PDPage();
document.addPage(pdf);
// Create a new font object selecting one of the PDF base fonts
PDFont font = PDType1Font.HELVETICA_BOLD;
// Start a new content stream which will "hold" the to be created content
PDPageContentStream contentStream = new PDPageContentStream(document, pdf);
// Define a text content stream using the selected font, moving the cursor and drawing the text "Hello World"
contentStream.beginText();
contentStream.setFont( font, 12 );
contentStream.moveTextPositionByAmount( 100, 700 );
contentStream.drawString( "Welcome to ThaiCreate.Com" );
contentStream.endText();
// Make sure that the content stream is closed:
contentStream.close();
// Save the results and ensure that the document is properly closed:
document.save(application.getRealPath("/data/myPDF.pdf"));
document.close();
out.println("PDF Created to." + application.getRealPath("/data/"));
} catch (Exception e) {
e.printStackTrace();
}
%>
</body>
</html>