"Ensuring that the embedded PDF in Bootstrap is not taking up the

I'm encountering an issue with the embedded pdf on this page for sponsorships. The previous site version was in html4, and the embedding method used the object tag as shown below:

<object data="pdf/GreekFestSponsorship2013.pdf" type="application/pdf" width="100%" height="700px"> 
  <p>It seems like you don't have a PDF plugin for this browser.</p>
  <p id="missing-pdf-plugin">You can <a href="pdf/GreekFestSponsorship2013.pdf">click here to download the PDF file</a>.</p>
  </object>

Now, the new code looks like this:

/* Flexible iFrame */
 
.flexible-container {
    position: relative;
    
    height: 0;
    overflow: hidden;
}
 
.flexible-container iframe,   
.flexible-container object,  
.flexible-container embed {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}
<!DOCTYPE html>
<!-HTML content goes here->   
                  
You can observe from this screenshot how the pdf doesn't stretch to 100% height. https://i.sstatic.net/PvC9Q.png

Answer №1

You have an additional 2 rulesets that will function as intended however you must...

  1. ...rectify this in HTML:

    <div class="flexible-container-embed"> 
    

    to this:

    <div class="flexible-container">
    
  2. ...and include this in the .flexible-container CSS ruleset:

    padding-bottom: 100%;
    

After adding these 2 rulesets, place them within a <style> element and then ensure it is positioned last inside the <head> section. Refer to the Plunker link below for a demonstration.

/* Flexible iFrame */
 
.flexible-container {
    position: relative;
    /* This blank line was most likely:
    || padding-top: 56.25%;
    */
    height: 0;
    overflow: hidden;
}
 
