Presentation is loading. Please wait.

Presentation is loading. Please wait.

ASP.NET 產生 PDF 建國科技大學 資管系 饒瑞佶 2007 年. ITEXTSHARP 類別 下載類別 下載類別

Similar presentations


Presentation on theme: "ASP.NET 產生 PDF 建國科技大學 資管系 饒瑞佶 2007 年. ITEXTSHARP 類別 下載類別 下載類別"— Presentation transcript:

1 ASP.NET 產生 PDF 建國科技大學 資管系 饒瑞佶 2007 年

2 ITEXTSHARP 類別 下載類別 http://sourceforge.net/projects/itextsharp/ 下載類別 http://sourceforge.net/projects/itextsharp/ http://sourceforge.net/projects/itextsharp/ 在專案中參考它 在專案中參考它

3 加入參考

4

5

6 Imports System Imports System.IO Imports iTextSharp.text Imports iTextSharp.text.pdf 程式需要的 namespace

7

8 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Request.QueryString("id") = 1 Then ShowHello() Else ShowTable() End If End Sub

9 Sub ShowHello() Dim doc As Document = New Document PdfWriter.GetInstance(doc, New FileStream(Request.PhysicalApplicationPath + "\1.pdf", FileMode.Create)) doc.Open() doc.Add(New Paragraph("Hello World")) doc.Close() Response.Redirect("~/1.pdf") End Sub

10 Sub ShowTable() Dim doc As Document = New Document PdfWriter.GetInstance(doc, New FileStream(Request.PhysicalApplicationPath + "\2.pdf", FileMode.Create)) doc.Open() Dim table As Table = New Table(3) table.BorderWidth = 1 table.BorderColor = New Color(0, 0, 255) table.Padding = 3 table.Spacing = 1 Dim cell As Cell = New Cell("header") cell.Header = True cell.Colspan = 3 table.AddCell(cell) cell = New Cell("example cell with colspan 1 and rowspan 2") cell.Rowspan = 2 cell.BorderColor = New Color(255, 0, 0) table.AddCell(cell) table.AddCell("1.1") table.AddCell("2.1") table.AddCell("1.2") table.AddCell("2.2") table.AddCell("cell test1") cell = New Cell("big cell") cell.Rowspan = 2 cell.Colspan = 2 cell.HorizontalAlignment = Element.ALIGN_CENTER cell.VerticalAlignment = Element.ALIGN_MIDDLE cell.BackgroundColor = New Color(192, 192, 192) table.AddCell(cell) table.AddCell("cell test2") doc.Add(table) doc.Close() Response.Redirect("~/2.pdf") End Sub

11 執行結果

12 中文顯示問題

13 加入字型宣告 Dim bf As BaseFont = BaseFont.CreateFont("C:\WINDOWS\Fonts\KAIU.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED) Dim font1 As iTextSharp.text.Font = New iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.NORMAL) 將字型加入 doc.Add(New Paragraph(“ 小名 22233", font1))


Download ppt "ASP.NET 產生 PDF 建國科技大學 資管系 饒瑞佶 2007 年. ITEXTSHARP 類別 下載類別 下載類別"

Similar presentations


Ads by Google