Error using IStream and PXCV_ReadDocumentFromIStream
Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan
Error using IStream and PXCV_ReadDocumentFromIStream
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.
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.
- 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
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
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
Re: Error using IStream and PXCV_ReadDocumentFromIStream
Yes, it is.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
Well, I rewrited only the Load method of TPDFXView into PdfScrollBox as follow: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.
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;
- 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
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
I'll ask the guys to take a look, and we will post in the topic when we have any news.
Best,
Stefan
-
- User
- Posts: 664
- Joined: Tue Nov 14, 2006 12:23 pm
Re: Error using IStream and PXCV_ReadDocumentFromIStream
Hello Stemonte,
In my tests - all works fine. Could you send us a PDF file where you have such problems?
thanks
In my tests - all works fine. Could you send us a PDF file where you have such problems?
thanks
Re: Error using IStream and PXCV_ReadDocumentFromIStream
I just sent you a private message with the pdf file.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?
Best regards.
- 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
Hello Stemonte,
I've asked Sasha to follow up on this case shortly, so he will update this topic soon.
Best,
Stefan
I've asked Sasha to follow up on this case shortly, so he will update this topic soon.
Best,
Stefan
-
- User
- Posts: 664
- Joined: Tue Nov 14, 2006 12:23 pm
Re: Error using IStream and PXCV_ReadDocumentFromIStream
Hi,Stemonte wrote: I just sent you a private message with the pdf file.
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.
Re: Error using IStream and PXCV_ReadDocumentFromIStream
...also if do you scroll my pdf document from page 3 to 4?Corwin - Tracker Sup wrote: And it still works fine for me (even with this file).
-
- User
- Posts: 664
- Joined: Tue Nov 14, 2006 12:23 pm
Re: Error using IStream and PXCV_ReadDocumentFromIStream
Yes, I have scrolled over all document.Stemonte wrote: ...also if do you scroll my pdf document from page 3 to 4?
So your program crashed only after scrolling from page 3 to 4?
Re: Error using IStream and PXCV_ReadDocumentFromIStream
Excuse me, may i know how many pages are contained into my files and how many are showed by the PdfScrollbox demoCorwin - Tracker Sup wrote: Yes, I have scrolled over all document.
Yes. Infact the file contains 14 pages, but the demo software shows 13: where is my page 4?So your program crashed only after scrolling from page 3 to 4?
Best regards.
-
- User
- Posts: 664
- Joined: Tue Nov 14, 2006 12:23 pm
Re: Error using IStream and PXCV_ReadDocumentFromIStream
Hello Stemonte,
It looks like some problem in Delphi code. Try to remove this line:
HTH.
It looks like some problem in Delphi code. Try to remove this line:
Code: Select all
TmpIStream.Write(@dw, sizeof(DWORD), @dwWritten);
Re: Error using IStream and PXCV_ReadDocumentFromIStream
Yeeeah! It works fine now!
Thanks.
May i know the cause?Corwin - Tracker Sup wrote:It looks like some problem in Delphi code. Try to [...]
HTH.
Thanks.
-
- User
- Posts: 664
- Joined: Tue Nov 14, 2006 12:23 pm
Re: Error using IStream and PXCV_ReadDocumentFromIStream
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.