Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

Is there a way?

Edrol97

Silver Coder
Hi all,

Is there a way to set the default setting of the pdf viewer on load to fit-to-width rather than fit-to page?

Thanks,

Eliot

Code:
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>The Context by Context Cast News</title>
    <link rel="stylesheet" href="Style.css" />
    <link
      rel="icon"
      type="image/x-icon"
      href="/Users/eliot/Desktop/ContextCastNewsWeb/Fav.svg"
    />
    <style>
      /* Responsive PDF viewer styles */
      .pdf-container {
        width: 100%;
        max-width: 1200px;
        margin: 0 auto;
        padding: 20px;
        box-sizing: border-box;
      }

      .pdf-container object {
        width: 80%;
        border: 1px solid #ddd;
        border-radius: 8px;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
      }

      /* Large screens (desktops) */
      @media screen and (min-width: 1200px) {
        .pdf-container object {
          min-height: 1000px;
        }
      }

      /* Medium screens (tablets landscape) */
      @media screen and (max-width: 1199px) and (min-width: 992px) {
        .pdf-container object {
          min-height: 900px;
        }
      }

      /* Tablets portrait */
      @media screen and (max-width: 991px) and (min-width: 768px) {
        .pdf-container {
          padding: 15px;
        }
        .pdf-container object {
          min-height: 700px;
        }
      }

      /* Mobile devices */
      @media screen and (max-width: 767px) {
        .pdf-container {
          padding: 10px;
        }
        .pdf-container object {
          min-height: 500px;
        }
      }

      /* Small mobile devices */
      @media screen and (max-width: 480px) {
        .pdf-container {
          padding: 5px;
        }
        .pdf-container object {
          min-height: 400px;
        }
      }
    </style>
  </head>
  <body>
    <header>
      <div class="header-content">
        <div class="logo-section">
          <a href="Context.html" style="text-decoration: none; color: #000">
            <img
              style="margin: auto; display: block"
              src="/Users/eliot/Desktop/ContextCastNewsWeb/TheContextWeb.png"
              width="50%"
              alt="Logo"
            />
            <h1 style="text-decoration: none; font-family: Montserrat">
              By Context Cast News
            </h1>
          </a>
        </div>
      </div>
    </header>

    <nav>
      <a href="index.html">Home</a>
      <a href="History.html">History</a>
      <a href="Contributors.html">Contributors</a>
      <a href="Context.html" class="active">Context</a>
      <a href="mailto:[email protected]">Contact</a>
    </nav>
    <div class="body">
      <h1 style="text-decoration: none">Read the first edition</h1>
      <h2>And if you're impressed sign up for more</h2>

      <a
        href="https://docs.google.com/forms/d/e/1FAIpQLScIok0lA2eXsNhx-isZmrRAu9BkQxGhuN9cgUgwDRkK2ZMpaw/viewform"
        target="_blank"
      >
        <h1
          style="
            font-weight: bold;
            background-color: #012169;
            color: white;
            padding: 2%;
            text-align: center;
          "
        >
          Enter your details for your free print copy of the magazine every
          quarter
        </h1></a
      >

      <h2>
        <br />
        <b>The Latest Edition</b>
        <br />
        <br />
        Featuring Lord Prem Sikka PhD, David Starkey CBE, The Right Honourable
        Sir John Redwood and Kevin Dent KC.
      </h2>

      <div class="pdf-container">
        <object data="CCNews19.10.2025.pdf" type="application/pdf">
          <p>
            Alternative text - include a link
            <a href="CCNews19.10.2025.pdf">to the PDF!</a>
          </p>
        </object>
      </div>
    </div>
    <footer>
      <div class="footertop">
        <a href="index.html">Home</a>
        <a href="History.html">History</a>
        <a href="Contributors.html">Contributors</a>
        <a href="Context.html" class="active">Context</a>
        <a href="mailto:[email protected]">Contact</a>
      </div>
      <br />
      <h2>
        © Context Cast News 2025. Design by
        <a href="https://www.house-of-lord.co.uk">Eliot Lord</a>
      </h2>
    </footer>
  </body>
</html>


CSS:
html {
  height: 100%;
}

body {
  margin: 0;
  padding: 0;
  font-family: Arial, Helvetica, sans-serif;
  background-color: #f4f4f0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  text-align: center;
  overflow-x: hidden;
  -webkit-user-drag: none;
}

img {
  -webkit-user-drag: none;
}

