#region 下载说明书PDF
protected void lbtnDownPDF_Click(object sender, EventArgs e)
{
int pid = ConvertHelper.GetInteger(Request["PID"]);
pds = p.GetModel(pid);
#region 第一种方法
DataTable datatable = new DataTable(dt.ToString());
try
{
string Url1 = "pdfBook\\" + GetNewName() + ".pdf";
//创建一个文档对象,并设置他的初始化大小
Rectangle pSize = new Rectangle(144, 90);
//文档的背景色
pSize.BackgroundColor = Color.WHITE;
//常用页面大小 PageSize.A4;
Document document = new Document(PageSize.A4);
PdfWriter.GetInstance(document, new FileStream(Server.MapPath(Url1), FileMode.Create));
BaseFont bfChinese = BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
Font fontChinese = new Font(bfChinese, 12, Font.NORMAL, new Color(0, 0, 0));
Font headerChinese = new Font(bfChinese, 15, Font.BOLD, new Color(0, 0, 0));
Font beizhufontChinese = new Font(bfChinese, 10, Font.ITALIC, new Color(255, 0, 0));
#region 页眉和页脚
/**
* HeaderFooter的第2个参数为非false时代表打印页码
* 页眉页脚中也可以加入图片,并非只能是文字
*/
HeaderFooter header = new HeaderFooter(new Phrase("陕西龙凤祥珠宝版权所有", beizhufontChinese), false);

//设置是否有边框等
// header.setBorder(Rectangle.NO_BORDER);
header.Border = Rectangle.BOTTOM_BORDER;
header.Alignment = 1;
header.BorderColor = Color.RED;
document.Header = header;

HeaderFooter footer = new HeaderFooter(new Phrase("-", beizhufontChinese), new Phrase("-", beizhufontChinese));
/**
* 0是靠左
* 1是居中
* 2是居右
*/
footer.Alignment = 1;
footer.BorderColor = Color.RED;
footer.Border = Rectangle.BOTTOM_BORDER;
document.Footer = footer;

/**
* 页眉页脚的设置一定要在open前设置好
*/
#endregion
document.Open();

//按设置的字体输出文本
string contents = replaceHtmlCode(pds.ProductName);
string details = replaceHtmlCode(pds.ProductDetail);
Paragraph heading = new Paragraph(contents, headerChinese);
heading.SpacingAfter = 18f;
heading.Alignment = 1;
//heading.IndentationLeft = 220f;
document.Add(heading);

MultiColumnText columns = new MultiColumnText();

columns.AddSimpleColumn(36f, 336f);

columns.AddSimpleColumn(360f, document.PageSize.Width - 36f);

Paragraph detail = new Paragraph(details, fontChinese);
detail.SpacingAfter = 9f;
detail.Alignment = Element.ALIGN_JUSTIFIED;
detail.IndentationLeft = 12f;//全文都缩进了
//document.Add(detail);
//输出图片到PDF文件
string Url = "../uploadpic\\" + pds.Picture;//<img src="../uploadpic/20150213/wm201521317692.jpg" />
iTextSharp.text.Image jpeg01 = iTextSharp.text.Image.GetInstance(Server.MapPath(Url));
jpeg01.IndentationLeft = 150f;
//document.Add(jpeg01);
columns.AddElement(detail);
columns.AddElement(jpeg01);
columns.AddElement(detail);
columns.AddElement(detail);
columns.AddElement(detail);
//columns.AddElement(end);
document.Add(columns);
//Paragraph end = new Paragraph("陕西龙凤祥珠宝版权所有", beizhufontChinese);
//end.IndentationLeft = 200f;
//document.Add(end);
document.Close();

#region 自动下载
// 保存文件的物理路径
string FullPath = HttpContext.Current.Server.MapPath(Url1);
// 初始化FileInfo类的实例,作为文件路径的包装
FileInfo FI = new FileInfo(FullPath);
// 判断文件是否存在
if (FI.Exists)
{
// 将文件保存到本机
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(FI.Name));
Response.AddHeader("Content-Length", FI.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Filter.Close();
Response.WriteFile(FI.FullName);
Response.End();
}
#endregion
}
catch (DocumentException de)
{
Response.Write(de.ToString());
}
#endregion

}
#endregion

