tags:

views:

60

answers:

2

i have various pdf files say file1.pdf, file2.pdf.......... Now I want to create a new pdf document say MainDoc.pdf. And this MainDoc.pdf will contain File1.pdf,File2.pdf... as attachments.

Tried this code but it is giving error : "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);

It Looks like issue is with writer.

Object reference not set to an instance of an object. at iTextSharp.text.pdf.PdfWriter.get_PdfIndirectReference()

A: 

I'm assuming the error occurrs on that last line? Check pfs - was it allocated?

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!
}
Jon Cage
hi jon, I am writing this code. And Error is coming on "pfs = its.pdf.PdfFileSpecification.FileEmbedded" line. Error is :Object Ref not set to instance of object Please suggest writer = its.pdf.PdfWriter.GetInstance(PDFD, new FileStream(targetpath, FileMode.Create)); its.pdf.PdfFileSpecification pfs; pfs = its.pdf.PdfFileSpecification.FileEmbedded(writer, "D:\\Test.xml", "Driving.pdf",null); if (pfs!=null) { writer.AddFileAttachment(pfs); } else { Response.Write("Err"); }
Richa
It Looks like issue is with writer.Object reference not set to an instance of an object. at iTextSharp.text.pdf.PdfWriter.get_PdfIndirectReference()
Richa
+1  A: 

Have you checked that 'writer' and 'PdfFileSpecification' isn't null?

Andre
Hi Andre Writer is not null I have checked.AND its.pdf.PdfFileSpecification is a class and "FileEmbedded" is a STATIC function. So it can be called by Instance of PdfFileSpecification class. For Ex.:its.pdf.PdfFileSpecification.FileEmbedded
Richa