body > *:not(footer) {
  width: 80%;
  margin-left: auto;
  margin-right: auto;
}

body::-webkit-scrollbar {
  width: 1em round;
  overflow: scroll;
}

body::-webkit-scrollbar-track {
  box-shadow: inset 0 0 6px #012169;
}

body::-webkit-scrollbar-thumb {
  background-color: #012169;
  outline: 1px solid #012169;
  width: 1em round;
  border-radius: 10px;
}

::selection {
  background-color: #012169;
  color: white;
}

nav,
h1,
h2 {
  overflow: hidden;
  margin: auto;
  display: block;
  width: 60%;
  text-align: center;
}

h1 {
  text-decoration: underline;
  font-size: clamp(18px, 2dvw, 32px);
}

h2 {
  font-size: clamp(14px, 1.2dvw, 24px);
}

h2 a {
  color: #c8102e;
}

h2 a:hover {
  color: #012169;
  font-weight: 900;
}

h1 a:hover {
  color: #ecd53e;
}

nav {
  padding-top: 2%;
  padding-bottom: 5%;
}

nav a {
  padding: 10px 5px;
  font-size: clamp(14px, 1.5dvw, 24px);
  text-align: center;
  text-decoration: none;
  color: #000;
}

nav a:hover {
  background-color: #c8102e;
  color: white;
  text-decoration: underline;
}

.active {
  background-color: #c8102e;
  color: white;
  text-decoration: underline;
}

.column {
  display: inline-block;
  width: 48%;
  padding: 10px;
  height: 300px;
  vertical-align: top;
  box-sizing: border-box;
}

.column:first-of-type {
  margin-right: 2%;
}

.bios-container {
  width: 90%;
  margin: 2% auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 2%;
}

.bio-item {
  width: 31.33%;
  text-align: center;
  margin-bottom: 3%;
}

.bio-item img {
  width: 50%;
  display: block;
  margin: 0 auto 1rem auto;
}

bio-item h1 {
  width: 100%;
  text-align: center;
}

.bio-item h2 {
  width: 100%;
  text-align: center;
}

/* Main content wrapper */
main {
  flex: 1;
}

/* Footer pinned to bottom */
footer {
  font-size: clamp(12px, 2dvw, 24px);
  padding: 1rem 0;
  margin-top: auto;
  width: 60vw;
  position: relative;
  margin: auto;
}

footer a {
  color: black;
  text-decoration: none;
}

footer a:hover {
  background-color: #c8102e;
  text-decoration: underline;
  color: white;
}

object {
  width: 100%;
  height: 80vh;
  min-height: 600px;
  max-height: 1200px;
  display: block;
  margin: 2% auto;
}

/* Responsive adjustments */
@media screen and (max-width: 768px) {
  body > *:not(footer) {
    width: 90%;
  }

  nav,
  h1,
  h2 {
    width: 90%;
  }

  .bios-container {
    width: 90%;
  }

  .column {
    width: 100%;
    margin-right: 0 !important;
    height: auto;
    margin-bottom: 20px;
  }

  .bio-item {
    width: 100%;
  }

  object {
    height: 70vh;
    min-height: 400px;
  }
}

@media screen and (max-width: 480px) {
  body > *:not(footer) {
    width: 95%;
  }

  nav,
  h1,
  h2 {
    width: 95%;
  }

  .bios-container {
    width: 95%;
  }

  nav {
    padding-top: 5%;
    padding-bottom: 8%;
  }

  nav a {
    display: block;
    margin-bottom: 5px;
    padding: 8px;
  }

  object {
    height: 60vh;
    min-height: 300px;
  }
}
 
@Edrol97 Not quite following what you're asking for. Do you have a link to the page?
So basically making a PDF viewer fully responsive to the screen width, for the percentage to be set at less than 100% on page load and for the little button on the pdf viewer that allows you to switch between page width and screen width to be toggled to fit to width rather than fit to page.
 
So basically making a PDF viewer fully responsive to the screen width, for the percentage to be set at less than 100% on page load and for the little button on the pdf viewer that allows you to switch between page width and screen width to be toggled to fit to width rather than fit to page.
I was able to get the viewer to be full viewport width with these changes:
CSS:
.pdf-container {
    width: 100%;
    margin: 0 auto;
    box-sizing: border-box;
}

.pdf-container object {
    width: 100%;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

You should also have a title attribute on the object:

title="PDF Viewer"
 

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom