using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
using System.Diagnostics;
namespace ConsoleApplication1
{
class pdfCreater
{
/// create pdf
/// </summary>
public static void CreatePdf()
{
iTextSharp.text.Document doc1 = new Document(PageSize.A4);
iTextSharp.text.Document doc2 = new Document(PageSize.A4); try
{
PdfWriter.GetInstance(doc1, new FileStream(@"D:\test1.pdf", FileMode.Create));
PdfWriter.GetInstance(doc2, new FileStream(@"D:\test2.pdf", FileMode.Create)); #region 设置PDF的头信息,一些属性设置,在Document.Open 之前完成
doc1.AddAuthor("cxa");
doc1.AddCreationDate();
doc1.AddCreator("cxa");
doc1.AddSubject("使用Do Net 创建了一个pdf1");
doc1.AddTitle("这是个标题");
doc1.AddKeywords("什么是keyword?不清楚反正这是个keyword"); doc2.AddAuthor("cxa");
doc2.AddCreationDate();
doc2.AddCreator("cxa");
doc2.AddSubject("使用Do Net 创建了一个pdf2");
doc2.AddTitle("这是个标题");
doc2.AddKeywords("什么是keyword?不清楚反正这是个keyword");
//自定义头
doc1.AddHeader("Expires", "0"); //0表示立即过期。我猜是立即生效
doc2.AddHeader("Expires", "0"); //0表示立即过期。我猜是立即生效
#endregion //打开document,此时打开啥呀没有
doc1.Open();
doc2.Open();
//载入字体
BaseFont bf = BaseFont.CreateFont("C:/Windows/Fonts/SIMHEI.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
iTextSharp.text.Font font = new iTextSharp.text.Font(bf);
doc1.Add(new Paragraph("这是一个由C#创建的pdf文件,6661", font));
doc2.Add(new Paragraph("这是一个由C#创建的pdf文件,6662", font));
doc1.Close();
doc2.Close();
Process.Start(@"D:\test1.pdf");
Process.Start(@"D:\test2.pdf");
}
catch (DocumentException de)
{
Console.WriteLine(de.Message); Console.ReadKey();
}
catch (IOException io)
{
Console.WriteLine(io.Message); Console.ReadKey();
}
}
public static void CreatePdf2()
{ iTextSharp.text.Document doc = new Document(PageSize.A4, 36, 72, 108, 180);
try
{
PdfWriter.GetInstance(doc, new FileStream(@"d:\test3.pdf", FileMode.Create));
doc.Open();
//创建表格
PdfPTable table = new PdfPTable(3); PdfPCell cell = new PdfPCell(new Phrase("Header spanning 3 columns")); cell.Colspan = 3; cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
cell.BorderColor = BaseColor.RED;
cell.BorderWidth = 2F; table.AddCell(cell);
table.AddCell("Col 1 Row 1"); table.AddCell("Col 2 Row 1"); table.AddCell("Col 3 Row 1"); table.AddCell("Col 1 Row 2"); table.AddCell("Col 2 Row 2"); table.AddCell("Col 3 Row 2"); doc.Add(table);
Image jpeg = Image.GetInstance(@"D:\re.jpg");
doc.Add(jpeg);
doc.Add(new Paragraph("this is rege"));
doc.Close();
Process.Start(@"d:\test3.pdf");
}
catch (DocumentException de)
{
Console.WriteLine(de.Message);
}
catch (IOException io)
{
Console.WriteLine(io.Message);
} }
}
}

  

iTextSharp操作pdf之pdfCreater的更多相关文章

  1. 【转载】 C#工具类:使用iTextSharp操作PDF文档

    iTextSharp是一个用于操作PDF文件的组件DLL程序,在C#程序中可以引用iTextSharp组件,用于开发与PDF文件相关的报表等功能,利用iTextSharp组件提供出来的方法接口,我们可 ...

  2. C#使用ITextSharp操作pdf

    在.NET中没有很好操作pdf的类库,如果你需要对pdf进行编辑,加密,模板打印等等都可以选择使用ITextSharp来实现. 第一步:可以点击这里下载,新版本的插件升级和之前对比主要做了这几项重大改 ...

  3. itextsharp操作pdf——插入图片、二维码等

