Creating a vertical scrollable container that spans the full height of the PDF document

I am currently working on embedding a PDF file into my website. I'm trying to hide the status bar, including download buttons and page numbers, through some clever techniques so that I can control them externally. My goal is to be able to redirect users to a different document when they attempt to download the file. Also, just in case it matters (for example, if a solution will only work with a specific framework), I am using React for this project.

While I have managed to set the active page of the PDF by manipulating the URL, I cannot seem to update the scroll position to reflect the current page number after loading.

To address this issue, I believe that placing the embedded PDF within a div that I can manage myself might be a viable solution. Essentially, I plan to set the height of the embedded object equal to the combined vertical height of all pages in the PDF, then enclose it in a div with a fixed height. This way, I should be able to track the document's scroll position and determine which page is currently being viewed.

<div class='encasing-div'>
    <div class='toolbar'/>
    <object data='some.pdf' type='application/pdf'>
        <embed src='some.pdf' type='application/pdf' wmode='opaque'/>
    </object>
</div>

My challenge now lies in setting the embedded PDF to match the full height of the document. While I know the total number of pages in the PDF upon initial load, figuring out how to adjust the height accordingly remains a puzzle.

So, how does one actually go about making an embedded object stretch to fit the entire PDF length, thus removing the need for scrolling within the embedded object and allowing an external scroll mechanism?

Edit: To offer a visual representation of what I am trying to achieve, I've included a diagram. In the second part of the image, everything outside of the div would be concealed but still scrollable. https://i.sstatic.net/nFPvS.png

Answer №1

Instead of using object and embed, consider utilizing iframe

<!DOCTYPE html>
<html style="height:100%">
<body style="height:100%">

<h2>HTML Iframes</h2>
<p>Specify the size of the iframe using height and width attributes:</p>
<div style="height:100%">
        <iframe src="some.pdf" height="100%" width="100%""></iframe>
</div>

</body>
</html>

Answer №2

Consider a different approach. Depending on the browser to show the PDF may not work in every scenario. Each browser has its own way of showing a PDF and these methods are constantly changing. It would be better to use a library like pdf.js to manage how the PDF is displayed. This way, you have more control over the navigation elements and can adjust them as required.

Answer №3

One time I faced a similar issue and managed to resolve it by following these steps. It worked perfectly for me, so hopefully it can help you too:

<div class="PDFContainer">
     <object data="example.pdf" type="application/pdf"  height="100%" width="100%">
          <param name="src" value="example.pdf" />
     </object>
  </div>

Also, don't forget to add the following CSS styles:

.PDFContainer{
    height: 100vh;
}

Answer №4

Manipulating the scrollbars in the pdf viewer is only possible from within the viewer itself, and external control is not allowed by browsers. Users can turn on or off toolbar and scrollbars using specific key combinations, following instructions provided by the internal script of the PDF document similar to how it's done in Acrobat PDFs. Alternatively, manipulation can be carried out by the user or their program within the binary viewer.

https://i.sstatic.net/Otp8T.png

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

Empty gaps separating two divs nested within another div within a div (unable to function)

I'm diving into the world of HTML, CSS, and JS as I embark on creating a weather application. My vision is to include the temperature, followed by the city and its corresponding weather (accompanied by an icon), and lastly additional details like humi ...

What is the best way to position a background image at the top of a div without overlapping the

