1 / 13

ASP.NET 產生 PDF

ASP.NET 產生 PDF. 建國科技大學 資管系 饒瑞佶 2007 年. ITEXTSHARP 類別. 下載類別 http://sourceforge.net/projects/itextsharp/ 在專案中參考它. 加入參考. 程式需要的 namespace. Imports System Imports System.IO Imports iTextSharp.text Imports iTextSharp.text.pdf.

yelena
Download Presentation

ASP.NET 產生 PDF

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

  3. 加入參考

  4. 程式需要的namespace Imports SystemImports System.IOImports iTextSharp.textImports iTextSharp.text.pdf

  5. 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

  6. 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

  7. 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

  8. 執行結果

  9. 中文顯示問題

  10. 加入字型宣告 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))

More Related