iTextSharp pdf demo 学习总结
using iTextSharp.text;
using iTextSharp.text.pdf;
Document document = new Document();
PdfWriter writer = null;
int titleSize = 13;
int contentSize = 8;
Font font= new Font(baseFont, contentSize);
//添加字体,支持pdf中文显示:
BaseFont baseFont = BaseFont.CreateFont(@"C:\Windows\Fonts\simsun.ttc,0", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(string.Format("{0}-{1}.pdf", DateTime.Now.Second, DateTime.Now.Millisecond),
FileMode.Create));
document.Open();
PdfPTable table = new PdfPTable(5); //初始化5列表
table.WidthPercentage = 94f; //表格宽度:1-100f
table.SpacingBefore = 5f;
table.HorizontalAlignment = Element.ALIGN_CENTER;
table.SplitRows = true;
PdfPCell cell;
Paragraph p;
//
p = new Paragraph(" " + LaoshiPingyuValue, new Font(baseFont, contentSize));
cell = new PdfPCell(p);
cell.Border = Rectangle.NO_BORDER;
cell.HorizontalAlignment = Element.ALIGN_LEFT;
cell.Colspan = 5; //次cell跨5列
cell.FixedHeight = 45f; //设置多行数据快的高度
cell.SetLeading(4, 1); //设置多行数据的行间距
table.AddCell(cell);
return table;
//加载本地图片到pdf上
string imagePath = "../../Data/header.png";
private PdfPTable GetTableHeader(string imagePath)
{
PdfPTable table = new PdfPTable(1);
table.WidthPercentage = 100f;
table.SplitRows = true;
table.HeaderRows = 0;
PdfPCell cell;
//add 图片
Image image = Image.GetInstance(imagePath);
cell = new PdfPCell(image, true);
table.AddCell(cell);
return table;
}
document.Add(GetTableContent(content_zongji, titleSize, contentSize));
document.Close();
writer.Close();
相关文章
- pdf merge
- Java使用itextpdf生成PDF文件
- 对pdf指定区域截图并提取文字
- inkscape转换svg为pdf
- Magicodes.IE已支持导出Word、Pdf和Html
- PDF 编辑器——uPdf
- 博客新功能上线,可导出PDF……【2021.12.14】
- itext给已有pdf添加页眉页脚
- 《WEB安全渗透测试》(22)pdf文件预览安全吗?
- vue-pdf预览pdf报错
- 【资料合集】首届互联网新兵进阶在线峰会:讲义PDF+活动视频!(持续更新)
- 图片合成器,一键将目录中多个文件夹的图片转换为PDF
- android 开发 获取各种intent (图片、apk文件、excel、pdf等文件)
- Office web apps 打补丁后(安装PDF在线浏览) 错误解决
- python odoo pdf文件 位置获取
- markdown转为pdf文件
- acrobat pdf 按页拆分与合并
- CAD图如何转换成PDF?CAD导出PDF教程
- Java从PDF中根据关键字实现截图
- 功能/项目 导出pdf 包含图片 Magicodes.IE.Pdf
- wkhtmltopdfhtml php生成pdf快照,网页截图,网页快照完整版 (原)