Error using IStream and PXCV_ReadDocumentFromIStream

This Forum is for the use of Software Developers requiring help and assistance for Tracker Software's PDF-Tools SDK of Library DLL functions(only) - Please use the PDF-XChange Drivers API SDK Forum for assistance with all PDF Print Driver related topics or PDF-XChange Viewer SDK if appropriate.

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan

Post Reply
Stemonte
User
Posts: 41
Joined: Mon Nov 26, 2007 9:17 am

Error using IStream and PXCV_ReadDocumentFromIStream

Post by Stemonte »

Hi,

I created a PDF file by merging 2 files containing some pages of different format (A4 and customized).
Opening this file with _standard_ "PDF Scrollbox Viewer example" all it's ok, but if I open it using the algorithm explained into "Delphi example about ReadDocumentFromIStream" thread, my application terminates itself drastically without any message. :(

What's solution?

Best regards.
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17948
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Error using IStream and PXCV_ReadDocumentFromIStream

Post by Tracker Supp-Stefan »

Hello Stemonte,

I will now pass that to our devs, but can you please confirm that this is the topic that you mention?
https://forum.pdf-xchange.com/ ... 36&t=10558

Also if you could provide compilable sample from your end that causes the crash - that would be most helpful!
Please ensure that your license information is NOT included or we will need to deactivate your license.

Best,
Stefan
Stemonte
User
Posts: 41
Joined: Mon Nov 26, 2007 9:17 am

Re: Error using IStream and PXCV_ReadDocumentFromIStream

Post by Stemonte »

Tracker Supp-Stefan wrote: I will now pass that to our devs, but can you please confirm that this is the topic that you mention?
https://forum.pdf-xchange.com/ ... 36&t=10558
Yes, it is.

Also if you could provide compilable sample from your end that causes the crash - that would be most helpful!
Please ensure that your license information is NOT included or we will need to deactivate your license.
Well, I rewrited only the Load method of TPDFXView into PdfScrollBox as follow:

Code: Select all

function TPDFXView.LoadFile(const PDFFilename: string;
                            Password: string;
                            bReadOnly: Boolean): boolean;

var
  PDFResult: HResult;
  TmpFileStream: TFileStream;
  TmpIStream: IStream;
  //tPos: int64;
  dwWritten : DWORD;
  dw : DWORD;
  dt : pointer;
  //Res: HResult;

