itextsharp c# asp.net 生成 pdf 文件
生活随笔
收集整理的這篇文章主要介紹了
itextsharp c# asp.net 生成 pdf 文件
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
一切的開始必須要有2個(gè)dll, 可以通過nuget 包xiazai, 關(guān)鍵字是itextsharp.
?
using iTextSharp.text; using iTextSharp.text.pdf; FileStream fs = new FileStream(Server.MapPath("pdf") + "\\" + "First PDF document6.pdf", FileMode.Create); //doneDocument document = new Document(PageSize.A4, 25, 25, 30, 30); PdfWriter writer = PdfWriter.GetInstance(document, fs);document.AddAuthor("Micke Blomquist");document.AddCreator("Sample application using iTextSharp");document.AddKeywords("PDF tutorial education");document.AddSubject("Document subject - Describing the steps creating a PDF document");document.AddTitle("The document title - PDF creation using iTextSharp");document.Open();document.Add(new Paragraph(""));以上就可以簡(jiǎn)單的在文檔中找到Doc1.pdf 了,現(xiàn)在會(huì)記入簡(jiǎn)單的css樣式。
?
Font arial = FontFactory.GetFont("Arial", 28, Font.BOLD, BaseColor.RED);//字體 Chunk c1 = new Chunk("A chunk represents an isolated string.", arial); c1.SetUnderline(0.5f, -1.5f);//下劃線 document.Add(c1);chunk是可以賦予很多的style,目前我只需要下劃線和基本的字體,顏色。接下來是table
?
PdfPTable table = new PdfPTable(2); //列table.TotalWidth = 216f; //table widthtable.LockedWidth = true; //配合table widthfloat[] widths = new float[] { 3f, 2f }; //table 的行比列 table.SetWidths(widths); table.SpacingBefore = 10f; //margin-toptable.SpacingAfter = 30f; //margin-bottomtable.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right (float) PdfPCell cell = new PdfPCell(new Phrase("content"));//cell.Colspan = 1; //列cell.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right (text)cell.Padding = 10;//cell.Border = 1; table.AddCell(cell);table.AddCell(cell);table.AddCell(cell);table.AddCell(cell);table.AddCell(cell);table.AddCell(cell);document.Add(table);table設(shè)計(jì)的是像html的float,首先給table知道幾列,以上是2列,所以所有的cell都是左右左右的排列。最后是圖片
?
document.Add(new Paragraph("JPG"));iTextSharp.text.Image gif = iTextSharp.text.Image.GetInstance(Server.MapPath("123.jpg"));document.Add(gif);?
完成了,這就是基本功了!
http://www.mikesdotnetting.com/article/80/create-pdfs-in-asp-net-getting-started-with-itextsharp
?
轉(zhuǎn)載于:https://www.cnblogs.com/stooges/p/4756202.html
總結(jié)
以上是生活随笔為你收集整理的itextsharp c# asp.net 生成 pdf 文件的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C1. 组队活动 Small(BNUOJ
- 下一篇: SQL Server XML转Table