Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: PDF not displaying in TWebBrowser - Need help


This question is answered. Helpful answers available: 1. Correct answers available: 1.


Permlink Replies: 3 - Last Post: Sep 11, 2017 4:49 AM Last Post By: Joe Fermani Threads: [ Previous | Next ]
Joe Fermani

Posts: 10
Registered: 2/4/13
PDF not displaying in TWebBrowser - Need help  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 7, 2017 11:00 AM
In my Android/iOS app, I download a pdf file from my server and save it in the app's document directory. I then invoke the twebbrowser and navigate to the file to display the PDF. The browser displays a blank page. This same code works fine on iOS. If I manually place the file on the phone and then use adobe to open the pdf, it displays fine.

The file is saved via the following lines:
fPDFFile := TPath.Combine(TPath.GetDocumentsPath, 'Temp.PDF');
aStream.SaveToFile(fPDFFile);

I then navigate to the file using the following command:
fBrowser.Navigate('file://' + fPDFFile);

I am running on a Samsung Galaxy 7 running Nougat .
Embarcadero® Delphi 10.1 Berlin Version 24.0.25048.9432

I use to be able to display PDFs in my app for Android. Last time I checked this feature I was running Seattle and I had a Galaxy Express running Jellybean.

I tried installing adobe and it had no effect on the problem.

Any ideas?

Edited by: Joe Fermani on Sep 7, 2017 11:01 AM

Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: PDF not displaying in TWebBrowser - Need help [Edit]
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 7, 2017 12:52 PM   in response to: Joe Fermani in response to: Joe Fermani
Am 07.09.2017 um 20:02 schrieb Joe Fermani:
In my Android/iOS app, I download a pdf file from my server and save it in the app's document directory. I then invoke the twebbrowser and navigate to the file to display the PDF. The browser displays a blank page. This same code works fine on iOS. If I manually place the file on the phone and then use adobe to open the pdf, it displays fine.

The file is saved via the following lines:
fPDFFile := TPath.Combine(TPath.GetDocumentsPath, 'Temp.PDF');
aStream.SaveToFile(fPDFFile);

I then navigate to the file using the following command:
fBrowser.Navigate('file://' + fPDFFile);

I am running on a Samsung Galaxy 7 running Nougat .
Embarcadero® Delphi 10.1 Berlin Version 24.0.25048.9432

I use to be able to display PDFs in my app for Android. Last time I checked this feature I was running Seattle and I had a Galaxy Express running Jellybean.

I tried installing adobe and it had no effect on the problem.

Any ideas?

Edited by: Joe Fermani on Sep 7, 2017 11:01 AM


Hello,

I'm not sure whether the webbrowser in Android can display PDF files.
But if you look at how Intents work (that's an Android mechanism to call
other apps, screens etc.) you can create one with a mimetype
representing PDF and your filename and then some program who registered
for PDF files will open and display it.

If there are several such apps available a chooser screen might be
presented by Android, unless the user already selected his default one
there once.

Greetings

Markus
Natkunasingam J...

Posts: 57
Registered: 3/5/00
Re: PDF not displaying in TWebBrowser - Need help  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 9, 2017 6:43 PM   in response to: Joe Fermani in response to: Joe Fermani
Joe Fermani wrote:
In my Android/iOS app, I download a pdf file from my server and save it in the app's document directory. I then invoke the twebbrowser and navigate to the file to display the PDF. The browser displays a blank page. This same code works fine on iOS. If I manually place the file on the phone and then use adobe to open the pdf, it displays fine.

The file is saved via the following lines:
fPDFFile := TPath.Combine(TPath.GetDocumentsPath, 'Temp.PDF');
aStream.SaveToFile(fPDFFile);

I then navigate to the file using the following command:
fBrowser.Navigate('file://' + fPDFFile);

I am running on a Samsung Galaxy 7 running Nougat .
Embarcadero® Delphi 10.1 Berlin Version 24.0.25048.9432

I use to be able to display PDFs in my app for Android. Last time I checked this feature I was running Seattle and I had a Galaxy Express running Jellybean.

I tried installing adobe and it had no effect on the problem.

Any ideas?

Edited by: Joe Fermani on Sep 7, 2017 11:01 AM



// Unlike Windows, iOS, the Android browser does not have built-in PDF view support.
// You can use intents on Android to present the user with an option to open the
// file using a pdf reader app
procedure TfrmMain.WebBrowser1DidStartLoad(ASender: TObject);
var
{$IFDEF ANDROID}
  Intent: JIntent;
{$ENDIF}
 LURL: string;
 IsPDF: Boolean;
begin
  LURL := WebBrowser1.URL;
  IsPDF := Pos('.pdf', LURL) > 0;
 
  {$IFDEF ANDROID}
    if IsPDF then  //PDf case
    begin
      Intent := TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_VIEW,
          TJnet_Uri.JavaClass.parse(StringToJString(LURL)));
      TAndroidHelper.Activity.startActivity(Intent);
    end;
  {$ENDIF}
end;
 
Joe Fermani

Posts: 10
Registered: 2/4/13
Re: PDF not displaying in TWebBrowser - Need help  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 11, 2017 4:49 AM   in response to: Joe Fermani in response to: Joe Fermani
Thanks for the replies. I have updated my code to invoke the pdf viewer outside of the browser.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02