pdf文件包(portfolio)允许用户将多种不同类型的文件如word、excel、pdf、powerpoint和图片等集合到一个pdf文件中,用户可以打开、更改pdf文件包中的单个文件,而不影响其他文件。本文将介绍如何使用spire.pdf for .net创建pdf文件包。
在创建pdf文件包时,spire.pdf for .net支持给包添加文件和文件夹。以下示例展示了如何使用spire.pdf for .net创建pdf文件包并添加文件。
c#
using system;
using spire.pdf;
namespace createpdfportfolio
{
class program
{
static void main(string[] args)
{
string[] files = new string[] { "instruction.pdf", "sales report.docx", "sample.xlsx" };
//创建pdfdocument实例
using (pdfdocument doc = new pdfdocument())
{
//创建pdf文件包并添加文件
for (int i = 0; i < files.length; i )
{
doc.collection.addfile(files[i]);
}
//保存结果文档
doc.savetofile("portfoliowithfiles.pdf", fileformat.pdf);
doc.dispose();
}
}
}
}
vb.net
imports system
imports spire.pdf
namespace createpdfportfolio
class program
private shared sub main(byval args as string())
dim files as string() = new string() {"instruction.pdf", "sales report.docx", "sample.xlsx"}
using doc as pdfdocument = new pdfdocument()
for i as integer = 0 to files.length - 1
doc.collection.addfile(files(i))
next
doc.savetofile("portfoliowithfiles.pdf", fileformat.pdf)
doc.dispose()
end using
end sub
end class
end namespace
以下示例展示了如何使用spire.pdf for .net创建pdf文件包并添加文件夹。
c#
using system;
using spire.pdf;
using spire.pdf.collections;
namespace createpdfportfolio
{
class program
{
static void main(string[] args)
{
string[] files = new string[] { "instruction.pdf", "sales report.docx", "sample.xlsx" };
//创建pdfdocument实例
using (pdfdocument doc = new pdfdocument())
{
//创建pdf文件包,添加文件夹并向文件夹添加文件
for (int i = 0; i < files.length; i )
{
pdffolder folder = doc.collection.folders.createsubfolder("folder" i);
folder.addfile(files[i]);
}
//保存结果文档
doc.savetofile("portfoliowithfolders.pdf", fileformat.pdf);
doc.dispose();
}
}
}
}
vb.net
imports system
imports spire.pdf
imports spire.pdf.collections
namespace createpdfportfolio
class program
private shared sub main(byval args as string())
dim files as string() = new string() {"instruction.pdf", "sales report.docx", "sample.xlsx"}
using doc as pdfdocument = new pdfdocument()
for i as integer = 0 to files.length - 1
dim folder as pdffolder = doc.collection.folders.createsubfolder("folder" & i)
folder.addfile(files(i))
next
doc.savetofile("portfoliowithfolders.pdf", fileformat.pdf)
doc.dispose()
end using
end sub
end class
end namespace