Show pdf in a htmlViewer

I use this method code to load a pdf and show it into an htmlViewer:

  if PdfFile.Exists Then
    PreviewFile = WebFile.Open(PdfFile)
    PreviewFile.MIMEType = "application/pdf"
    PreviewFile.UseCompression = False
    HVPreview.URL = PreviewFile.URL
  End If

It works fine, but some time I’ve got this error:

In webapp error.log I found this:

JavaScript Error: Error: Could not execute returned javascript: Cannot read property 'children' of null Source: document.getElementById('JksPgQwS').children[0].src = "/17AA9EB4F3D5D80935E17EFF30158C449CDDC7A9/files/4881-2410-4886-0669-5337/tmpdoc__4rb0tazv4.PDF"; User Details:

Any idea?

Where is PreviewFile stored? If it goes out of scope, it would be destroyed before it gets to the HTML Viewer.

What I sometimes do is opening a PDF as a picture. And with a picture object you can do whatever you want.
I have not tried it with multi-page documents though.

It might not be what you are looking for. But it maybe inspires future readers :slight_smile:

I found the error and solve it.
The code was correct, but there was a problem in another method that call the htmlviewer refresh when the file still not exists.

Thanks to all for contributions