We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Direct-to-file method error

Dear All,

When I am trying to add a PDF table to a section with the direct-to-file method, it gives me an error as follows.

This error occurs at Close method.

System.NullReferenceException: Object reference not set to an instance of an object.
at x3f91538e8c0de749.x276fb33596224483.x41c54da67f427bb8(Pdf x6beba47238e0ade6, xa65184d44a47025b xbbe2f7d7c86e0379)
at Aspose.Pdf.Pdf.Close()
at ProductionMonitoringForm.cfGenerateCoverTable() in f:\PrinterVersion\App_Code\ProductionMonitoringForm.cs:line 239

Aspose.Pdf.Table tblPMMain = new Aspose.Pdf.Table();
tblPMMain = cpGeneratePMTable();
section.Paragraphs.Add(tblPMMain);


Without above three lines it works fine.

Thanx in advance.

Regards,
Sugath

Hello Sugath,

Thanks for using our products.

Can you please share the complete code snippet, so that we can test the scenario at our end. We apologize for your inconvenience.

FileInfo fiPDF = new FileInfo(“Test.pdf”);
FileStream fsPDF = fiPDF.Open(FileMode.Create, FileAccess.ReadWrite);

Pdf pdf1 = new Pdf(fsPDF);

Section section = pdf1.Sections.Add();
section.IsNewPage = true;

#region "Form Content Table"
Aspose.Pdf.Table tblPMMain = new Aspose.Pdf.Table();
tblPMMain = cpGeneratePMTable();
section.Paragraphs.Add(tblPMMain);
#endregion

pdf1.Close();

cpGeneratePMTable() is returning a PDF table.

Is this good enough to understand my problem?

Regards,
Sugath

Finally I found the solution.

Instead of section.Paragraphs.Add(tblPMMain); I have to use section.AddParagraph(tblPMMain);


Hello Sugath,

Yes you are correct. When using Direct-to-File mode, you need to use AddParagraph(..) to add any particular paragraph to the paragraphs collection of Section object. For more related information, please visit Writing PDF directly

In case you have any further query, please feel free to contact. We apologize for your inconvenience.