begin
  result := True;

  if pDocument = 0 then begin
    {If we get here, then it is likley that unlock has not been called, so we shall try and init with no
     license Info...}
    PDFResult := PXCV_Init(@pDocument, nil, nil);
    result := CheckErrorAndUpdateMessage(PDFResult);

    if not result then FLastErrorMessage := 'Could not initialise PDF for reading with no license information.';
  end;

  if result then
    Begin
    PDFResult := 0;

    if bReadOnly then
      Begin
      TmpFileStream := TFileStream.Create(PDFFilename,fmOpenReadWrite or fmShareDenyNone);
      dw := TmpFileStream.Size;
      GetMem(dt, dw);
      TmpFileStream.Read(dt^, TmpFileStream.Size);
      CreateStreamOnHGlobal(0, False, TmpIStream);
      if TmpIStream <> nil then
        begin
        TmpIStream.Write(@dw, sizeof(DWORD), @dwWritten);
        TmpIStream.Write(dt, dw, @dwWritten);

        try
        PDFResult := PXCV_ReadDocumentFromIStream(pDocument, TmpIStream, 0)
        Except
          on E: exception do
            begin
            MessageDlg('Impossibile leggere il documento ' + PDFFilename + '  [ShowDoc]' + #10 +
                       'Si è verificato il seguente errore:' + #10 + E.Message, mtError, [mbOK], 0);
            end;
        end;
        end;

      FreeMem(dt, dw);

      if Assigned(TmpFileStream) then
        FreeAndNil(TmpFileStream);
      End // ** Fine if bReadOnly then
    else
      PDFResult := PXCV_ReadDocumentW(pDocument, PWChar(WideString(PDFFilename)), 0);

    if (PDFResult = HResult(PS_ERR_DocEncrypted)) then	begin
      PDFResult := PXCV_CheckPassword(pDocument, PByte(PChar(Password)), Length(Password));
      result := CheckErrorAndUpdateMessage(PDFResult);
      if result then begin
        PDFResult := PXCV_FinishReadDocument(pDocument, 0);
      end;
    end;

    result := result and CheckErrorAndUpdateMessage(PDFResult);
    if result then begin
      PDFResult := PXCV_GetPagesCount(pDocument, @FPageCount);
      if FPageCount > 0 then
        result := CheckErrorAndUpdateMessage(PDFResult)
      else
        result := False;
    end;

    if not result then begin
      UnloadFile;
    end;
  end;
end;
Best regards.
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17948
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Error using IStream and PXCV_ReadDocumentFromIStream

Post by Tracker Supp-Stefan »

Thanks for the sample Stemonte,

I'll ask the guys to take a look, and we will post in the topic when we have any news.

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

Re: Error using IStream and PXCV_ReadDocumentFromIStream

Post by Corwin - Tracker Sup »

Hello Stemonte,

In my tests - all works fine. Could you send us a PDF file where you have such problems?

thanks
Stemonte
User
Posts: 41
Joined: Mon Nov 26, 2007 9:17 am

Re: Error using IStream and PXCV_ReadDocumentFromIStream

Post by Stemonte »

Corwin - Tracker Sup wrote:Hello Stemonte,

As I have test it - all works fine. Could you send us PDF file on which you have such problems?
I just sent you a private message with the pdf file.

Best regards.
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17948
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Error using IStream and PXCV_ReadDocumentFromIStream

Post by Tracker Supp-Stefan »

Hello Stemonte,

I've asked Sasha to follow up on this case shortly, so he will update this topic soon.

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

Re: Error using IStream and PXCV_ReadDocumentFromIStream

Post by Corwin - Tracker Sup »

Stemonte wrote: I just sent you a private message with the pdf file.
Hi,

And it still works fine for me (even with this file). Maybe you add some more changes in the source code?
Please install latest version of PDF-Tools SDK and then try to step by step debug your code, just to know on which line you have application terminating.
Stemonte
User
Posts: 41
Joined: Mon Nov 26, 2007 9:17 am

Re: Error using IStream and PXCV_ReadDocumentFromIStream

Post by Stemonte »

Corwin - Tracker Sup wrote: And it still works fine for me (even with this file).
...also if do you scroll my pdf document from page 3 to 4?
Corwin - Tracker Sup
User
Posts: 664
Joined: Tue Nov 14, 2006 12:23 pm

Re: Error using IStream and PXCV_ReadDocumentFromIStream

Post by Corwin - Tracker Sup »

Stemonte wrote: ...also if do you scroll my pdf document from page 3 to 4?
Yes, I have scrolled over all document.
So your program crashed only after scrolling from page 3 to 4?
Stemonte
User
Posts: 41
Joined: Mon Nov 26, 2007 9:17 am

Re: Error using IStream and PXCV_ReadDocumentFromIStream

Post by Stemonte »

Corwin - Tracker Sup wrote: Yes, I have scrolled over all document.
Excuse me, may i know how many pages are contained into my files and how many are showed by the PdfScrollbox demo

So your program crashed only after scrolling from page 3 to 4?
Yes. Infact the file contains 14 pages, but the demo software shows 13: where is my page 4?

Best regards.
Corwin - Tracker Sup
User
Posts: 664
Joined: Tue Nov 14, 2006 12:23 pm

Re: Error using IStream and PXCV_ReadDocumentFromIStream

Post by Corwin - Tracker Sup »

Hello Stemonte,

It looks like some problem in Delphi code. Try to remove this line:

Code: Select all

TmpIStream.Write(@dw, sizeof(DWORD), @dwWritten);
HTH.
Stemonte
User
Posts: 41
Joined: Mon Nov 26, 2007 9:17 am

Re: Error using IStream and PXCV_ReadDocumentFromIStream

Post by Stemonte »

Yeeeah! It works fine now!
Corwin - Tracker Sup wrote:It looks like some problem in Delphi code. Try to [...]
HTH.
May i know the cause?


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

Re: Error using IStream and PXCV_ReadDocumentFromIStream

Post by Corwin - Tracker Sup »

Well in that line of code to stream was written additional 4 bytes (size of stream), which may cause bad affect for pdf file structure.
Post Reply