CSharp: iTextSharp 5.13.2 create pdf

2023-11-12

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using iTextSharp.text;
using iTextSharp.awt;
using iTextSharp.javaone;
using iTextSharp.tool;
using iTextSharp.xmp;
using iTextSharp.xtra;
using iTextSharp.text.pdf;
using System.util;
using System.IO;
using System.Diagnostics;
 
 
 
namespace DuiTextCSharpDemoVS2010
{
 
    /// <summary>
    /// geovindu Geovin Du
    /// 涂聚文
    /// iTextSharp5 5.13.2
    /// </summary>
    public partial class _Default : System.Web.UI.Page
    {
     
        string fontfile = "/resources/fonts/SIMLI.TTF";
        private BaseFont dfont ;// = BaseFont.CreateFont("STSong-Light", "UniGB-UCS2-H", BaseFont.EMBEDDED);
        private BaseFont bfChinese = BaseFont.CreateFont("C://WINDOWS//Fonts//simsun.ttc,0", BaseFont.IDENTITY_H, false);//BaseFont.NOT_EMBEDDED
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            dfont = BaseFont.CreateFont(@System.Web.HttpContext.Current.Server.MapPath("resources/fonts/SIMLI.TTF"), "Identity-H", true); //Server.MapPath(fontfile)
 
           // iTextSharp.text.Font dufont = new iTextSharp.text.Font(dfont, 30, iTextSharp.text.Font.BOLD);
 
            iTextSharp.text.Font cnfont = new iTextSharp.text.Font(bfChinese, 30, iTextSharp.text.Font.BOLD);
            if (!IsPostBack)
            {
                try
                {
 
                    //Create document 
                    Document doc = new Document();
                    //Create PDF Table 
                    PdfPTable tableLayout = new PdfPTable(4);
                    //Create a PDF file in specific path 
                    PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(Server.MapPath("geovindu.pdf"), FileMode.Create));
                    //
                    writer.PageEvent = new DuEventIsHand();
 
                    //Open the PDF document 
                    doc.Open();
                    //doc.AddLanguage("");
                    doc.AddAuthor("geovindu, Geovin Du,涂聚文");
                    doc.AddCreator("涂聚文 itextsharp");
                    doc.AddKeywords("涂聚文itextsharp");
                    doc.AddSubject("涂聚文itextsharp");
                    doc.AddTitle("涂聚文itextsharp");
                    //
                   // PdfDocument pdf = new PdfDocument();
                    //PdfFont font = new PdfFont();
 
                    //Add Content to PDF 
                    doc.Add(Add_Content_To_PDF(tableLayout));
                    // Closing the document 
                    doc.Close();
                }
                catch (Exception ex)
                {
 
                    Response.Write(ex.Message.ToString());
 
 
                }
 
            }
        }
 
        /// <summary>
        ///
        /// </summary>
        /// <param name="tableLayout"></param>
        /// <returns></returns>
 
        private PdfPTable Add_Content_To_PDF(PdfPTable tableLayout)
        {
 
           // BaseFont bfChinese = BaseFont.CreateFont("C://WINDOWS//Fonts//simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
           // iTextSharp.text.Font fontChinese_11 = new iTextSharp.text.Font(bfChinese, 11, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(0, 0, 0));
 
 
            dfont = BaseFont.CreateFont(@System.Web.HttpContext.Current.Server.MapPath("resources/fonts/SIMLI.TTF"),"Identity-H", true);
           // iTextSharp.text.Font dufont = new iTextSharp.text.Font(dfont, 30, iTextSharp.text.Font.BOLD);
 
            iTextSharp.text.Font cnfont = new iTextSharp.text.Font(bfChinese, 30, iTextSharp.text.Font.BOLD);
 
 
            float[] headers = { 
                    20, 
                    20, 
                    30, 
                    30 
                }; //Header Widths 
            tableLayout.SetWidths(headers); //Set the pdf headers 
            tableLayout.WidthPercentage = 80; //Set the PDF File witdh percentage 
            //Add Title to the PDF file at the top 
            tableLayout.AddCell(new PdfPCell(new Phrase("Creating PDF file using iTextsharp 生成PDF文档", cnfont)));
            //Add header 
            AddCellToHeader(tableLayout, "姓名");
            AddCellToHeader(tableLayout, "高度");
            AddCellToHeader(tableLayout, "出生");
            AddCellToHeader(tableLayout, "父母");
            //Add body 
            AddCellToBody(tableLayout, "Sachin Tendulkar Geovin Du 涂聚文");
            AddCellToBody(tableLayout, "1.65 m");
            AddCellToBody(tableLayout, "April 24, 1973");
            AddCellToBody(tableLayout, "Ramesh Tendulkar, Rajni Tendulkar");
            AddCellToBody(tableLayout, "Mahendra Singh Dhoni");
            AddCellToBody(tableLayout, "1.75 m");
            AddCellToBody(tableLayout, "July 7, 1981");
            AddCellToBody(tableLayout, "Devki Devi, Pan Singh");
            AddCellToBody(tableLayout, "Virender Sehwag");
            AddCellToBody(tableLayout, "1.70 m");
            AddCellToBody(tableLayout, "October 20, 1978");
            AddCellToBody(tableLayout, "Aryavir Sehwag, Vedant Sehwag");
            AddCellToBody(tableLayout, "Virat Kohli");
            AddCellToBody(tableLayout, "1.75 m");
            AddCellToBody(tableLayout, "November 5, 1988");
            AddCellToBody(tableLayout, "Saroj Kohli, Prem Kohli");
            return tableLayout;
        }
 
        /// <summary>
        ///  Method to add single cell to the header 
        /// </summary>
        /// <param name="tableLayout"></param>
        /// <param name="cellText"></param>
        private void AddCellToHeader(PdfPTable tableLayout, string cellText)
        {
            iTextSharp.text.Font cnfont = new iTextSharp.text.Font(bfChinese, 30, iTextSharp.text.Font.BOLD);
            dfont = BaseFont.CreateFont(@System.Web.HttpContext.Current.Server.MapPath("resources/fonts/SIMLI.TTF"), "Identity-H", true);
            iTextSharp.text.Font dufont = new iTextSharp.text.Font(dfont, 30, iTextSharp.text.Font.BOLD);
            tableLayout.AddCell(new PdfPCell(new Phrase(cellText, cnfont))); //new Font(Font.HELVETICA, 8, 1, iTextSharp.text.Color.WHITE)
        }
        /// <summary>
        /// Method to add single cell to the body
        /// </summary>
        /// <param name="tableLayout"></param>
        /// <param name="cellText"></param>
 
        private void AddCellToBody(PdfPTable tableLayout, string cellText)
        {
            iTextSharp.text.Font cnfont = new iTextSharp.text.Font(bfChinese, 30, iTextSharp.text.Font.BOLD);
            dfont = BaseFont.CreateFont(@System.Web.HttpContext.Current.Server.MapPath("resources/fonts/SIMLI.TTF"), "Identity-H", true);
            iTextSharp.text.Font dufont = new iTextSharp.text.Font(dfont, 30, iTextSharp.text.Font.BOLD);
            tableLayout.AddCell(new PdfPCell(new Phrase(cellText, cnfont))); // new Font(Font.HELVETICA, 8, 1, iTextSharp.text.Color.BLACK)
 
 
        }
 
    }
}

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

