Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone



Clound SSD Virtual Server

JSP and PDF (Java)

JSP and PDF (Java) ในการเขียน JSP ด้วยภาษา Java ในกรณีที่ต้องการสร้าง PDF จะต้องหา Library ข้างนอกมาใช้ เพราะใน JDK ที่จะไม่มี Class มาให้ใช้ และ Library ที่อยากจะแนะนำให้ใช้ก็คือ Apache PDFBox ซึ่งเป็น Library ที่ได้รับความนิยมและสามารถ Download ใช้งานได้ฟรี

Apache PDFBox - A Java PDF Library


JSP and PDF

Example การอ่านสร้าง PDF ด้วย JSP แบบง่าย ๆ

index.jsp
<%@ 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>

Output

JSP and PDF

แสดง Path ที่จัดเก็บ Temp ของ Path ในการรัน

JSP and PDF

ตัวอย่าง PDF ที่ได้


อ่านเพิ่มเติมเกี่ยว Java และ PDF

JSP and PDF

Java and PDF







   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2013-08-17 15:08:08 / 2013-08-20 21:24:31
  Download : No files
 Sponsored Links / Related

 
JSP and Zip (Java)
Rating :

 
JSP and FTP (Java)
Rating :

 
JSP and Excel (Java)
Rating :

 
JSP and Word (Java)
Rating :

 
JSP and XML (Java)
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่