PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, December 1, 2022

[FIXED] How do I make an iframe show at 100%?

 December 01, 2022     iframe, pdf, vb.net, webview2     No comments   

Issue

I am trying to follow along with this post to show a PDF in a WebView2. I have set my WebView2 to dockstill "Fill", so it will use the entire space of the form.

The author recommends:

Dim html As String = "<!DOCTYPE html><html><head></head><body><div>" &
        $"<iframe width=100% height=500 src=""data:Application/pdf;base64,{pdfBase64}"">" &
        "</iframe></div></body></html>"

Me.WebView2.NavigateToString(html)

This works.

The PDF is displayed over the width of the webview / form and with 500 pixels in height.

However, I would like the iframe to be the size of the parent. To do that, I change "500" to "100%" like this:

Dim html As String = "<!DOCTYPE html><html><head></head><body><div>" &
        $"<iframe width=100% height=100% src=""data:Application/pdf;base64,{pdfBase64}"">" &
        "</iframe></div></body></html>"

This has no effect. Instead, the pdf that is shown in the iframe gets a height of 152 pixels.

enter image description here

What am I doing wrong?


Solution

Probably just invalid or at least not well-formatted HTML string. I'd suggest using the XElement syntax to build the HTML output, it helps to write the tags and attributes correctly...

Dim pdfBytes = 'The PDF byte array...
Dim pdfBase64 = Convert.ToBase64String(pdfBytes)
Dim html =
    <html>
        <body>
            <iframe
                width="100%"
                height="100%"
                src=<%= $"data:application/pdf;base64,{pdfBase64}" %>>
            </iframe>
        </body>
    </html>.ToString()

WebView21.NavigateToString(html)

SO73708467

Nice VB.NET feature.



Answered By - dr.null
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing