Display a PDF on a website and ensure it is horizontally scrolled to the center

After embedding a PDF in a webpage, I noticed that the width of the window is smaller than the actual PDF, resulting in a horizontal scroll bar appearing. Surprisingly, the PDF itself has wide margins on both sides, making it challenging for users to view the content easily. However, when the user scrolls to the center of the PDF, the content fits perfectly.

If possible, I would like this scrolling to happen automatically.

You can find the code here. Click on the specification tab to view the PDF.

For Google Chrome, I made the following adjustments:

I replaced the embed tag with an iframe.

<iframe id='pdf_embed' height='1300' style='width: 734px; margin-left: -40px;' src='iframe_url?pdf=pdf_url.'></iframe>

On the page with the iframe, I included the following styles:

<style>
object{
    width: 200%;
    margin-left: -370px;
    margin-top: -150px;
}
embed{
    width:100%;
    height:95%;
}
</style>
<html>
<body >
    <object height='1430' data="<?php echo $_GET['pdf']; ?>" type="application/pdf">
        <embed height='1430' src="<?php echo $_GET['pdf']; ?>" type="application/pdf" />
    </object> 
</body>
</html>

This solution worked well for zooming in on the PDF and eliminating the visible margins, making the text easier to read. Although it didn't work for Firefox or IE, @Infer-On's solution below provides an alternative.

Answer №1

It seems that passing some parameters to your PDF file might solve the issue. I found a helpful documentation with some suggestions:

You can try using the following code snippet:

zoom=scale 

This sets the zoom and scroll factors by using float or integer values. For instance, a scale value of 100 indicates a zoom value of 100%.

Alternatively, you could use:

view=Fit

This sets the view of the displayed page based on keyword values defined in the PDF language specification. For more details, refer to the PDF Reference.

Refer to the documentation to determine which parameter will work best for your needs:

http://example.org/doc.pdf#zoom=50
http://example.org/doc.pdf#view=Fit,100

EDIT

I have already attempted the following:

<object data="http://www.stelladoradus.com/wp-content/uploads/2014/03/en_spec_RP1000G3.pdf" 
 type="application/pdf" 
 width="300" height="500">
    <param name="view" value="fit" />

</object>  

http://jsfiddle.net/InferOn/wVaGa/23/

This method works, except for Chrome browser...

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

AngularJS basic webpage application halts code rendering

While working on an AngularJS tutorial on codeschool.com, I encountered a frustrating issue. Every time I refresh my browser to check my progress, the webpage ends up blank and refuses to load the code. I've restarted the tutorial from scratch twice, ...

Encountering issues loading background image with Reactjs and Webpack

I've encountered an issue while trying to load a background image in my React project from a custom CSS file. I am currently using Webpack 4. .bgimage { height: 100vh; background: url('../images/header.jpg'); } Unfortunately, the image ...

"Utilizing HTML aids for creating text input fields and adding line breaks

public string BannerText {get;set;} public void SetBanner() { BannerText = "This is line 1. \nThis is line 2." } on my webpage, I am displaying it like this: <div> <h1><%: Model.BannerText %></h1> </div> The issue ...

InsertOne function in MongoDB schema fails to add property during insertion operation

The issue has been resolved, thank you! Now, when I upload the document it appears in this format: { _id: "5e3b64b6655fc51454548421", todos: [ ], title: "title" } It should be formatted like this, as per the schema where the "title" property is listed ...

managing the placement of tooltipster tooltips for a set of radio buttons

I have successfully set up tooltipster to display my validation messages, but I am facing an issue with one specific case. The problem arises when dealing with a set of radio buttons where selecting "Yes" from the Yes/No options is mandatory. Despite setti ...

Guide on incorporating the WHERE clause into an insert statement in PHP version 5.1.6

What is the correct way to incorporate a where clause into an insert statement in PHP 5.1.6? In my code, I have declared a global variable $module and I am trying to use a where clause to refine my search results. Specifically, I want to include where mod ...

