Direct to file mode fails on pdf.close()

I am opening a filestream to a pdf file using FileMode.Create and FileAccess.ReadWrite
Everything goes smooth until I call the Close() method.
It works fine when using memmory but when I try to use a a FileStream it crashes:

My code is something like this:

dim fin as new FileInfo(“test.pdf”)
dim f as IO.FileStream= fin.Open(FileMode.Create, FileAccess.ReadWrite)
dim _pdf as new Pdf(f)

Here I write some sections that worked when using memmory

_pdf.close()

Then I get a nullref error like this:

Message: “Object reference not set to an instance of an object.”
Source: “Aspose.Pdf”
StackTrace: " at Aspose.Pdf.Xml.aw.a(Pdf A_0, c A_1)
at Aspose.Pdf.Pdf.Close()

Also there are never more that 15 bytes of data written to the stream, which in fact should be larger.

Hope you can help me on this.

With regards
Morten

Dear Morten,

Thank you for considering Aspose.

I have tested using the following code and have not found any error:

Dim fin As New FileInfo("e:/temp/test.pdf")
Dim f As IO.FileStream = fin.Open(FileMode.Create, FileAccess.ReadWrite)
Dim _pdf As New Pdf(f)

Dim sec As Section = _pdf.Sections.Add()

Dim t As Aspose.Pdf.Text = New Aspose.Pdf.Text("hello world")
sec.AddParagraph(t)


_pdf.Close()

When using images of the type MemmoryBMP it seems the behaviour of direct to file mode differs somewhat from memmory mode.

In Direct to file mode I have to read in all of the memmory data of the image before calling the AddParagraph.
In Memmory mode I call AddParagraph first and secondly read in the Memmorydata.

Anyway, the problem I had was solved by calling AddParagraph at the end of the code.

With regards
Morten