The VB example shows how to write report lines, etc, but that is not the problem...we are successful in creating reports.
It sounds as if you are looking at the wrong demo. For VB6 the demo is named MemoryStream.vbp / frm.
Even the VPE Reference Manual and VPE DLL manual do not give specific enough information, and also cite two different methods to use (the DLL manual calls the write method VPEStreamWrite, while the general Reference Manual calls the method WriteDocStream().
This is confusing and wrong. In the DLL manual the method is named VpeStreamWrite() and for the ActiveX it is TVPEStream.Write(). Both are equivalent, and both write data directly to a memory stream. This is clearly said in the manuals.
Here is the code from MemoryStream.frm:
- Code: Select all
Private Sub Command1_Click()
Dim stream As TVPEStream
Dim buffer() As Byte
Doc.OpenDoc
Doc.VpePrint 1, 1, "Hello World!"
' Create a memory stream
Set stream = Doc.CreateMemoryStream(0)
' Write the VPE document as PDF file to the memory stream
Doc.DocExportType = VPE_DOC_TYPE_PDF
Doc.WriteDocStream stream
' Export the memory stream to an external file.
' This is only for demonstration purposes, normally you would write the memory stream now
' as BLOB to a database or do something like that.
nFileNum = FreeFile
Open "test.pdf" For Binary Access Write Lock Read Write As #nFileNum
' Seek to the beginning of the memory stream
stream.Seek 0
' As long as there is data in the stream, copy it
Position = 1
ReDim buffer(4096)
While (Not stream.IsEof)
' Read data from the VPE stream into a memory buffer
bytes_read = stream.Read(buffer, 4096)
' Write the memory buffer to the external file
If bytes_read < 4096 Then ReDim Preserve buffer(bytes_read)
Put #nFileNum, Position, buffer
Position = Position + bytes_read
Wend
Close #nFileNum
stream.Close
MsgBox "PDF file 'test.pdf' created in working directory"
End Sub
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 (as described in the manuals)
Hope, this helps.