<< Click to Display Table of Contents >> Memory Streams |
[Professional Edition and above; .NET, Java, PHP, etc.]
This chapter explains special memory streams of VPE, which allow to read and write documents and images from / to memory. This is especially useful, if you want to store VPE documents or images in databases as BLOBs, or if you wish to create for example PDF documents on a web server in memory - without writing them to disk - in order to send them directly via HTTP to clients.
A memory stream is like a file, which is held in memory only.
This chapter describes the methods and functions for the VPE .NET component, where the stream class has been derived from System.IO.Stream and is therefore compatible to the stream classes of .NET.
Important:
After any write or read operation to a memory stream, the position of the internal memory stream pointer is, where the last read or write operation did stop. E.g. after calling WriteDocStream(), a ReadDocStream() on the written stream will fail. You must call Seek(0) first, to position the internal memory stream pointer at the beginning of the memory stream, before executing ReadDocStream().
The same is true, if you wish to read data from a memory stream using TVPEStream.Read() – where the memory stream has been filled before by WriteDocStream().
Call Seek(0) first!
This applies to all read and write operations.
Example:
Vpe.OpenDoc()
// Write the current document to a memory stream
TVPEStream Stream = Vpe.CreateMemoryStream(0)
Vpe.WriteDocStream(Stream)
// Create a second document
Vpe2.OpenDoc()
// Read the memory stream into the new document,
// seek to position 0 first!
Stream.Seek(0);
Vpe.ReadDocStream(Stream);
// Cleanup
Stream.Close();