bzwirs 4 Posted September 10 I am having a problem using the PDFControl on Android device. Have followed the example code for using the PDFControl in demo provided by Kastri but all I get is the PDF displayed in a narrow vertical area (small, about 10mm wide) up the middle of the screen. In the onCreate event I have placed if TOSVersion.Platform = TOSVersion.TPlatform.pfAndroid then begin FPDFControl := TPDFControl.Create(Self); FPDFControl.Align := TAlignLayout.Client; FPDFControl.Parent := TabItem17; end; The PDF needs to be displayed in TabItem17 of a TabControl. TabItem17 has nothing on it except for a TLayout at bottom of screen with a button to enable return to another TabItem. Following is the code used to load and display the PDF procedure TMainForm.Display_PDF(const sFile : string); begin {$IF DEFINED(ANDROID)} if FPDFControl <> nil then FPDFControl.LoadPDF(sFile); TabControl1.SetActiveTabWithTransition(TabItem17,TTabTransition.Slide, TTabTransitionDirection.Normal); {$ENDIF} {$ifdef win32} PDFBrowser.Navigate('file://' + sFile); TabControl1.SetActiveTabWithTransition(TabItem13,TTabTransition.Slide, TTabTransitionDirection.Normal); {$ENDIF} end; Can anybody please help with what I need to do to display the PDF properly. Thanks in advance. Bill Zwirs Share this post Link to post
Dave Nottage 557 Posted September 10 51 minutes ago, bzwirs said: Can anybody please help with what I need to do to display the PDF properly. I can replicate the behaviour using the original demo, adding a TabControl with 2 tabs. Reversing the calls fixes it for me, i.e. TabControl1.SetActiveTabWithTransition(TabItem17, TTabTransition.Slide, TTabTransitionDirection.Normal); FPDFControl.LoadPDF(sFile); ..however I can look into why the original way around is not working like it should. Share this post Link to post
bzwirs 4 Posted September 11 Thanks. Reversed the calls as suggested and that now works for me also. But has now raised another issue. The displayed PDF now adopts the background colour of the style set for the application instead of a white background. I've tried to play with the Opacity property of the FPDFControl which doesn't solve the problem and not sure what else to try. Any suggestions? Bill Zwirs Share this post Link to post
bzwirs 4 Posted September 11 Fixed the background colour problem by placing a TMSFNCPanel component on the TabItem and changing the FPDFControl.Parent to the panel name. The PDF now displays with a proper white background. Bill Zwirs 1 Share this post Link to post
Rollo62 536 Posted September 11 On 9/10/2024 at 11:55 AM, Dave Nottage said: I can replicate the behaviour using the original demo, adding a TabControl with 2 tabs. Reversing the calls fixes it for me, i.e. TabControl1.SetActiveTabWithTransition(TabItem17, TTabTransition.Slide, TTabTransitionDirection.Normal); FPDFControl.LoadPDF(sFile); ..however I can look into why the original way around is not working like it should. Perhaps it would even better to decouple this a little more, to be on the safe(r) side against timing problems on different OS and hardware. This is what I would usually do, if not really give a delay inbetween, like 50ms or so: TabControl1.SetActiveTabWithTransition(TabItem17, TTabTransition.Slide, TTabTransitionDirection.Normal); TThread.ForceQueu( nil, procedure begin FPDFControl.LoadPDF(sFile); end ); Share this post Link to post
bzwirs 4 Posted October 5 Since upgrade to Delphi 12.2 I am getting the PDF displayed in a narrow vertical area in middle of screen again. Have downloaded latest Kastri but that didn't fix the issue. Any ideas?? Bill Zwirs Share this post Link to post
Dave Nottage 557 Posted October 5 On 9/10/2024 at 7:25 PM, Dave Nottage said: Reversing the calls fixes it for me That now fails for me in Delphi 12.2 😞 Rollo's example, i.e.: TabControl1.SetActiveTabWithTransition(TabItem1, TTabTransition.Slide, TTabTransitionDirection.Normal); TThread.ForceQueue(nil, procedure begin FPDFControl.LoadPDF(LFileName); end); Works ok for me in Delphi 12.2 Share this post Link to post
bzwirs 4 Posted October 11 That works but still getting the narrow vertical print randomly. If pdf already exists then shows ok but if LoadPDF is called directly after creating the PDF then still getting the narrow view occasionally (exit out and view again and all ok). Any way around this behavior? Bill Zwirs Share this post Link to post
Dave Nottage 557 Posted October 11 20 minutes ago, bzwirs said: Any way around this behavior? Sounds like you already worked that out? i.e. create the PDF control beforehand. Share this post Link to post
bzwirs 4 Posted October 11 I think I didn't explain very clearly. Where I state 'creating the PDF', I am talking about creating a PDF document and then directly calling the PDFControl LoadPDF method to display the document. Bill Zwirs Share this post Link to post
Rollo62 536 Posted October 11 Like said, maybe you even need more decoupling, by a timer. Perhaps Android needs a while interally to build and save a PDF in the background, if PdfView kicks in too soon, that could maybe lead to odd behaviours. Share this post Link to post
Dave Nottage 557 Posted October 11 3 hours ago, bzwirs said: I am talking about creating a PDF document and then directly calling the PDFControl LoadPDF method to display the document. It might help to show the code you're using. Share this post Link to post
bzwirs 4 Posted October 12 Thank you Rollo and Dave. Added a delay value of 50 to the forcequeue (as suggested by Rollo in earlier post) and all seems to be working correctly now. Bill Zwirs Share this post Link to post