Uncovering the secrets to fetching numerous JSON files asynchronously using JavaScript and JQuery

My goal is to fetch multiple JSON files using JavaScript or jQuery and extract elements named j_name, j_value, and j_sts into sarr[i], rarr[i], and parr[i], respectively. var sarr = new Object; var rarr = new Object; var parr = new Object; //num_json rep ...

What causes the cleanup function in React hooks to be triggered upon reopening a previously closed tab?

There seems to be an issue with closing a tab and then undoing that action. This causes all the cleanup functions in the component to execute, resulting in the abortion of new fetches needed to load the component. This behavior is observed only on Safari ...

Is it possible to open one collapse item and simultaneously close all the others using Bootstrap 5?

Can someone explain how to properly use the Bootstrap 5 collapses component? I want it so that when one collapse item opens, all others close. The documentation mentions setting a parent attribute, but I'm not entirely sure how that works. Here's ...

Incorrect script enqueue order in child theme of WordPress

Help needed with enqueuing a script in a WordPress child theme. Despite specifying Jquery dependency, the script is loaded before Jquery. The code in question: add_action( 'wp_enqueue_scripts', 'child_theme_scripts' ); function child_ ...

I encountered a problem when making multiple JSON calls within a for loop

for(var j = 0; j < tempArray.length; j ++){ $.getJSON('http://localhost:8080/predict', tempArray[j]) .fail(function(data,textStatus, error) { Probability = data.responseText; console.error("getJSON failed, status: " + textStat ...

Having trouble dynamically applying css properties on the element

I am facing an issue where I want to display a popup without the scroll bar showing up. The popup is being displayed using an iframe. var addPartnerDialog = App.addDialog("AddExistingPartner", 500, 250); $(addPartnerDialog.getId()).css('overfl ...

Using the outer ng-repeat's object property to filter nested ng-repeat items

I'm currently working on nesting two ng-repeats with two separate JSON files. The goal is to filter the second ng-repeat based on parameters from the first ng-repeat. The first JSON file, $scope.matches, includes information about each match in the W ...

Executing ESM-Enabled Script in Forever

Is it possible to execute a script using the option -r esm in Forever? When I try to run the configuration below, I encounter an error message that reads: Unexpected token import. Here is the configuration: { "uid": "app", "script": "index.js", "s ...

Utilize an SVG to function as a block-level element

I've been struggling to find a solution for making my SVG element act as display: block. I want to display an image right below the SVG, but it keeps overlapping the SVG. I've attempted changing the properties to "display: block" and even creatin ...

Is it possible to eliminate the default placeholder text from Safari browser?

My goal is to design a form that includes date and time input fields. The placeholder text should move up by X pixels when the user clicks on the field. While the form appears fine in Chrome, there seems to be an issue with overlapping form fields in Safa ...

Adjusting the <input> value in real-time based on the fluctuating integer value

Within this foreach loop, I am retrieving images from a table named "Treasure" in the database: //the rest of the code is omitted for reading purposes. foreach (var item in tresh) { if (item.itemImage != null) { string imageBase = Conv ...

Eliminate empty space in the table cell

I am working with a table that looks like this: <table> ... <td> <div class="btn-group btn-group-sm"> <button class="btn btn-info mini"><span class="glyphicon glyphicon-duplicate"></span></button&g ...

Is there a method in PHP to conceal HTML code?

Although I understand that obfuscated html/js code may seem unnecessary to some (I've read similar questions on SO), I still want to add an extra layer of protection against potential copycats of my site... My website is php-based and generates html ...

Alter the background hue of alternate div elements within a row

The table I have contains multiple div elements, each corresponding to an item in an array. Within the table, there is a single tr, and the 1st and 2nd td are not directly related to the 3rd and 4th td. Each td in the table repeats a div element for the ...