Force a PDF to display in a WebHTMLViewer

My database server creates a PDF file and my xojo web app loads it into an HTMLViewer

      //send a request to the database server for the path to the pdf
      Dim pdfWebFile As New WebFile
      Dim f As FolderItem = PathToFolderItem(responseDictionary.Value("filepath"))
      pdfWebFile = WebFile.Open(f)
      pdfWebFile.MIMEType = "application/pdf"
      HTMLViewer1.URL = myPDFFile.URL

This works great as long as the browser is set to display PDFs in the browser. Otherwise, the WebHTMLViewer is ignored and the PDF is displayed in a tab or window or downloaded, depending on the browser and the browser settings.

Is there any way to force the pdf to be opened in the HTMLViewer?

If not, I am thinking of putting instructions on how to set the browser’s preference to display the PDF in the browser. Is there a way to get the browser being used?

Session.mPDF = New WebFile
Session.mPDF.MimeType = “application/pdf”
Session.mPDF.ForceDownload = False
Session.mPDF.FileName = “report.pdf”
Session.mPDF.Data = data

@Alexis Colon Lugo Session.mPDF.ForceDownload = False

That does not work. As I understand it, Session.mPDF.ForceDownload is set to false by default and you would set it to true if you wanted to force the file to not open in your browser.

@Alexis Colon Lugo

Perhaps you were trying to tell me more than to use ForceDownload. Your sample code creates a pdf file and fills it with data, which I assume is dowloaded from the server. I am not doing it this way or at least I don’t think I am. I am passing a path to the WebFile with PathToFolderItem then assigning the WebFile.URL to the HTMLViewer. Should I be doing this differently?

Ok
So how you generate the pdf file

I use Valentina Reports it generate my PDFs Reports

The Xojo WebApp and the database server reside on the same machine. The PDF is generated by the Database Server. It is just a pdf file saved to a folder on the server. Xojo does not create the pdf. It sends a request to the database server for the path to the PDF file. Xoxo then downloads the pdf file for display in the HTMLViewer.

[quote=211630:@John Baughman]My database server creates a PDF file and my xojo web app loads it into an HTMLViewer

      //send a request to the database server for the path to the pdf
      Dim pdfWebFile As New WebFile
      Dim f As FolderItem = PathToFolderItem(responseDictionary.Value("filepath"))
      pdfWebFile = WebFile.Open(f)
      pdfWebFile.MIMEType = "application/pdf"
      HTMLViewer1.URL = myPDFFile.URL

This works great as long as the browser is set to display PDFs in the browser. Otherwise, the WebHTMLViewer is ignored and the PDF is displayed in a tab or window or downloaded, depending on the browser and the browser settings.

Is there any way to force the pdf to be opened in the HTMLViewer?

If not, I am thinking of putting instructions on how to set the browser’s preference to display the PDF in the browser. Is there a way to get the browser being used?[/quote]

You must be using Windows. Unfortunately, you depend on the user settings.

MBS DynaPDF has a rendering engine that may be able to do what you want. http://www.monkeybreadsoftware.de/realbasic/dynapdf.shtml

Also see https://forum.xojo.com/21529-pdf-to-image/0

@Michel Bujardet You must be using Windows

Actually the same is true on the Mac. For example in Firefox on the Mac you can easily switch prefs between opening with Adobe Reader or in the browser. Set it to “Preview in Firefox” and the pdf opens nicely in the HTMLViewer. Set it to “Use Adobe Reader” and it opens in the Adobe Reader app.

The more I think about it the more I think this is to be expected as the browser is only doing what the user has told it to do. Unfortunately the users of this site are mostly kids many as young as 8. While it is easy to change the pref in Firefox, Safari is a pain and I am not even sure how to do it in Explorer on Windows.

Your referral to pdf-to-image suggested an alternative for me. I can simply have the database server create a png or jpg instead of a pdf of the document.

Once again, thanks Michel!

Well, in Windows there is no such thing as opening PDF native in Safari. Out of the box, Windows 8 Internet Explorer was perfectly unable to display PDF, so was HTMLViewer. Fortunately today the Windows 10 Edge browser does open PDF natively, but as HTMLViewer is still bound to IE…

Generating a picture is indeed the best solution.