c# iText 生成PDF 有文字,图片,表格,文字样式,对齐方式,页眉页脚,等等等,的更多相关文章

  1. 【PDF】java使用Itext生成pdf文档--详解

    [API接口]  一.Itext简介 API地址:javadoc/index.html:如 D:/MyJAR/原JAR包/PDF/itext-5.5.3/itextpdf-5.5.3-javadoc/ ...

  2. Java Itext 生成PDF文件

    利用Java Itext生成PDF文件并导出,实现效果如下: PDFUtil.java package com.jeeplus.modules.order.util; import java.io.O ...

  3. itext 生成pdf文件添加页眉页脚

    原文来自:https://www.cnblogs.com/joann/p/5511905.html 我只是记录所有jar版本,由于版本冲突及不兼容很让人头疼的,一共需要5个jar, 其中itextpd ...

  4. JavaWeb项目生成PDF文件添加水印图片并导出

    一.前言 首先需要在Maven中添加相应的jar包依赖,若项目没用到Maven,也可自行下载相应所需的jar包(itextpdf.jar 与 itext-asian.jar),如下图所示.点此下载 M ...

  5. iText + Freemarker实现pdf的导出,支持中文、css以及图片,页眉页脚,页眉添加图片

    本文为了记录自己的实现过程,具体的实现步骤是参考博文 https://www.cnblogs.com/youzhibing/p/7692366.html 来实现的,只是在他的基础上添加了页眉页脚及页眉 ...

  6. 在linux环境下使用itext生成pdf

    转载请注明出处 https://www.cnblogs.com/majianming/p/9537173.html 项目中需要对订单生成pdf文件,在不断的尝试之后,终于生成了比较满意的pdf文档. ...

  7. 用itext生成PDF报错:Font 'STSong-Light1' with 'UniGB-UCS2-H' is not recognized.

    用itext生成PDF报错,加上try catch捕获到异常是 BaseFont bFont = BaseFont.createFont("STSong-Light1", &quo ...

  8. 【Itext】7步制作Itext5页眉页脚pdf实现第几页共几页

    itext5页眉页脚工具类,实现page x of y 完美兼容各种格式大小文档A4/B5/B3,兼容各种文档格式自动计算页脚XY轴坐标 鉴于没人做的这么细致,自己就写了一个itext5页眉页脚工具类 ...

  9. C#word(2007)操作类--新建文档、添加页眉页脚、设置格式、添加文本和超链接、添加图片、表格处理、文档格式转化

    转:http://www.cnblogs.com/lantionzy/archive/2009/10/23/1588511.html 1.新建Word文档 #region 新建Word文档/// &l ...

随机推荐

  1. TIME_WAIT Accumulation and Port Exhaustion

    客户端实现连接的唯一性 HTTP The Definitive Guide 4.2.7 TIME_WAIT Accumulation and Port Exhaustion TIME_WAIT por ...

  2. 不再依赖A*,利用C++编写全新寻路算法

    一,说在前面的话 大概在半年前,看见一到信息竞赛题:在任意方格阵中设置障碍物,确定起始点后,求这两点之间路径.当时觉得蛮有意思的,但是没有时间去做,今天花了两个小时来实现它.据说有一个更高级的寻路算法 ...

  3. 实时流计算Spark Streaming原理介绍

    1.Spark Streaming简介 1.1 概述 Spark Streaming 是Spark核心API的一个扩展,可以实现高吞吐量的.具备容错机制的实时流数据的处理.支持从多种数据源获取数据,包 ...

  4. 记ambari启用kerberos添加kafka组件后yarn和hive出现Failure unspecified at GSS-API level (Mechanism level: Checksum failed)--403错误

    出现警告的过程是: 1.搭建ambari集群成功后,添加了hdfs和zk组件,然后启用了kerberos: 2.kerberos启用完毕后添加hbase和yarn.MapReduce.hive都没有出 ...

  5. SHELL脚本自动备份数据库

    #!/bin/bash db_user="root" db_passwd="dddddd " db_name="mmmmmm" cd /db ...

  6. 使用jQuery为文本框、单选框、多选框、下拉框、下拉多选框设值及返回值的处理

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  7. ECMAScript与JavaScript

    ECMAScript发展史: 1997 1998.6 1999.12 2008.7 2009.12 2015.61996年11月 javaScript创造者Netscape公司将javaScript提 ...

  8. 大数据相关的面试题(摘自网络)hbase,kafka,spark

    1.讲讲你做的过的项目, 项目里有哪些难点重点呢?    kafkaDirect ES  /hive  kafka producer   难点值得一提的有两点:  1.rdd中用到外部变量的时候如何处 ...

  9. cocos2d-x 3.3 引用【#include "cocos-ext.h"】头文件出现编译错误

    添加[#include "cocos-ext.h"] 头文件后报错 f:\projects\test_httpclient\cocos2d\extensions\gui\cccon ...

  10. win7 eclipse设置Courier New字体

    win7系统 1.控制面板-->字体.找到Courier New 字体,右键->显示,这种字体就开始变亮了. 2.eclipse里设置: windows-->Preferences- ...