I have this HTML code: <div class="page"> <div id="header"> ... </div> </div> Below is my CSS: .page { width: 1028px; background-color:#103250; margin-left: auto; margin-right: auto; } ...

Adjust the width of a textarea dynamically as you type by detecting keyup events

Two text areas have the same text formatting. Their IDs are textareaA and textareaB. I've successfully added functionality to resize textareaA on keyup. How can I make textareaB resize its WIDTH while the user is typing in textareaA? Here's wha ...

Tips for creating a button-like anchor in Bootstrap 4

After using a button in Bootstrap 4, it appears as follows: https://i.sstatic.net/laGLo.png <button type="button" class="btn btn-primary" target="_blank">Download</button> On the other hand, when I substitute an anchor with the same button s ...

Finding the number of Tuesdays within a specified date range can be achieved through ReactJS - here's how!

When choosing dates on the calendar, for instance between June 10th and July 26th, I want to determine the count of Tuesdays and Thursdays in the specified range. ...

Unable to modify the background image of a div using jQuery

I'm encountering an issue in my script where I tried to implement an event that changes the background-image of a div when a button is clicked, but it's not functioning as intended. Below is the code snippet: HTML <div class="col-md-2 image ...

node index of data that has been posted

My HTML file is quite straightforward: <form method="post" action="http://localhost:3000/post"> <input name="name" type="text"/><br /> <input name="last_name" type="text"/><br /> <button id="submit" type="submit"& ...

Django Media Files Delivery with Nginx (Django/React/Nginx/Docker-Compose)

Background I currently have a one-page web application utilizing the following technology stack: React for the front end Django for the back end Nginx as the web server The web application is dockerized using docker-compose. In this setup, my React app ...

Challenges encountered with Material-UI elements

Attempting to implement the http://www.material-ui.com/#/components/drawer (Docked Example) component from Material-UI in conjunction with ReactJS. An error is encountered with the "=" sign in this line: handleToggle = () => this.setState({open: !this ...

What steps can I take to improve the design of this layout created using Twitter Bootstrap?

Currently, I am designing a sample form layout using Twitter Bootstrap. The form displays fields horizontally, with a link between each field. My goal is to have bullet points appear on the right side of the fields when the link is clicked. However, the al ...

Printing from a Windows computer may sometimes result in a blank page

Looking to incorporate a print button into an HTML page, I'm facing an issue. The majority of the content on the page should not be included in the printed version, so my approach involves hiding everything in print and then showing only the designate ...

Having trouble submitting data to a NextJS API route?

I am currently working on a simple form within a NextJS page, where the data is being stored in state: const [bookingInfo, setBookingInfo] = useState({ name: "", email: "", phone: "", }); const handleChange = (e ...

Attempting to determine the smallest and largest dimensions of two values using CSS3

Trying to make sure the image on my phone adjusts its size based on orientation, I attempted using Ionic4. When in landscape mode, I want it to adapt according to height instead of width. Essentially, I need it to use the minimum size and also require the ...

Mastering the art of carousel div creation with Bootstrap

Is there a way to create a carousel in Bootstrap 3 where only one div slides at a time, instead of three? I attempted to use divs instead of images in the traditional carousel structure, but it's not functioning as expected. I'm looking for some ...

Updating events instantly with a single click in Angular 6: A step-by-step guide

Hello there, I am currently diving into learning Angular 6 and I have encountered a query. I want to achieve a functionality where upon clicking a button, the text on the button changes as well as the corresponding event that triggers when the button is cl ...

Utilizing unique background images tailored to different screen resolutions

In order to enhance the user experience on my website, I am looking to implement a feature that dynamically changes the background images based on the user's screen resolution. My plan is to use a small snippet of JavaScript within the <head> s ...

Struggling with simulating a React component in Jest using React Testing Library?

Currently, I am in the process of writing tests for a local component known as LocalLink. My main goal is to ensure that it correctly passes the 'slug' prop to the third-party component ThirdPackageLink. In order to achieve this, I attempted to m ...

Developing 2 potential results from textarea input using NODE.JS and HTML

Today, I encountered an issue while working on my bot website project that responds to textarea input. When I attempted to test it with two different commands, one of the commands stopped working unexpectedly. I'm puzzled by this and would greatly app ...

What is the best way to configure the loading state of my spinner?

When a user clicks to navigate to the articles page, I want to display a spinner while waiting for the articles data to be fetched and displayed. There is a slight delay after the click, hence the need for the spinner. I have a custom spinner component ca ...

Is the IE7 Modal Dialog Misaligned?

Update After some investigation, I discovered the root cause of the problem. In my code, I was referencing the height of the overlay, which resulted in different values in IE7 compared to other browsers. To resolve this issue, I adjusted the code to refe ...