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

Registered : 109,038

HOME > Java Programming > Java Forum > ช่วยด้วยครับ JSP สร้างไฟล์ PDF แล้วไม่แสดง ภาษาไทย ทั้งที่ getFont ภาษาไทยแล้ว


 

[Java] ช่วยด้วยครับ JSP สร้างไฟล์ PDF แล้วไม่แสดง ภาษาไทย ทั้งที่ getFont ภาษาไทยแล้ว

 
Topic : 125371



โพสกระทู้ ( 43 )
บทความ ( 0 )



สถานะออฟไลน์



Code
001.<%--
002.    Document   : Create_PDF
003.    Created on : Nov 9, 2016, 12:03:13 PM
004.    Author     : Life
005.--%>
006. 
007.<%@page import="com.itextpdf.text.BaseColor"%>
008.<%@page import="com.itextpdf.text.pdf.BaseFont"%>
009. 
010.<%@page import="com.itextpdf.text.Phrase"%>
011.<%@page import="com.itextpdf.text.pdf.PdfPCell"%>
012.<%@page import="com.itextpdf.text.pdf.PdfPTable"%>
013.<%@page import="com.itextpdf.text.Section"%>
014.<%@page import="com.itextpdf.text.Chapter"%>
015.<%@page import="com.itextpdf.text.Paragraph"%>
016.<%@page import="java.io.FileOutputStream"%>
017.<%@page import="com.itextpdf.text.pdf.PdfWriter"%>
018.<%@page import="com.itextpdf.text.Document"%>
019.<%@page import="com.itextpdf.text.pdf.CMYKColor"%>
020.<%@page import="com.itextpdf.text.FontFactory"%>
021.<%@page import="com.itextpdf.text.Font"%>
022. 
023.<%@ page import="java.io.File"%>
024.<%@ page import="org.apache.pdfbox.pdmodel.PDDocument" %>
025.<%@ page import="org.apache.pdfbox.pdmodel.PDPage" %>
026.<%@ page import="org.apache.pdfbox.pdmodel.edit.PDPageContentStream" %>
027.<%@ page import="org.apache.pdfbox.pdmodel.font.PDFont" %>
028.<%@ page import="org.apache.pdfbox.pdmodel.font.PDType1Font" %>
029. 
030.<%@ page import="java.text.SimpleDateFormat" %>
031.<%@ page import="java.util.Calendar" %>
032.<%@ page import="java.util.Date" %>
033.<%@ page import="java.util.GregorianCalendar" %>
034.<%@page contentType="text/html" pageEncoding="UTF-8"%>
035.<% request.setCharacterEncoding("UTF-8"); %>
036.<!DOCTYPE html>
037.<html>
038.    <head>
039.        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
040.        <title>JSP Page</title>
041.    </head>
042.    <body>
043.        <% 
044.            Calendar c = Calendar.getInstance();
045.            SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
046.            String currentDate = df.format(c.getTime());
047.             
048.            Font blueFont = FontFactory.getFont("C:\\Users\\Life\\Downloads\\CS_PraJad-3\\CS_PraJad\\CSPraJad.TTF", 8, Font.NORMAL, new CMYKColor(255, 0, 0, 0));
049.            Font font = FontFactory.getFont("C:\\Users\\Life\\Downloads\\CS_PraJad-3\\CS_PraJad\\CSPraJad.TTF",
050.    BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 8, Font.NORMAL, BaseColor.BLACK);
051.BaseFont baseFont = font.getBaseFont();
052.            Font redFont = FontFactory.getFont(FontFactory.COURIER, 12, Font.BOLD, new CMYKColor(0, 255, 0, 0));
053.            Font yellowFont = FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD, new CMYKColor(0, 0, 255, 0));
054.Document document = new Document();
055. 
056.try
057.{
058.    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("C:\\pdf\\StylingExample.pdf"));
059.    document.open();
060.     
061.    PdfPTable my_report_table  = new PdfPTable(4);
062.    PdfPCell table_cell;
063.                                 
064.                                String hdept_id = "กกดกด";
065.                                 
066.                                table_cell=new PdfPCell(new Phrase(hdept_id,font));
067.                                my_report_table.addCell(table_cell);
068.                                String hdept_name="กกกกกก";
069.                                table_cell=new PdfPCell(new Phrase(hdept_name,font));
070.                                my_report_table.addCell(table_cell);
071.                                String hmanager_id="CCCCCC";
072.                                table_cell=new PdfPCell(new Phrase(hmanager_id,font));
073.                                my_report_table.addCell(table_cell);
074.                                String hlocation_id="DDDDDD";
075.                                table_cell=new PdfPCell(new Phrase(hlocation_id,font));
076.                                my_report_table.addCell(table_cell);
077.                    for(int i=0;i<10;i++) {               
078.                                String dept_id = "DEPARTMENT_ID";
079.                                table_cell=new PdfPCell(new Phrase(dept_id,blueFont));
080.                                my_report_table.addCell(table_cell);
081.                                String dept_name="DEPARTMENT_NAME";
082.                                table_cell=new PdfPCell(new Phrase(dept_name,blueFont));
083.                                my_report_table.addCell(table_cell);
084.                                String manager_id="MANAGER_ID";
085.                                table_cell=new PdfPCell(new Phrase(manager_id,blueFont));
086.                                my_report_table.addCell(table_cell);
087.                                String location_id="LOCATION_ID";
088.                                table_cell=new PdfPCell(new Phrase(location_id,blueFont));
089.                                my_report_table.addCell(table_cell);
090.                                }
091.     
092.     /* Attach report table to PDF */
093.                                       
094.                
095.    //document.add(new Paragraph("Styling Example"));
096.  
097.    //Paragraph with color and font styles
098.   // Paragraph paragraphOne = new Paragraph("Some colored paragraph text", redFont);
099.   // document.add(paragraphOne);
100.    //Create chapter and sections
101.    Paragraph chapterTitle = new Paragraph(currentDate, blueFont);
102.    Chapter chapter1 = new Chapter(chapterTitle, 1);
103.    chapter1.setNumberDepth(0);
104.     
105.    Paragraph sectionContent = new Paragraph("กกกกกกกกกกกกกกกกกกกกกก", blueFont);
106.    chapter1.add(sectionContent);
107.  
108.    Paragraph sectionContent2 = new Paragraph("Section Text content\n\n", yellowFont);
109.    sectionContent2.setAlignment(sectionContent2.ALIGN_CENTER);
110.    chapter1.add(sectionContent2);
111.  
112.   
113.  
114.     
115.    document.add(chapter1);
116.     
117.     
118.    document.add(my_report_table);
119.    document.close();
120.     
121.     
122.    writer.close();
123.} catch (Exception e)
124.{
125.    e.printStackTrace();
126.}
127.            %>
128.             
129.    </body>
130.</html>


