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,027

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



 

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

 



Topic : 125371



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



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




Code
<%-- 
    Document   : Create_PDF
    Created on : Nov 9, 2016, 12:03:13 PM
    Author     : Life
--%>

<%@page import="com.itextpdf.text.BaseColor"%>
<%@page import="com.itextpdf.text.pdf.BaseFont"%>

<%@page import="com.itextpdf.text.Phrase"%>
<%@page import="com.itextpdf.text.pdf.PdfPCell"%>
<%@page import="com.itextpdf.text.pdf.PdfPTable"%>
<%@page import="com.itextpdf.text.Section"%>
<%@page import="com.itextpdf.text.Chapter"%>
<%@page import="com.itextpdf.text.Paragraph"%>
<%@page import="java.io.FileOutputStream"%>
<%@page import="com.itextpdf.text.pdf.PdfWriter"%>
<%@page import="com.itextpdf.text.Document"%>
<%@page import="com.itextpdf.text.pdf.CMYKColor"%>
<%@page import="com.itextpdf.text.FontFactory"%>
<%@page import="com.itextpdf.text.Font"%>

<%@ page import="java.io.File"%>
<%@ 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" %>

<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Calendar" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.util.GregorianCalendar" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<% request.setCharacterEncoding("UTF-8"); %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%  
            Calendar c = Calendar.getInstance();
            SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
            String currentDate = df.format(c.getTime());
            
            Font blueFont = FontFactory.getFont("C:\\Users\\Life\\Downloads\\CS_PraJad-3\\CS_PraJad\\CSPraJad.TTF", 8, Font.NORMAL, new CMYKColor(255, 0, 0, 0));
            Font font = FontFactory.getFont("C:\\Users\\Life\\Downloads\\CS_PraJad-3\\CS_PraJad\\CSPraJad.TTF",
    BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 8, Font.NORMAL, BaseColor.BLACK);
BaseFont baseFont = font.getBaseFont();
            Font redFont = FontFactory.getFont(FontFactory.COURIER, 12, Font.BOLD, new CMYKColor(0, 255, 0, 0));
            Font yellowFont = FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD, new CMYKColor(0, 0, 255, 0));
Document document = new Document();

try
{
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("C:\\pdf\\StylingExample.pdf"));
    document.open();
    
    PdfPTable my_report_table  = new PdfPTable(4);
    PdfPCell table_cell;
                                
                                String hdept_id = "กกดกด";
                                
                                table_cell=new PdfPCell(new Phrase(hdept_id,font));
                                my_report_table.addCell(table_cell);
                                String hdept_name="กกกกกก";
                                table_cell=new PdfPCell(new Phrase(hdept_name,font));
                                my_report_table.addCell(table_cell);
                                String hmanager_id="CCCCCC";
                                table_cell=new PdfPCell(new Phrase(hmanager_id,font));
                                my_report_table.addCell(table_cell);
                                String hlocation_id="DDDDDD";
                                table_cell=new PdfPCell(new Phrase(hlocation_id,font));
                                my_report_table.addCell(table_cell);
                    for(int i=0;i<10;i++) {                
                                String dept_id = "DEPARTMENT_ID";
                                table_cell=new PdfPCell(new Phrase(dept_id,blueFont));
                                my_report_table.addCell(table_cell);
                                String dept_name="DEPARTMENT_NAME";
                                table_cell=new PdfPCell(new Phrase(dept_name,blueFont));
                                my_report_table.addCell(table_cell);
                                String manager_id="MANAGER_ID";
                                table_cell=new PdfPCell(new Phrase(manager_id,blueFont));
                                my_report_table.addCell(table_cell);
                                String location_id="LOCATION_ID";
                                table_cell=new PdfPCell(new Phrase(location_id,blueFont));
                                my_report_table.addCell(table_cell);
                                }
    
     /* Attach report table to PDF */
                                      
               
    //document.add(new Paragraph("Styling Example"));
 
    //Paragraph with color and font styles
   // Paragraph paragraphOne = new Paragraph("Some colored paragraph text", redFont);
   // document.add(paragraphOne);
    //Create chapter and sections
    Paragraph chapterTitle = new Paragraph(currentDate, blueFont);
    Chapter chapter1 = new Chapter(chapterTitle, 1);
    chapter1.setNumberDepth(0);
    
    Paragraph sectionContent = new Paragraph("กกกกกกกกกกกกกกกกกกกกกก", blueFont);
    chapter1.add(sectionContent);
 
    Paragraph sectionContent2 = new Paragraph("Section Text content\n\n", yellowFont);
    sectionContent2.setAlignment(sectionContent2.ALIGN_CENTER);
    chapter1.add(sectionContent2);
 
  
 
    
    document.add(chapter1);
    
    
    document.add(my_report_table); 
    document.close();
    
    
    writer.close();
} catch (Exception e)
{
    e.printStackTrace();
}
            %>
            
    </body>
</html>


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

pdf



Tag : Java, JAVA, JSP







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

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 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,058 )
บทความ ( 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 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 03
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 อัตราราคา คลิกที่นี่