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.

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.

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

Output each uploaded file using jQuery's console.log function

My AJAX upload form is set up and working, but when multiple files are selected they all upload at once. I want to create a separate div for each file to show the progress individually. However, when I try to test the number of files using this code snippe ...

Trick for using :checked in CSS

Is it possible to change the color of a deep linking div using an input checkbox hack in the code below? <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /&g ...

Discover the secrets to acquiring cookies within a Next.js environment

I am currently working with Next.js and attempting to retrieve a cookie value. Below is the code I have written: import cookie from "js-cookie"; export default function Home({ token }) { return ( <div className="flex flex-col items ...

How come the max-width property is not functioning properly on tables in Internet Explorer 7?

Is there a reason why the "max-width" property does not seem to have any effect on tables in Internet Explorer 7? While it works fine on other elements, when applied to a table, the max-width rule is completely ignored. <!DOCTYPE html PUBLIC "-//W3C//D ...

What is the best way to determine the size of the URLs for images stored in an array using JavaScript?

I am working on a project where I need to surround an image with a specific sized 'div' based on the image's dimensions. The images that will be used are stored in an array and I need to extract the height and width of each image before disp ...

Navigating an Array of Objects is not functioning properly within React

In my React App, I am facing an issue with populating a key identifier. Currently, the key is based on the Object.name property, but this is not ideal as it could lead to duplications and trigger errors in React. The server does not provide a unique key ei ...

Incorporate SVG or HTML5 elements into a Box2D World

My SVG logo is primarily composed of elements. I am interested in animating it by placing it in a "gravity world". Although I am new to Box2D and Canvas, I have managed to convert my SVG into HTML5 canvas using canvg. Currently, I am going through the begi ...

What are the steps to customize the format of Vue3 Datepicker extensions?

Is there anyone who can lend a hand? I am currently using the Vue3 Datepicker and I have received a value that looks like this Thu Jun 23 2022 17:14:00 GMT+0700 (Western Indonesia Time) Does anyone know how to transform it into the following format? Thu, ...

Buttons are not aligned with the rest of the row's height

I'm currently working on designing an upload layout that consists of a container with a row inside. Within the row, there are two buttons (each containing input elements) and one h3. For some reason, I am having difficulty getting them to align at the ...

How to add an OnClick listener to a cell element in a table built with the Tan

I am currently working on a project using React and trying to implement a table. I want to show an alert when a header cell in the table is clicked, displaying some information. However, I have been struggling to find assistance on adding a click listener ...

What method can I use to modify the object's keys based on certain conditions in ES6/React?

How can I dynamically change the value of an object's keys based on specific conditions? What is the most effective way to structure and implement this logic? Data const newData = { id: 111, name: "ewfwef", description: "Hello&qu ...

Display the div only after all images have finished loading in response to the AJAX call

Prior to diving into this, I am determined to steer clear of utilizing Jquery for personal reasons that I won't delve into. So please refrain from suggesting it, as that is not the solution I seek. I am currently working on a web page that sends mult ...

Creating videos with NEXTJS

I am currently developing a website using NextJS and I encountered an issue when trying to set a video as the background. Initially, everything works perfectly during the first render, but upon reloading the screen, the video no longer plays in autoplay mo ...

Guide to modifying the text color of a Primefaces/jqPlot line chart:

I've implemented a basic JSF line chart with PrimeFaces (using jqPlot library) in my project: <p:lineChart id="linear" value="#{team.chart}" title="Lap Times" xaxisLabel="Lap" yaxisLabel="Time ...

Content in tab remains stagnant

I am having trouble creating different tabs on a page with unique content in each tab's body. Whenever I click on a new tab, the body content remains the same. I'm not sure if it's an issue with how the tabs are set up in the HTML or if ther ...

Struggling to make Tumblr Javascript function properly

I have integrated the following code snippet: <script type="text/javascript" src="http://underlineent.tumblr.com/api/read/json"> </script> Unfortunately, my Tumblr blog is not appearing on this site. Can anyone provide assistance? The provid ...

forming a boundary that stands alone, unattached to any other boundaries

I am trying to design a navigation bar that resembles the one depicted in the image provided. The concept involves creating a navigation bar where each border is separated from the others, potentially achieved using hr tags. However, I am struggling to fi ...

Integrating mandatory updates in React Native applications

Trying to find a method to prompt users to update a React Native app before proceeding. This is new territory for me, so any guidance on how to tackle this would be greatly appreciated! Thank you in advance for any insight. ...

Error: The specified module could not be located and resolved: 'child_process'

Encountering a webpack error while using ReactJS, specifically when running npm start. The error message states: `./~/csvtojson/libs/core/workerMgr.js Module not found: Can't resolve 'child_process' in '/var/www/html/ReactLogin ...

In what ways can the accessibility of a website be impacted by using CSS

After reading numerous articles on Google and Stack Overflow, I have decided to ask my question straightforwardly in the hopes of receiving a clear and direct answer. Adding another layer to the discussion about whether Does opacity:0 have exactly the sam ...