Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDFViewer on Android crashes for large files #125

Open
GitUserMarkus opened this issue Nov 1, 2022 · 10 comments
Open

PDFViewer on Android crashes for large files #125

GitUserMarkus opened this issue Nov 1, 2022 · 10 comments
Assignees
Labels
bug Something isn't working priority low Low priority issue

Comments

@GitUserMarkus
Copy link

I am using your PDFViewer as shown in your demo application. When loading a huge file (say 1000 pages) and scrolling through the file, the app eventually crashes (typically when reaching some point beyond page 100). No exception is thrown, even the debugger gets no notice of the problem.
Any idea how to fix this issue?

@DelphiWorlds DelphiWorlds self-assigned this Nov 1, 2022
@DelphiWorlds DelphiWorlds added the bug Something isn't working label Nov 1, 2022
@DelphiWorlds
Copy link
Owner

Did you test the same PDF with the demo (i.e. instead of it using Feature Matrix.pdf)? I just tested a 914 page file, and it loads the first 500 pages (I stopped scrolling after that) without crashing. If the demo crashes, are you able to provide a PDF file to test with?

@GitUserMarkus
Copy link
Author

Thank you very much for testing. With the original demo the error does not occur so it must have to do with the modifications I made. However, since I only added the support to zoom into the pdf, which is not in action while scrolling, I currently do not understand which side effect might be responsible for the crash. Sorry for bothering.

@DelphiWorlds
Copy link
Owner

I had planned to add zooming, however I am yet to do that. I'll keep this issue open as a reminder :-)

@GitUserMarkus
Copy link
Author

Great, looking forward see how you will implement it.

@GitUserMarkus
Copy link
Author

Now I can reproduce the crash for your demo app with just one modification. I call TPDFRenderer.RenderPage with AScale = 5.0 which I originally did in order to have a high resolution bitmap for zooming in. With this single change your demo crashes as reported above.

@DelphiWorlds
Copy link
Owner

Thanks for the update! I'll look into it

@DelphiWorlds
Copy link
Owner

Still cannot get it to crash. Please show exactly what you are changing, and it may also help if I know which PDF file you are using

@GitUserMarkus
Copy link
Author

This is the change I made (the last argument of FRenderer.RenderPage is set to 5.0, overwriting the default 1.0

procedure TPDFControl.LoadPage;
var
LPage: TPDFPage;
begin
Inc(FPageIndex);
LPage := TPDFPage.Create(Self);
LPage.PageIndex := FPageIndex;
LPage.Height := FVertScrollBox.ClientHeight;
LPage.Position.Y := FVertScrollBox.ContentBounds.Height;
LPage.Align := TAlignLayout.Top;
LPage.Parent := FVertScrollBox;
{$IF Defined(ANDROID)}
LPage.Image.Bitmap.SetSize(LPage.Image.Size.Size.Round);
FRenderer.RenderPage(FPageIndex, LPage.Image.Bitmap, 5.0);
{$ENDIF}
end;

The crash happens on Android 64 phones (I am not aware if it can be observed in any simulator). I can't share the PDF I am using publically, if you provide any means for a personal communication I will send it to you.

@DelphiWorlds
Copy link
Owner

It was my bad.. I tested with scale of 0.5 instead of 5.0!

I've removed the scaling of the native bitmap (not sure why I did it that way!). I suspect the scaling should be done in the bitmap in the image in the control instead. Could you help work out how to do that?

@GitUserMarkus
Copy link
Author

If I remember correctly my experiments, without scaling the native bitmap (giving it a higher resolution than 1), the bitmap in the control will have a resolution which is not good enough for zooming in, too. Then it would be necessary to somehow link a page in the control to the corresponding page of the pdf such that one could rerender the bitmap with the needed resolution while zooming. A workaround could be to use a high scale (say 5) on creation of the bitmap, but to keep only a subset of the pages within the control. This would save the memoty for many hight resolution bitmaps (which is what I assume the reason for crashing). However, so far I did not find the time to implement something like that myself.

@DelphiWorlds DelphiWorlds added the priority low Low priority issue label May 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority low Low priority issue
Projects
None yet
Development

No branches or pull requests

2 participants