CSharp: iTextSharp 5.13.2 create pdf 的相关文章

  • 当我在组合框中选择一个项目时,如何防止 TextChanged 事件?

    我有一个TextChanged http msdn microsoft com en us library system windows forms control textchanged aspx我的事件ComboBox http msd
  • 如何从 C# 中的 dataTable.Select( ) 查询中删除单引号?

    所以我有一个经销商名称列表 我正在我的数据表中搜索它们 问题是 一些傻瓜必须被命名为 Young s 这会导致错误 drs dtDealers Select DealerName dealerName 所以我尝试替换字符串 尽管它对我不起作
  • 使用 C# 登录《我的世界》

    我正在尝试为自己和一些朋友创建一个简单的自定义 Minecraft 启动器 我不需要启动 Minecraft 的代码 只需要登录的实际代码行 例如 据我所知 您过去可以使用 string netResponse httpGET https
  • 如何捕获未发送到 stdout 的命令行文本?

    我在项目中使用 LAME 命令行 mp3 编码器 我希望能够看到某人正在使用什么版本 如果我只执行 LAME exe 而不带参数 我会得到 例如 C LAME gt LAME exe LAME 32 bits version 3 98 2
  • 以编程方式读取 SQL Server 查询计划建议的 SQL 特定执行的索引?

    如果我在 SSMS 中运行此命令 set showplan xml on GO exec some procedure arg1 arg2 arg3 GO set showplan xml off GO 我获得查询执行中涉及的完整调用堆栈的
  • 查找进程的完整路径

    我已经编写了 C 控制台应用程序 当我启动应用程序时 不使用cmd 我可以看到它列在任务管理器的进程列表中 现在我需要编写另一个应用程序 在其中我需要查找以前的应用程序是否正在运行 我知道应用程序名称和路径 所以我已将管理对象搜索器查询写入
  • 当一组凭据下的计划任务启动的进程在另一组凭据下运行另一个程序时,Windows 是否有限制

    所以我有一个简单的例子 其中我有应用程序 A 它对用户 X 本地管理员 有一些硬编码的凭据 然后它使用硬编码的绝对路径启动带有这些凭据的应用程序 B A 和 B 以及 dotnet 控制台应用程序 但是它们不与控制台交互 只是将信息写入文件
  • C# 数据表更新多行

    我如何使用数据表进行多次更新 我找到了这个更新 1 行 http support microsoft com kb 307587 my code public void ExportCSV string SQLSyntax string L
  • 从客户端访问 DomainService 中的自定义对象

    我正在使用域服务从 Silverlight 客户端的数据库中获取数据 在DomainService1 cs中 我添加了以下内容 EnableClientAccess public class Product public int produ
  • Python 属性和 Swig

    我正在尝试使用 swig 为一些 C 代码创建 python 绑定 我似乎遇到了一个问题 试图从我拥有的一些访问器函数创建 python 属性 方法如下 class Player public void entity Entity enti
  • 类型约束

    我有以下类层次结构 class Header IEnumerable
  • 打破 ReadFile() 阻塞 - 命名管道 (Windows API)

    为了简化 这是一种命名管道服务器正在等待命名管道客户端写入管道的情况 使用 WriteFile 阻塞的 Windows API 是 ReadFile 服务器已创建启用阻塞的同步管道 无重叠 I O 客户端已连接 现在服务器正在等待一些数据
  • 如何在 C 中安全地声明 16 位字符串文字?

    我知道已经有一个标准方法 前缀为L wchar t test literal L Test 问题是wchar t不保证是16位 但是对于我的项目 我需要16位wchar t 我还想避免通过的要求 fshort wchar 那么 C 不是 C
  • 为什么我的单选按钮不起作用?

    我正在 Visual C 2005 中开发 MFC 对话框应用程序 我的单选按钮是 m Small m Medium 和 m Large 它们都没有在我的 m Summary 编辑框中显示应有的内容 可能出什么问题了 这是我的代码 Pizz
  • 保护 APK 中的字符串

    我正在使用 Xamarin 的 Mono for Android 开发一个 Android 应用程序 我目前正在努力使用 Google Play API 添加应用内购买功能 为此 我需要从我的应用程序内向 Google 发送公共许可证密钥
  • 使 Guid 属性成为线程安全的

    我的一个类有一个 Guid 类型的属性 该属性可以由多个线程同时读写 我的印象是对 Guid 的读取和写入不是原子的 因此我应该锁定它们 我选择这样做 public Guid TestKey get lock testKeyLock ret
  • 使用 C 在 OS X 中获取其他进程的 argv

    我想获得其他进程的argv 例如ps 我使用的是在 Intel 或 PowerPC 上运行的 Mac OS X 10 4 11 首先 我阅读了 ps 和 man kvm 的代码 然后编写了一些 C 代码 include
  • Objective-C / C 给出枚举默认值

    我在某处读到过关于给枚举默认值的内容 如下所示 typedef enum MarketNavigationTypeNone 0 MarketNavigationTypeHeirachy 1 MarketNavigationTypeMarke
  • 灵气序列解析问题

    我在使用 Spirit Qi 2 4 编写解析器时遇到一些问题 我有一系列键值对以以下格式解析
  • 如何将十六进制字符串转换为无符号长整型?

    我有以下十六进制值 CString str str T FFF000 如何将其转换为unsigned long 您可以使用strtol作用于常规 C 字符串的函数 它使用指定的基数将字符串转换为 long long l strtol str

