C#——使用iTextSharp生成pdf文件
2009-01-07 15:23
597 查看
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
using System.Windows.Forms;
using iTextSharp.text;
using iTextSharp.text.pdf;
List<String> pages = new List<String>();//存放所有页码
iTextSharp.text.Image image;
//设置文档大小及边距
Document document = new Document(iTextSharp.text.PageSize.A4, 25, 25, 25, 25);
//生成pdf
PdfWriter.GetInstance(document, new FileStream(desPath + name + ".pdf", FileMode.Create));
document.Open();
foreach (string p in pages)//逐个插入图片
{
//获取图片文件名
fileTif = Directory.GetFiles(desPath, p + ".tif", SearchOption.AllDirectories);
if (fileTif.Length == 0)
{
WriteFile(textBox2.Text + "//err.txt", fileZIP[0] + "中" + p + ".tif" + "未找到!!"
+ desPath + filename + (ii + 1).ToString() + ".pdf中缺少该页");
continue;
}
image = iTextSharp.text.Image.GetInstance(fileTif[0]);
//调整图片大小,使之适合A4
if (image.Height > iTextSharp.text.PageSize.A4.Height - 25)
image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
else if (image.Width > iTextSharp.text.PageSize.A4.Width - 25)
image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
//调整图片位置,使之居中
image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
document.NewPage();
document.Add(image);
}
document.Close();
相关文章推荐
- C#使用itextsharp生成PDF文件
- 使用ITextSharp生成PDF文件心得
- C#使用itextsharp生成PDF文件
- C#使用itextsharp生成PDF文件
- C#使用itextsharp生成PDF文件的实现代码
- C#——使用iTextSharp生成pdf文件
- 使用ITextSharp生成PDF文件心得
- 使用Apache XML项目FOP生成PDF文件(上)
- fpdf 在php中生成pdf文件时如何使用自定义字库.
- SpringMVC使用PDF模板生成PDF文件
- laravel 使用snappy生成pdf文件或生成图片
- itext使用html标签生成pdf文件
- 使用Aspose.word生成.pdf和.doc(word)报告文件
- 生成PDF文件-使用iText制作复杂表格
- 使用Apache XML项目FOP生成PDF文件(下)
- 使用的开放源码Scryber库动态生成PDF文件
- Java 使用iText7生成带页码的PDF文件(同时生成目录,但是不会合并两个PDF)
- 使用itext组件生成PDF文件
- 使用freemaker和itext从html模板生成pdf文件
- asp.net使用itextsharp.dll类库导出pdf文件