    简单介绍 业务需求,需要往pdf图纸上添加二维码功能,将实现过程记录下来 下载类库 直接下载 添加引用 添加命名空间 using System.IO; using iTextSharp.text.pd ...

  4. asp.net for itextsharp 操作pdf

    今天分享下昨天做的一个东西 asp.net 的文件 zip 批量下载,首先你需要去 到http://dotnetzip.codeplex.com这个站点下载zip 的包,在里面找到 Ionic.Zip ...

  5. 【译】在Asp.Net中操作PDF - iTextSharp - 利用列进行排版

    原文 [译]在Asp.Net中操作PDF - iTextSharp - 利用列进行排版 在使用iTextSharp通过ASP.Net生成PDF的系列文章中,前面的文章已经讲述了iTextSharp所涵 ...

  6. 【译】在Asp.Net中操作PDF - iTextSharp - 绘制矢量图

    原文 [译]在Asp.Net中操作PDF - iTextSharp - 绘制矢量图 在上一篇iTextSharp文章中讲述了如何将现有的图片插入PDF中并对其进行操作.但有时,你需要在PDF中绘制不依 ...

  7. 【译】在Asp.Net中操作PDF – iTextSharp - 操作图片

    原文 [译]在Asp.Net中操作PDF – iTextSharp - 操作图片 作为我的iTextSharp系列的文章的第七篇,开始探索使用iTextSharp在PDF中操作图片,理解本篇文章需要看 ...

  8. 【译】在Asp.Net中操作PDF – iTextSharp - 使用表格

    原文 [译]在Asp.Net中操作PDF – iTextSharp - 使用表格 使用Asp.Net生成PDF最常用的元素应该是表格,表格可以帮助比如订单或者发票类型的文档更加格式化和美观.本篇文章并 ...

  9. 【译】在Asp.Net中操作PDF – iTextSharp - 使用链接和书签

    原文 [译]在Asp.Net中操作PDF – iTextSharp - 使用链接和书签 用户和PDF文档的交互可以通过锚(链接)和书签进行,接着我前面iTextSharp的系列文章,本篇文章主要讲通过 ...

随机推荐

  1. Object 接受集合里面的任意数据类型 所有的类型默认继承object

  2. BZOJ 2152 聪聪可可(树形DP)

    给出一颗n个点带边权的树(n<=20000),求随机选择两个点,使得它们之间的路径边权是3的倍数的概率是多少. 首先总的对数是n*n,那么只需要统计路径边权是3的倍数的点对数量就行了. 考虑将无 ...

  3. 洛谷P2894[USACO08FEB]酒店Hotel(线段树)

    问题描述 奶牛们最近的旅游计划,是到苏必利尔湖畔,享受那里的湖光山色,以及明媚的阳光.作为整个旅游的策划者和负责人,贝茜选择在湖边的一家著名的旅馆住宿.这个巨大的旅馆一共有N (1 <= N & ...

  4. 【Java】数组升序和降序

    int[] x={1,6,4,8,6,9,12,32,76,34,23}; 升序: Arrays.sort(x); 降序: resort(x); public int[] resort(int[] n ...

  5. 【Java】常用POI生成Excel文档设置打印样式

    package poi_test; import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi ...

  6. C++解析(1):C到C++的升级

    0.目录 1.C与C++的关系 2.C到C++的升级 2.1 语言的实用性 2.2 register关键字 2.3 同名的全局变量 2.4 struct关键字 2.5 int f() 与 int f( ...

  7. Redis的键值命令、服务器命令

    Redis提供了丰富的命令对数据库和各种数据类型进行操作,这些命令可以在Linux 终端使用.在编程时,比如各类语言包,这些命令都有对应的方法. 键值命令 服务器命令 获取数据库中所有键名 >k ...

  8. 数字表格(product)

    Portal -->broken qwq Description ​  求\(\prod\limits_{i=1}^n\prod\limits_{j=1}^m f[gcd(i,j)](mod\ ...

  9. C++之面向对象编程20170912

    /*************************************************************************************************** ...

  10. HTML+CSS鼠标悬停效果

    HTML+CSS实现鼠标悬停效果 HTML: <link href="style.css" rel="stylesheet"> <a clas ...