Memory Streams

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

Memory Streams

Previous pageReturn to chapter overviewNext page

[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.

 

Background:

For export, the basic idea is to write a VPE (or PDF, HTML, etc.) document to a memory stream first, using VpeWriteDocStream(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 VpeStreamRead() 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 VpePictureExportStream() and VpePictureExportPageStream().
 
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 VpeStreamWrite(). 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 VpeReadDocStream(stream) afterwards.
 
Note that you can also read (import) images from memory streams using equivalently the methods VpePictureStream() or VpeRenderPictureStream(). And you can also read (import) RTF (Rich Text) from memory streams using VpeWriteRTFStream(),VpeWriteBoxRTFStream(),VpeRenderRTFStream()  and VpeRenderBoxRTFStream(). 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 VpeWriteDocStream(), a VpeReadDocStream() on the written stream will fail. You must call VpeStreamSeek(hStream, 0) first, to position the internal memory stream pointer at the beginning of the memory stream, before executing VpeReadDocStream().

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 VpeWriteDocStream().
Call VpeStreamSeek(hStream, 0) first!

This applies to all read and write operations, i.e. PictureStream(), etc.

 

Example:

VpeHandle hDoc = VpeOpenDoc(hwnd, "Sample Application", VPE_GRIDBUTTON);

 

// Write the current document to a memory stream

VpeHandle hStream = VpeCreateMemoryStream(hDoc, 0);

VpeWriteDocStream(hDoc, hStream);

 

// Create a second document

VpeHandle hDoc2 = VpeOpenDoc(hwnd, "Sample Application", VPE_GRIDBUTTON);

 

// Read the memory stream into the new document,

// seek to position 0 first!

VpeStreamSeek(hStream, 0);

VpeReadDocStream(hDoc2, hStream);

 

// Cleanup

VpeCloseStream(hStream);

_unlink("test.vpe");

VpeWriteDoc(hDoc2, "test.vpe");

VpeCloseDoc(hDoc2);

VpeCloseDoc(hDoc);

 

 

See Also:

VpeWriteDocStream

VpeWriteDocStreamPageRange

 

VpeReadDocStream

VpeReadDocStreamPageRange

 

VpePictureStream

VpeRenderPictureStream

VpePictureExportPageStream

VpePictureExportStream

 

VpeWriteRTFStream

VpeWriteBoxRTFStream

VpeRenderRTFStream

VpeRenderBoxRTFStream