TallPDF.NET是一款功能强大的.NET类库,可以在.NET应用程序中生成PDF文档,支持直接从代码或者XML文件生成PDF文档,支持为PDF文档创建书签、为PDF文档生成内部和外部链接、创建表格、嵌入各种图片、创建表单字段、嵌入字体、文本格式化、支持导入XHTML,可以为PDF文档嵌入存在PDF页,嵌入简单或者复杂的图形等很多PDF文件常用的功能,这篇文章主要介绍怎么利用
TallPDF.NET这款控件来把多页TIFF文件转换为PDF文件,具体可以参考下面的代码:
// count the number of TIFF frames/pages
string path = "in.tif";
ImageShape image = new ImageShape(path);
int count = image.FrameCount;
Document document = new Document();
// for each frame add a section
for (int index = 0; index < count; index++)
{
// create a section and add it to the document.
Section section = document.Sections.Add();
section.StartOnNewPage = true;
// set margins to zero; the image will span the entire page
section.Margin.Left = 0;
section.Margin.Right = 0;
section.Margin.Top = 0;
section.Margin.Bottom = 0;
// load the frame into an Image paragraph
Image frame = new Image(path, index);
// set PageSize from the Image dimensions
section.PageSize.Width = frame.Width;
section.PageSize.Height = frame.Height;
// add the image to the section
section.Paragraphs.Add( frame );
}
// save the PDF to a file
using (FileStream file = new FileStream(
"out.pdf", FileMode.Create, FileAccess.Write))
{
document.Write(file);
}