Progress ABL and Memory Streams

Knowledge exchange related to the VPE Report Engine and PDF Library

Moderator: IDEAL Software Support

Progress ABL and Memory Streams

Postby BartG » Fri Jun 06, 2008 12:09 am

Sorry, the last response to my query regarding how to create and write to a memory stream in Progress was not helpful at all. The VB example shows how to write report lines, etc, but that is not the problem...we are successful in creating reports.

What we want to do is to create a receipt for a POS using Progress and then use a memorystream to send to .NET to be read and printed out.

We have the receipt created, and I believe we have successfully created the memorystream too, but we cannot write to it. I have tried to use the WriteDocStream method, but it is not recognized in Progress, although almost any other method is (such as CreateMemoryStream).

I really need some help here, I am spinning my wheels on this. We do not want to write the file to hard disk, it is far better for speed and efficiencie's sake that we do this all through memory.

Can you please give me some more detailed information or point me to someplace that I can find some good examples of specifically writing to a memorystream?

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().

Thanks in advance for your help.
BartG
 
Posts: 17
Joined: Tue Mar 18, 2008 5:06 pm
Location: Scottsdale,AZ

Postby IDEAL Software Support » Fri Jun 06, 2008 11:16 am

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.
IDEAL Software Support
 
Posts: 1633
Joined: Thu Nov 18, 2004 4:03 pm

Thanks! Progress ABL & memorystreams...

Postby BartG » Fri Jun 06, 2008 4:22 pm

Thanks for pointing me in the right direction...this is a lot more helpful. I appreciate you taking the time to give me some better examples and clearing up the differences between DLL and VBX!

Regards,

Bart
BartG
 
Posts: 17
Joined: Tue Mar 18, 2008 5:06 pm
Location: Scottsdale,AZ


Return to VPE Open Forum

Who is online

Users browsing this forum: No registered users and 2 guests

cron