C# 生成PDF
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Collections;
//
using iTextSharp;//下载这个DLL即可
using iTextSharp.text;
using iTextSharp.text.pdf;
namespace PDFGenerator
{
class Program
{
static void Main(string[] args)
{
Document document = new Document();
PdfWriter.GetInstance(document, new FileStream("e://test1.pdf", FileMode.Create));
//生成的PDF文件名为test1.pdf
document.Open();
BaseFont bfChinese = BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
//对齐方式:cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE;
//下划线:Chunk chunk1 = new Chunk("This text is underlined", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE));
//删除线:Chunk chunk2 = new Chunk("This font is of type ITALIC | STRIKETHRU", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.ITALIC | Font.STRIKETHRU));
Font fontChinese = new Font(bfChinese, 14, Font.UNDERLINE, Color.RED);
//Font fontChinese = new Font(bfChinese, 12, Font.NORMAL, new Color(0, 0, 0));//黑
//Font fontChinese = new Font(bfChinese, 12, Font.NORMAL,new Color(0, 255, 0)); //绿
document.Add(new Paragraph("你好,world", fontChinese));
//向PDF添加TextBox1的内容
iTextSharp.text.Image jpeg = iTextSharp.text.Image.GetInstance("01.jpg");
document.Add(jpeg);
//向PDF添加图片01.jpg
document.Close();
}
}
}