3C科技 娛樂遊戲 美食旅遊 時尚美妝 親子育兒 生活休閒 金融理財 健康運動 寰宇綜合

Zi 字媒體

2017-07-25T20:27:27+00:00
加入好友
使用PDF元件[itextsharp]到C#專案 新增中文字+顏色+大小 程式   資料來源:http://renjin.blogspot.tw/2009/01/using-chinese-fonts-in-itextsharp.html          http://www.cc.ntu.edu.tw/chinese/epaper/0015/20101220_1509.htm   00.去GOOGLE 搜尋itextsharp 並且下載 01.解壓 itextsharp-dll-core.zip     iTextSharp.xml     itextsharp.dll 02.解壓 itextsharp-dll-pdfa.zip     itextsharp.pdfa.dll 03.解壓 itextsharp-dll-xtra.zip         itextsharp.xtra.dll 04.專案引入三個DLL參考 05.在程式碼中加入引用函式庫語法     //PDF_start     using System.IO;     using iTextSharp.text;     using iTextSharp.text.pdf;     //PDF_end      06.建立一個按鈕事件並加入測試程式碼     private void button1_Click(object sender, EventArgs e)//基本使用測試     {         iTextSharp.text.Document doc = new Document(iTextSharp.text.PageSize.A4, 10, 10, 42, 35);//左,右,上,下 邊界         iTextSharp.text.pdf.PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream(“test.pdf”, FileMode.Create));         doc.Open();         Paragraph paragraph = new Paragraph(“this is my first line.”);         doc.Add(paragraph);         doc.Close();     } 07.    建立一個按鈕事件並加入測試程式碼     private void button2_Click(object sender, EventArgs e)//顯示中文+顏色     {         //資料來源:http://renjin.blogspot.tw/2009/01/using-chinese-fonts-in-itextsharp.html         //http://www.cc.ntu.edu.tw/chinese/epaper/0015/20101220_1509.htm         iTextSharp.text.Document doc = new Document(iTextSharp.text.PageSize.A4, 10, 10, 42, 35);//左,右,上,下 邊界         iTextSharp.text.pdf.PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream(“test2.pdf”, FileMode.Create));         iTextSharp.text.pdf.BaseFont bfTW = BaseFont.CreateFont(“01.ttf”, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);//01.ttf是微軟正黑體         iTextSharp.text.pdf.BaseFont bfCN = BaseFont.CreateFont(“01.ttf”, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);         iTextSharp.text.Font fontTW = new iTextSharp.text.Font(bfTW, 40, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(51, 0, 153));         iTextSharp.text.Font fontCN = new iTextSharp.text.Font(bfCN, 12, iTextSharp.text.Font.NORMAL, BaseColor.RED);         doc.Open();         Paragraph paragraph = new Paragraph(“this is my first line.”);         doc.Add(paragraph);         doc.Add(new Paragraph(“foolish”, fontTW));         doc.Add(new Paragraph(“難得糊塗”, fontTW));//繁中         doc.Add(new Paragraph(“难得糊涂”, fontCN));//簡中         doc.Close();     }          

本文由jashliaoeuwordpress提供 原文連結

寫了 5860316篇文章,獲得 23313次喜歡
精彩推薦