TMSFNCWebbrowser PDF viewing (from memory)

Hi,

I've made a simple test program to view PDF's in the FNC webbrowser component.
Seems to work just fine.

For this, I used the LoadFile method.
We have the PDF's in the database and not in the filesystem.
I could write it to disk and call LoadFile, but due to the sensitive nature of the PDF's and their contents it's undesirable.

Is there a way to load it "from memory" directly into the webbrowser?

Thx.

Hi,

you can use the following technique instead:

procedure TForm1.LoadFromStream(MyStream: TStream);
var
  h: string;
  p: string;
  ms: TMemoryStream;
begin
  p := TTMSFNCUtils.SaveStreamToBase64(MyStream);
  h := '<!DOCTYPE html><html><head></head><body><div>' +
    '<iframe width=100% height=500 src="data:application/pdf;base64,' + p + '">' +
    '</iframe></div></body></html>';
  TMSFNCWebBrowser1.LoadHTML(h);
end;

Thanks Peter for the extremely quick response.
I am definitely gonna try this one out.

1 Like

Hi Pieter,
Just tried your technique and it works great.

The only problem I now encounter is the Height=500 setting.
Unfortunately settting Height=100% doesn't work well.
Is there a way to autosize the Height.
The Width=100% works like a charm.

Thx.

Hi, you can use the following code instead:

  h := '<body style="margin: 0px; padding: 0px;">' +
    '<iframe frameborder="0" scrolling="no" height="100%" width="100%" src="data:application/pdf;base64,' + p + '">' +
    '</iframe></body>';

Looks to be working just great.
Thanks for this solution Pieter.

1 Like

You're welcome!