Open document using IStream from C# Source storage is wrong

PDF-XChange Viewer SDK for Developer's
(ActiveX and Simple DLL Versions)

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

chrisbunn
User
Posts: 8
Joined: Thu Feb 03, 2011 2:22 pm

Open document using IStream from C# Source storage is wrong

Post by chrisbunn »

I am currently evaluating the SDK. Our application is written in the OpenEdge ABL (Progress 4GL). Our application stores PDF documents in a database table. I would like to utilize the ability of the SDK to open documents from a stream, saving the overhead of writing the PDF document to a temporary disk file. The OpenEdge ABL interfaces to the SDK using a COM interface. This works well for most methods but I am not able to pass an ISTREAM type to to OpenDocument method. After reviewing the SDK examples related to stream I/O I thought I could resolve the issue by implementing an "ActiveX wrapper" around the SDK and implementing the ISTREAM functionality by generating event callbacks to my OpenEdge ABL environment in the ISTREAM implemention to fetch the required blocks of data from my application database. I started by creating the wrapper and making sure I could open the document using an ISTREAM the same way the examples illustrate. I then added added a call to the IStream.Read method that should generate a simple callback event to my OpenEdge ABL environment, the callback event would do nothing more than post a message saying it got there, the data for the open was still coming from the standard ISTREAM. The moment I did this my application generated the following message from the PDF-XChange Viewer Control "Error opening document 'Document from Stream': Error[Application]:Source storage is wrong". Can anyone identify the trigger for the message "Source storage is wrong"? Is my assumption about the use of the ISTREAM type incorrect?

Thanks,
Chris
Corwin - Tracker Sup
User
Posts: 664
Joined: Tue Nov 14, 2006 12:23 pm

Re: Open document using IStream from C# Source storage is wrong

Post by Corwin - Tracker Sup »

Hi Chris,

One of possible reason is that OpenEdge IStream is different from standard stream objects provided by Microsoft COM specifications. As you can see - all our samples works fine with open/save to IStream.
chrisbunn
User
Posts: 8
Joined: Thu Feb 03, 2011 2:22 pm

Re: Open document using IStream from C# Source storage is wrong

Post by chrisbunn »

The OpenEdge ABL (4GL) does not provide and Istream interface. I am using the standard IStream interface as shown in the C# examples. I am modifying the IstreamWrapper class to make calls to my own logic written in OpenEdge ABL. I am defining events in the COM interface that allow me to pass the requested data stream to the SDK.

Example,

Code: Select all

 void IStream.Read(byte[] pv, int cb, System.IntPtr pcbRead)
 {
    Marshal.WriteInt64(pcbRead, m_stream.Read(pv, 0, cb));
    // The above line will be replaced by the following call
    MY_IStreamRead(pv, cb, pcbRead);
 }
The call to MY_StreamRead will return the requested number of bytes from my application database. At the moment I am only testing to see that the parameters are passing properly, the data is still coming from the m_stream object. The error "Source storage is wrong" is only occurring when I call a method that raises a COM event that is trapped by the OpenEdge ABL. I am certain the problem is not caused by your SDK product. I am just looking for any information or experience in working with the Open Document via iStream that might indicate what I am doing wrong.

Thanks,
Chris
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3586
Joined: Thu Jul 08, 2004 10:36 pm

Re: Open document using IStream from C# Source storage is wrong

Post by Ivan - Tracker Software »

Does your IStream implement IStream::Stat ?
PDF-XChange Co Ltd. (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
chrisbunn
User
Posts: 8
Joined: Thu Feb 03, 2011 2:22 pm

Re: Open document using IStream from C# Source storage is wrong

Post by chrisbunn »

At the moment my IStream wrapper looks just like the C# example provided with the SDK, with the exception of the call to the COM event after the "Marshal.WriteInt64(pcbRead, m_stream.Read(pv, 0, cb));" statement. I was hoping to generate the PDF data stream by making repeated calls to my OpenEdge ABL(4GL) event procedures and returning the data to the IStreamWrapper. I suspect that I am doing something wrong in how I am using the COM events.

I think the repeated calls using the COM event technique is going to be problematic. I think I will load the entire document to memory and pass a pointer to the SDK and modify the IStream to read the data from the memory pointer. I think I have seen forum discussion similar to this.

Once concern I have with this approach is with memory allocation. When a document is loaded into the viewer using a stream does it read the entire document at once or does it read the document catalog and seek thru the document as needed to render the current page? Is it possible my application process size will be consuming twice the document size to view the document. Some of our customers work with documents approaching 100MB in size.

Thanks,
-Chris
Corwin - Tracker Sup
User
Posts: 664
Joined: Tue Nov 14, 2006 12:23 pm

Re: Open document using IStream from C# Source storage is wrong

Post by Corwin - Tracker Sup »

Hi Chris,

To view PDF, Viewer should have full document, however IStream.Read function may take as much time for loading bytes as it needs.