<< Click to Display Table of Contents >> Memory Streams (ActiveX / VCL) |
![]() ![]() ![]() |
[Professional Edition and above]
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 ActiveX / VCL. For the other VPE controls (.NET, Java, PHP, etc.) a special TVPEStream class (see Memory Streams on page 14) has been implemented, which is derived from System.IO.Stream and is therefore compatible to the stream classes of .NET.
Background:
For export, the basic idea is to write a VPE (or PDF, HTML, etc.) document to a memory stream first, using WriteDocStream(stream). In order to be able to access the data of the memory stream (for sending it to a client's browser or to store it as BLOB in a database), you need to use TVPEStream.Read() afterwards. This will copy the data from the stream to a buffer of your application.
Note that you can also export pages as images like TIF, JPG, etc. to memory streams using equivalently the methods PictureExportStream() and PictureExportPageStream().
Vice versa for import, the basic idea is to write a VPE document as BLOB from a database (or from anywhere else, e.g. a network stream) to a memory stream first, using TVPEStream.Write(). This will copy the data from a buffer of your application to the stream. In order to import the document from the stream into VPE, you need to use ReadDocStream(stream) afterwards.
Note that you can also read (import) images from memory streams using equivalently the methods PictureStream() or RenderPictureStream(). And you can also read (import) RTF (Rich Text) from memory streams using WriteRTFStream(), WriteBoxRTFStream(), RenderRTFStream() and RenderBoxRTFStream(). Please don’t be confused that the RTF-methods begin with the word "write", this will not write to the stream, but create the RTF objects from the given stream. The names have been chosen accordingly to the RTF-methods which create RTF objects from strings.
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, i.e. PictureStream(), etc.
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();