Delphi example about ReadDocumentFromIStream

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

Stemon63
User
Posts: 6
Joined: Mon Apr 28, 2008 5:09 pm

Delphi example about ReadDocumentFromIStream

Post by Stemon63 »

Hi,

Where can I found a piece of Delphi code about the use of PXCV_ReadDocumentFromIStream?

Best regards.
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19913
Joined: Mon Jan 12, 2009 8:07 am

Re: Delphi example about ReadDocumentFromIStream

Post by Stefan - PDF-XChange »

Hello Stemon,

If you have installed the Viewer SDK in the default folder you should find the example in e.g.
C:\Program Files\Tracker Software\PDF-XChange Viewer SDK\Examples\DelphiExamples\OpenDocumentFromStream

Best,
Stefan
Stemon63
User
Posts: 6
Joined: Mon Apr 28, 2008 5:09 pm

Re: Delphi example about ReadDocumentFromIStream

Post by Stemon63 »

Tracker Supp-Stefan wrote:If you have installed the Viewer SDK in the default folder you should find the example in e.g.
C:\Program Files\Tracker Software\PDF-XChange Viewer SDK\Examples\DelphiExamples\OpenDocumentFromStream
Yes, but in the example doesn't uses PXCV_ReadDocumentFromIStream function exported from pxcview.dll...
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19913
Joined: Mon Jan 12, 2009 8:07 am

Re: Delphi example about ReadDocumentFromIStream

Post by Stefan - PDF-XChange »

Hello Stemon63,

Apologies - the samples I pointed you to are for the Viewer AX, and you are asking for the Simple DLL SDK one.

I am sorry, we do not have such a sample, but it is a straight forward function, and the parameters it requires are also pretty obvious, so please ensure that you have created a PDF file to pass as the PXVDocument paramter via PCV_Init, and that you have a correct IStream to pass as the second parameter. Flags are optional.

Best,
Stefan
Stemon63
User
Posts: 6
Joined: Mon Apr 28, 2008 5:09 pm

Re: Delphi example about ReadDocumentFromIStream

Post by Stemon63 »

Tracker Supp-Stefan wrote:I am sorry, we do not have such a sample, but it is a straight forward function, and the parameters it requires are also pretty obvious, so please ensure that you have created a PDF file to pass as the PXVDocument paramter via PCV_Init, and that you have a correct IStream to pass as the second parameter. Flags are optional.
It's ok.

I modified PDFXView.LoadFile() method in this way:

var
PDFResult: HResult;
TmpFileStream: TFileStream;
TmpIStream: IStream;
tPos: int64;

[...]
//PDFResult := PXCV_ReadDocumentW(pDocument, PWChar(WideString(PDFFilename)), 0);
// -- Start read from stream
TmpFileStream := TFileStream.Create(PDFFilename,fmOpenReadWrite or fmShareDenyNone);

TmpIStream := TStreamAdapter.Create(TmpFileStream, soOwned);
TmpIStream.Seek(0, 0, tPos);
// -- End read from stream

PDFResult := PXCV_ReadDocumentFromIStream(pDocument, TmpIStream, 0)
[...]

but it doesn't works and in PDFResult I have a negative value. :-(


P.S.
Since the PXView_36.pas file was missing the function PXCV_ReadDocumentFromIStream, I added in its statement:
function PXCV_ReadDocumentFromIStream(pDoc :PXVDocument; Stream: IStream; Flags: DWORD):HRESULT;stdcall;external 'pxcview.dll';
Corwin - Tracker Sup
User
Posts: 664
Joined: Tue Nov 14, 2006 12:23 pm

Re: Delphi example about ReadDocumentFromIStream

Post by Corwin - Tracker Sup »

Hello Stemon63,

Problem with TStreamAdapter is that TStreamAdapter doesn't provide a correct implementation of IStream.Clone method. As example you may use create IStream by using CreateStreamOnHGlobal function.
Here is example code:

Code: Select all

var
  fs: TFileStream;
  IStr:iStream;
  dwWritten : DWORD;
  dw : DWORD;
  dt : pointer;
  Res: HResult;
....

Res := PXCV_Init(@m_pDocument,...);
....
try
	fs := TFileStream.Create(PDFFilename, fmOpenRead);
	dw := fs.Size;
	GetMem(dt, dw);
	fs.Read(dt^, fs.Size);
	CreateStreamOnHGlobal(0, False, IStr);
	if IStr <> nil then
	begin
		IStr.Write(@dw, sizeof(DWORD), @dwWritten);
		IStr.Write(dt, dw, @dwWritten);
		Res := PXCV_ReadDocumentFromIStream(m_pDocument, IStr, 0);
	end;

finally
	fs.Free();
	FreeMem(dt, dw);
end;
HTH.
Stemon63
User
Posts: 6
Joined: Mon Apr 28, 2008 5:09 pm

Re: Delphi example about ReadDocumentFromIStream

Post by Stemon63 »

Corwin - Tracker Sup wrote:Hello Stemon63,
[...]
As example you may use create IStream by using CreateStreamOnHGlobal function.
[...]
Works!
thanks! :D
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19913
Joined: Mon Jan 12, 2009 8:07 am

Re: Delphi example about ReadDocumentFromIStream

Post by Stefan - PDF-XChange »

Glad to hear that Stemon!

(And kudos to Corwin :D )

Regards,
Stefan