.net快速创建PDF文档 by c#
2015-08-13 15:47
489 查看
原文地址:/article/5067330.html
C#引用IText创建PDF文档
先引用IText 可以从这里进行下载组件
下面演示五步创建PDF
第一步:创建文件对象的实例
Document myDocument= new Document(PageSize.A4.Rotate());
第二步:创建一个Writer监听文件并且向文件写入想要的流
PdfWriter.GetInstance(myDocument, new FileStream("Salman.pdf",FileMode.Create));
第三步:打开文件
myDocument.Open();
第四步:向文件写入一些内容
myDocument.add( new Paragraph ( "First Pdf File made by Salman using iText"));
第五步:最后记得关闭文件
myDocument.close();
using System;
using System.IO;
using System.Diagnostics;
using iTextSharp.text;
using iTextSharp.text.pdf;
publicclass iTextDemo
{
publicstaticvoid Main()
{
Console.WriteLine("iText Demo");
// step 1: creation of a document-object
Document myDocument =new Document(PageSize.A4.Rotate());
try
{
// step 2:
// Now create a writer that listens to this doucment and writes the document to desired Stream.
PdfWriter.GetInstance(myDocument, new FileStream("Salman.pdf", FileMode.Create));
// step 3: Open the document now using
myDocument.Open();
// step 4: Now add some contents to the document
myDocument.Add(new Paragraph("First Pdf File made by Salman using iText"));
}
catch(DocumentException de)
{
Console.Error.WriteLine(de.Message);
}
catch(IOException ioe)
{
Console.Error.WriteLine(ioe.Message);
}
// step 5: Remember to close the documnet
myDocument.Close();
}
}
欲查看英语原文请点击此处
C#引用IText创建PDF文档
先引用IText 可以从这里进行下载组件
下面演示五步创建PDF
第一步:创建文件对象的实例
Document myDocument= new Document(PageSize.A4.Rotate());
第二步:创建一个Writer监听文件并且向文件写入想要的流
PdfWriter.GetInstance(myDocument, new FileStream("Salman.pdf",FileMode.Create));
第三步:打开文件
myDocument.Open();
第四步:向文件写入一些内容
myDocument.add( new Paragraph ( "First Pdf File made by Salman using iText"));
第五步:最后记得关闭文件
myDocument.close();
using System;
using System.IO;
using System.Diagnostics;
using iTextSharp.text;
using iTextSharp.text.pdf;
publicclass iTextDemo
{
publicstaticvoid Main()
{
Console.WriteLine("iText Demo");
// step 1: creation of a document-object
Document myDocument =new Document(PageSize.A4.Rotate());
try
{
// step 2:
// Now create a writer that listens to this doucment and writes the document to desired Stream.
PdfWriter.GetInstance(myDocument, new FileStream("Salman.pdf", FileMode.Create));
// step 3: Open the document now using
myDocument.Open();
// step 4: Now add some contents to the document
myDocument.Add(new Paragraph("First Pdf File made by Salman using iText"));
}
catch(DocumentException de)
{
Console.Error.WriteLine(de.Message);
}
catch(IOException ioe)
{
Console.Error.WriteLine(ioe.Message);
}
// step 5: Remember to close the documnet
myDocument.Close();
}
}
欲查看英语原文请点击此处
相关文章推荐
- Luhn算法 C#实现 信用卡校验
- [转]正则表达式相关:C# 抓取网页类(获取网页中所有信息)
- C# GET 和 SET作用
- C# 代码片段
- Visual C#2010学习笔记六之运算符的重载
- C#实现求一组数据众数的方法
- C#自动添加using引用命名空间
- C# winform 实现图片轮播
- C#错误---线程间操作无效: 从不是创建控件"Form1"的线程访问它.
- c#软件实现语言版本切换
- C#读取csv文件内容到DataTable
- C#实现将浮点数表示的货币数量以汉字大写形式输出的方法
- C#双向链表LinkedList排序实现方法
- XmlDocument在C#中的应用
- c#日期和随机数--》的士发票
- C#实现计算一个点围绕另一个点旋转指定弧度后坐标值的方法
- c# winform richtextbox 滚动条 最后位置
- c# winform 模拟web post图片
- C# 对象数据转换
- C# 读取共享目录文件