How to fit a pdfdocument fully in pdfviewer

57 views Asked by At

I want a pdfviewer where the pdf is fully matching the pdfviewer (so that no grey background is visible)

This is my code (with PDFObject):

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">

        <title>PDFObject</title>

        <style>
            body {
                margin: 0;
                padding: 0;
            }
        </style>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfobject/2.2.4/pdfobject.min.js" integrity="sha512-mW7siBAOOJTkMl77cTke1Krn+Wz8DJrjMzlKaorrGeGecq0DPUq28KgMrX060xQQOGjcl7MSSep+/1FOprNltw==" crossorigin="anonymous"></script>
    </head>
    <body>
        <main id="main">
            <div id="mypdf">
            </div>
        </main>

        <script>
            PDFObject.embed("myfile.pdf", "#mypdf", {width: "100vh", height: "100vh"});
        </script>
    </body>
</html>

This is actual

I want it like this also when I zoom in and out

Is there any solutions out there with PDFObject

1

There are 1 answers

1
K J On

You need to change the 3 values in your main command to get this result, However it will need to be different for each browser and possibly each user (NOTE you cannot remove the grey between pages)

enter image description here

For newest Acrobat Viewer in Edge III may work with many Chromium based viewers ?

PDFObject.embed("myfile.pdf#view=fith", "#mypdf", {width: "100vw", height: "98vh"});

You will find it cannot be 100 and 100 in all cases because at some lower heights if both are set maximum 100 then the scrollbars appear unnecessarily! and that point is based on the users default browser zoom so 98vh, this is only good at near normal 100% to 200 %

enter image description here

In order to force the window background to white you need to edit the settings in the PDF viewer like here but that can only work for users that allow such modification into their browser.
From https://github.com/pipwerks/PDFObject/issues/69

To my knowledge this is not possible, as it is controlled by the PDF rendering app (reader, FoxIt, Preview, PDF.js, etc). Sorry

enter image description here