iTextSharp操作pdf之pdfCreater
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的更多相关文章
- 【转载】 C#工具类:使用iTextSharp操作PDF文档
iTextSharp是一个用于操作PDF文件的组件DLL程序,在C#程序中可以引用iTextSharp组件,用于开发与PDF文件相关的报表等功能,利用iTextSharp组件提供出来的方法接口,我们可 ...
- C#使用ITextSharp操作pdf
在.NET中没有很好操作pdf的类库,如果你需要对pdf进行编辑,加密,模板打印等等都可以选择使用ITextSharp来实现. 第一步:可以点击这里下载,新版本的插件升级和之前对比主要做了这几项重大改 ...
- itextsharp操作pdf——插入图片、二维码等
简单介绍 业务需求,需要往pdf图纸上添加二维码功能,将实现过程记录下来 下载类库 直接下载 添加引用 添加命名空间 using System.IO; using iTextSharp.text.pd ...
- asp.net for itextsharp 操作pdf
今天分享下昨天做的一个东西 asp.net 的文件 zip 批量下载,首先你需要去 到http://dotnetzip.codeplex.com这个站点下载zip 的包,在里面找到 Ionic.Zip ...
- 【译】在Asp.Net中操作PDF - iTextSharp - 利用列进行排版
原文 [译]在Asp.Net中操作PDF - iTextSharp - 利用列进行排版 在使用iTextSharp通过ASP.Net生成PDF的系列文章中,前面的文章已经讲述了iTextSharp所涵 ...
- 【译】在Asp.Net中操作PDF - iTextSharp - 绘制矢量图
原文 [译]在Asp.Net中操作PDF - iTextSharp - 绘制矢量图 在上一篇iTextSharp文章中讲述了如何将现有的图片插入PDF中并对其进行操作.但有时,你需要在PDF中绘制不依 ...
- 【译】在Asp.Net中操作PDF – iTextSharp - 操作图片
原文 [译]在Asp.Net中操作PDF – iTextSharp - 操作图片 作为我的iTextSharp系列的文章的第七篇,开始探索使用iTextSharp在PDF中操作图片,理解本篇文章需要看 ...
- 【译】在Asp.Net中操作PDF – iTextSharp - 使用表格
原文 [译]在Asp.Net中操作PDF – iTextSharp - 使用表格 使用Asp.Net生成PDF最常用的元素应该是表格,表格可以帮助比如订单或者发票类型的文档更加格式化和美观.本篇文章并 ...
- 【译】在Asp.Net中操作PDF – iTextSharp - 使用链接和书签
原文 [译]在Asp.Net中操作PDF – iTextSharp - 使用链接和书签 用户和PDF文档的交互可以通过锚(链接)和书签进行,接着我前面iTextSharp的系列文章,本篇文章主要讲通过 ...
随机推荐
- luogu 1437 敲砖块(DP)
这道题的DP的状态设计的很有想法啊. 假如我们一行一行来选择的话,状态将会极其复杂. 如果一列一列来看的话,比如你想选aij,那么第i列的前j个都要选,并且第i+1列的前j-1个都要选. 于是状态就很 ...
- jmeter3.2生成图形html遇到的问题Error in NonGUIDriver java.lang.IllegalArgumentException: Results file:log is not empty
遇到Creating summariser <summary> Error in NonGUIDriver java.lang.IllegalArgumentException: Resu ...
- MSSQL数据库分页存储过程
create procedure [dbo].[p_splitpage] ), , , output, output as set nocount on declare @p1 int ,,@rowc ...
- 🔺Count on a tree SPOJ - COT (无能为力。。。)
https://cn.vjudge.net/problem/SPOJ-COT 插上 大佬的代码 和 我的...以后再看吧... Count on a tree 大佬:http://www.cnblog ...
- 【BZOJ1391】Order(网络流,最小割)
[BZOJ1391]Order(网络流,最小割) 题面 BZOJ权限题... 良心洛谷 题目描述 有N个工作,M种机器,每种机器你可以租或者买过来. 每个工作包括若干道工序,每道工序需要某种机器来完成 ...
- 解题:HNOI 2012 永无乡
题面 并查集维护连通性,然后暴力启发式合并就完了,记得合并时边DFS边清空数组 #include<cstdio> #include<cstring> #include<a ...
- Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3) A B C D 水 模拟 二分 贪心
A. Is it rated? time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- centos 前端环境搭建
Node.js 安装 wget 下载安装 yum -y install gcc make gcc-c++ openssl-devel wget node v6.11.0 下载 wget https:/ ...
- 「Linux」centos7安装mysql
1.yum仓库下载MySQL:sudo yum localinstall https://repo.mysql.com//mysql80-community-release-el7-1.noarch. ...
- 【Docker】docker 入门以及一些常用指令
概述 Docker是一款针对程序开发人员和系统管理员来开发.部署.运行应用的一款虚拟化平台.Docker 可以让你像使用集装箱一样快速的组合成应用,并且可以像运输标准集装箱一样,尽可能的屏蔽代码层面的 ...