/* These rules say:
|| "Apply the following properties and their values to ANY `<iframe>`,
|| `<object>`, or `<embed>` THAT IS A CHILD OF any element with the 
|| class of `.flexible-container`.
*/
.flexible-container iframe,   
.flexible-container object, 
.flexible-container embed {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

When you implemented these 2 rulesets, you applied the class .flexible-container-embed to the wrapping div of the <object>, however both rulesets are meant for elements with the class .flexible-container as well as any children like <iframe>, <object>, or <embed>. Essentially, remove the -embed part from the class name.

Next up is the padding-bottom property. Typically set at 56.25%, when applied to an iframe container, it maintains a height ratio of 9 to width 16. This is suitable for wide screen videos, but not ideal for PDFs which usually have an aspect ratio of 8:11 or 72% (I utilized 100% in the example as per your request, anticipate an edit including a 72% version.) When combined with height:0, it creates a "shrinkwrap" container that adjusts its height based on content width. Update: there's no visible difference between 100% and 72% due to padding added by the PDF plugin.

I changed the <object> to an <iframe> since they offer more flexibility; you can also use <embed>. Check out this PLUNKER

Answer №2

Successfully displaying a PDF file at full 100% height can be quite challenging. Consider utilizing Bootstrap's responsive embedded media approach for a more satisfactory outcome with minimal hassle.

View in Chrome: https://i.sstatic.net/aFwrY.png

View in Firefox: https://i.sstatic.net/LDJnT.png

Code Snippet:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8>
    <title>PDF</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script
  src="https://code.jquery.com/jquery-2.2.4.min.js"
  integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
  crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
    <div class="container">
        <h1>Hello World!</h1>
        <div class="embed-responsive embed-responsive-4by3">
            <object data="test.pdf" type="application/pdf">
                <p>Your browser does not support embedded PDF files.<br>
                    <a href="test.pdf">Click here to download the PDF file.</a>
                </p>
            </object>
        </div>
    </div>
</body>
</html>

Note that some browsers may not fully support embedded PDF files, as indicated within the <object> tag.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Override the ui.bootstrap.tpls template for the datepicker popup.html template

I have developed a new template/datepicker/popup.html page that is loaded after ui.bootstrap.tpls. The issue I am facing involves calling a function from ng-click in the new template without making any changes to the ui.bootstrap.tpls file. I have attempt ...

Which component from the Bootstrap library would be best suited for my needs?

I am looking to create a basic 6-page website. Here is the code for my main page: <html> <style> .ali{ width:170px; text-align:center; } footer{ background:#333; color:#eee; font-size:11px; padding-top: 25px; p ...

Steps for embedding a webpage within a div element

I am facing an issue while trying to load a web page within a div using an ajax call. Unfortunately, it's not working as expected and displaying the following error message: jquery.min.js:2 [Deprecation] Synchronous XMLHttpRequest on the main thread ...

What is the best way to align the button correctly beside the cluster of checkboxes within bootstrap framework?

Here is a snippet of HTML code that I am working with: <div class="container"> <form name ="queryForm"> <div class="form-group"> <p class="checkbox-inline"> <input type="checkbox" name="optionsRadios" id="checkOne" ...

Toggle between pausing and running CSS animations with this handy button!

My awesome graphic animation is in CSS and SVG format. I've been struggling to add a play/pause button to control the animation on click. Here is what I have so far: .animation1 { --animation-delay: 0.1s; animation: ani_keyframes 1 ...

Customize .dropdown-content style to correspond with unique button IDs using CSS

I am currently working on a splash page that features 3 dropdown buttons, each associated with a specific color representing a geological time period. I am trying to customize the formatting of the .dropdown-content for each button to reflect its base colo ...

When using the `:hover` pseudoclass, it appears that it does not apply to the `<p>` element, but it does work

While hovering over the <a>, I noticed that it changes color correctly. However, when I hover over the <p>, nothing seems to happen. It's puzzling why the <p> does not change color upon being hovered over. If I switch the selector t ...

Only allow the next button to navigate to another tab if the JSON response is verified as true

This particular HTML form entails a tab-pane with specific data and inputs to be filled out. <div class="tab-pane" id="step1"> <form method="POST" onSubmit="return false;" data-parsley-validate="true" v-on:submit="handelSubmi ...

Issues with Swiper functionality in Jquery Mobile

I have implemented the Swiper plugin by idangero.us along with jQuery Mobile... In this case, I am utilizing the Scroll Container Swiper for a content slider... However, I am encountering several difficulties when trying to integrate the code... You can ...

Tips for altering the background of a video on Vonage

Hello everyone, Currently, I am incorporating the Vonage API for video calling into my project. I would like to tweak the video background - does anyone have any ideas on how to accomplish this? I eagerly await your responses! Thank you in advance! ...

Customizing jQueryUI Button: Changing the Color of Button Icons

I have embedded an HTML button within a div using the following structure: <div class="ui-state-highlight"> <button type="button" class="ui-button ui-state-default ui-corner-all ui-button-text-icon-primary"> <!-- first span --&g ...

Submitting a jQuery Userlike form will not result in a page change

I'm facing a challenge with posting a form without the page refreshing. Despite various suggestions on SO, none of the methods seem to work for my specific case. The use of jQuery's ajax or post APIs is not an option as they change the encoding ...

Toggle the class to slide in or out of the div

I am attempting to create a header with two positions - one absolute and one fixed. I want the header to smoothly slide in as you scroll down, and then slide out when you scroll back to the top. However, I am having trouble getting it to slide; instead, it ...

Displaying information from a database in a text box

I'm trying to display data from a database in a textbox using this code. However, when I click the show button, I encounter an error: (Notice: Undefined index: first_name ) How can I successfully display the data in the textbox? **//BootStrap Co ...

Prevent clicks from passing through the transparent header-div onto bootstrap buttons

I have a webpage built with AngularJS and Bootstrap. It's currently in beta and available online in (German and): teacher.scool.cool simply click on "test anmelden" navigate to the next page using the menu This webpage features a fixed transparent ...

Display a hidden div on every page of the website after clicking a designated <a> hyperlink for the first time

I came across a question like mine on Stack Overflow. The solution provided in the link is for clicking any div in the HTML, but I need something different. I want to click on the first div to display the second div, and then click on the second div to dis ...

Storing information on the webpage when it is refreshed

My goal is to maintain the order of the data in the target ordered list even after a page refresh, achieved through jQuery prepend on document ready. Here's the code snippet: // when a refresh event occurs window.onbeforeunload = function(event){ ...

Tips for displaying dynamic data using innerHTML

Recently, I set out to implement an infinite scroll feature in Angular 2 using JavaScript code (even though it may seem a bit unusual to use JavaScript for this purpose, it's actually working perfectly). Initially, I was able to create an infinitely s ...

The cards in the Bootstrap layout stack on top of one another when viewed on a mobile screen

I have a "flipping card" and another bootstrap 4 card positioned side by side. However, when tested on a mobile screen using Chrome's dev console, the second card overlaps the flipping card and covers it completely. To provide some context, I've ...

Using CSS to define the pseudo element :after that comes after an input

My HTML code is set and I'm unable to make changes, plus JavaScript isn't an option in this case. That leaves CSS as the only solution. For example, you can see the code here: https://jsfiddle.net/4gKPL/ HTML: <!-- code for input --> <d ...