close


 
Itextsharp PDF
//匯出檔案可以選擇另存OR開啟舊檔
System.IO.StringWriter stringWrite = new StringWriter();
        System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
        StringReader reader = new StringReader(stringWrite.ToString());
        Response.ContentType = "application/pdf";
        Response.ContentEncoding = System.Text.Encoding.UTF8;
        Response.AddHeader("content-disposition", "attachment;filename=" + FunId + ".pdf");


  //文件初始化
        Document doc = new Document(iTextSharp.text.PageSize.A4.Rotate(), 10, 10, 10, 5);//改為橫向
        MemoryStream Memory = new MemoryStream();
        PdfWriter writer = PdfWriter.GetInstance(doc, Memory);
        HTMLWorker parser = new HTMLWorker(doc);
        PdfWriter.GetInstance(doc, Response.OutputStream);
        //頁碼
        int pageN = writer.PageNumber;
        String text = "Page" + pageN + "of";
        //文件開啟
        doc.Open();


  //字型設定
        BaseFont baseFont = BaseFont.CreateFont(@"C:\WINDOWS\FONTS\kaiu.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
        //設定字體大小
        iTextSharp.text.Font font = new iTextSharp.text.Font(baseFont, 13);
        iTextSharp.text.Font font1 = new iTextSharp.text.Font(baseFont, 9);


        //設定表格需要幾攔幾列 (如果不設列,可能會在使用RowSpan或ColSpan發生錯誤)
        PdfPTable table = new PdfPTable(Length);
        table.WidthPercentage = 100;
//預設固定標題行數
        table.HeaderRows = 3;
        PdfPCell cell = null;
        //寫入標題
        cell = new PdfPCell(new Phrase(ExcelTitle, font));
        cell.Colspan =Length;//跨行
cell.Rowspan =Length;//跨列
        cell.HorizontalAlignment = Element.ALIGN_CENTER;//置中
    cell.HorizontalAlignment = Element.ALIGN_RIGHT;//靠右
    cell.HorizontalAlignment = Element.ALIGN_LEFT;//靠左
    cell.MinimumHeight = 20;//行寬
        table.AddCell(cell);

//調整Cell的框限
cell.Border = 4;//0無 1上2下3上下 4左5左上6左下7左上下 8右9右上10右下11右上下 12右左13左右上14左右下15 上下左右

arrow
arrow
    文章標籤
    asp.net
    全站熱搜
    創作者介紹
    創作者 鴨鴨仔 的頭像
    鴨鴨仔

    DUCK,Fearless!

    鴨鴨仔 發表在 痞客邦 留言(0) 人氣()