附件pdf

时间:2010-07-15 08:41:54

标签: c# pdf

我有各种pdf文件说file1.pdf,file2.pdf .......... 现在我想创建一个新的pdf文档,说MainDoc.pdf。 此MainDoc.pdf将包含File1.pdf,File2.pdf ...作为附件。

尝试了这段代码,但它给出了错误: “Object Refrence not set to an instance

its.Document PDFD = new its.Document(its.PageSize.LETTER);
its.pdf.PdfWriter writer;
writer = its.pdf.PdfWriter.GetInstance(PDFD, new FileStream(targetpath, FileMode.Create));
its.pdf.PdfFileSpecification pfs = its.pdf.PdfFileSpecification.FileEmbedded(writer, "C:\\test.xml", "New.xml", null);
writer.AddFileAttachment(pfs);

看起来问题与作家有关。

对象引用未设置为对象的实例。在iTextSharp.text.pdf.PdfWriter.get_PdfIndirectReference()

3 个答案:

答案 0 :(得分:1)

您是否检查过'writer'和'PdfFileSpecification'不为空?

答案 1 :(得分:1)

Null来自文件。

添加

PDFD.Open();

之后

its.pdf.PdfWriter writer = its.pdf.PdfWriter.GetInstance(PDFD, new FileStream(targetpath, FileMode.Create));

答案 2 :(得分:0)

我假设最后一行发生错误?检查pfs - 是否已分配?

its.Document PDFD = new its.Document(its.PageSize.LETTER);
its.pdf.PdfWriter writer = its.pdf.PdfWriter.GetInstance(PDFD, new FileStream(targetpath, FileMode.Create));
its.pdf.PdfFileSpecification pfs = its.pdf.PdfFileSpecification.FileEmbedded(writer, "C:\\test.xml", "New.xml", null);
if( pfs )
{
    writer.AddFileAttachment(pfs);
}
else
{
    // An error occurred!
}