รบกวนช่วยด้วยนะครับ

pdf



Tag : Java, JAVA, JSP

Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2016-11-14 11:16:51 By : jakkrit01 View : 4435 Reply : 4
 

 

No. 1



โพสกระทู้ ( 74,059 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Quote:
PdfWriter


Library ตัวนี้มัน Support Chartset แบบ UTF-8 หรือเปล่าครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-11-15 09:13:29 By : mr.win
 

 

No. 2



โพสกระทู้ ( 32 )
บทความ ( 0 )



สถานะออฟไลน์


ใช้ Eclipse ป่าวครับ ถ้าใช้ให้คลิกขวาที่ ไฟล์ นี้
เลือก properties
เลือก Resource
ตรงหัวข้อ text file encoding ให้เลือกเป็น Other และเลือก UTF-8

ส่วนตัวผมใช้ itext ออก PDF ได้ทั้งไทย ลาว khmer ก็ไม่มีปัญหานะครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-11-24 22:01:28 By : taturk
 

 

No. 3



โพสกระทู้ ( 43 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 2 เขียนโดย : taturk เมื่อวันที่ 2016-11-24 22:01:28
รายละเอียดของการตอบ ::
ขอบคุณมากครับ จะลองดูครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-12-23 15:36:00 By : jakkrit01
 

 

No. 4



โพสกระทู้ ( 74,059 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-12-27 11:15:09 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ช่วยด้วยครับ JSP สร้างไฟล์ PDF แล้วไม่แสดง ภาษาไทย ทั้งที่ getFont ภาษาไทยแล้ว
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





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