随机推荐

  • C++中float和double的比较

    在c 开发中 double或者float类型判断相等性不能简单的用等于符号 进行 一般会采用如下方式进行判断 static inline bool DoubleEqual double a double b return fabs a b
  • Log4j学习笔记

    Log4j学习笔记 1 入门实例 2 Log4j基本使用方法 2 1 定义配置文件 2 2 在代码中使用Log4j 2 3 日志级别 本文参考https blog csdn net u013870094 article details 79
  • 实战--Kafka学习(二)

    问题导读1 Kafka工作包含哪些流程 2 为防止log文件过大导致数据定位效率低下 kafka引入了什么 3 Kafka生产者分区的原因和原则是什么 4 Kafka数据可靠性是如何保证的 3 1 Kafka工作流程及文件存储机制Kafka
  • 哈希及其应用(字典,加密等)

    一 名词说明 Hash 一般翻译做散列 杂凑 或音译为哈希 是把任意长度的输入 又叫做预映射pre image 通过散列算法变换成固定长度的输出 该输出就是散列值 这种转换是一种压缩映射 也就是 散列值的空间通常远小于输入的空间 不同的输入
  • kafka学习

    链接1 Kafka入门教程 香菜 的博客 CSDN博客 链接2 https mbd baidu com ug share mbox 4a83aa9e65 share product smartapp tk d716b5f663babe030
  • mysql函数及关键字使用

    collect set collect set col 函数只接受 基本数据类型 它的主要作用是将某字段的值进行去重汇总 产生array类型字段 MySQL中concat函数 连接字符串 MySQL中concat函数 使用方法 concat
  • java语法基础练习

    1 阅读示例 EnumTest java 并运行 分析结果 代码 public class EnumTest public static void main String args Size s Size SMALL Size t Size
  • MSP432学习笔记:IAR的环境配置(官方demo程序的测试)

    近来入手一块MSP432 折腾了一天 终于把官方demo程序导入IAR 可以愉快的写代码了 以下是我个人的解决办法 首先 如果要使用IAR对TI的单片机进行开发 首先要下载对应的单片机型号的MSPWARE 本人目前使用的是TI的MSP432
  • python实现的一些方法,可以直接拿来用的那种

    1 日期生成 很多时候我们需要批量生成日期 方法有很多 这里分享两段代码 获取过去 N 天的日期 import datetime def get nday list n before n days for i in range 1 n 1
  • 梯度下降算法

    下面这篇文章讲的非常不错 https www jianshu com p c7e642877b0e 转载于 https www cnblogs com lvchaoshun p 11403808 html
  • 【网络】协议定制+序列化/反序列化

    为什么要序列化 如果光看定义很难理解序列化的意义 那么我们可以从另一个角度来推导出什么是序列化 那么究竟序列化的目的是什么 其实序列化最终的目的是为了对象可以跨平台存储 和进行网络传输 而我们进行跨平台存储和网络传输的方式就是IO 而我们的
  • leetcode刷题(5)

    各位朋友们 大家好 今天是我leedcode刷题的第五篇 我们一起来看看吧 文章目录 栈的压入 弹出序列 题目要求 用例输入 提示 做题思路 代码实现 C语言代码实现 Java代码实现 最小栈 题目要求 用例输入 提示 做题思路 代码实现
  • eclipse中使用Install New software下载资源超时解决

    问题 使用eclipse中提供的Help菜单 Install New software 已填入正确的链接地址 但是在下载过程中出现错误 Some sites could not be found See the error log for
  • 宝塔面板升级踩坑:ImportError: class/PluginLoader.so: undefined symbol: PyImport_GetModule

    今天在宝塔面板升级了PHP8 但是站点的PHP版本选择仍然没有PHP8以上的版本 百度了一下说是要升级宝塔面板 于是在面板首页右上角进行了升级 结果升级后发现安全入口无法打开 于是用ssh登录服务器 执行命令 etc init d bt d
  • 推荐 20 款 IDEA 主题!

    官方对主题模块的介绍 作为一名开发人员 您需要使用大量文本资源 编辑器中的源代码 搜索结果 调试器信息 控制台输入和输出等等 颜色和字体样式用于格式化这个文本 并帮助您更好地理解它一目了然 个人感觉 每天我们大半的时间都是在跟代码打交道 时
  • Vue前端代码风格指南超级详细

    本文仅作日常项目开发中的知识补充 不必按顺序阅读 如果已经知悉 请跳过 一 命名规范 现有常用的命名规范 camelCase 小驼峰 首字母小写 PsscalCase 大驼峰 首字母大写 kebab case 短横线连接式 Snake 下划
  • VSCode好用的插件

    文章目录 前言 1 Snippet Creator easy snippet 自定义代码 2 Indent Rainbow 代码缩进 3 Chinese Simplified Language Pack 中文包 4 Path Intelli
  • react项目配置 @ 为src根目录

    前置 修改jsconfig json文件 compilerOptions jsx react experimentalDecorators true baseUrl paths src 1 原生create react app 的情况 若已
  • 16、什么是拟牛顿法(Quasi-Newton Methods)?

    拟牛顿法是求解非线性优化问题最有效的方法之一 于20世纪50年代由美国Argonne国家实验室的物理学家W C Davidon所提出来 Davidon设计的这种算法在当时看来是非线性优化领域最具创造性的发明之一 不久R Fletcher和M
  • CSharp: iTextSharp 5.13.2 create pdf

    using System using System Collections Generic using System Web using System Web UI using System Web UI WebControls using