React-pdf: Component PDFViewer: set props height to 100 % does not work

Created on 9 Sep 2020  路  14Comments  路  Source: diegomura/react-pdf

Describe the bug
Based on the react-pdf documention, you can set the props height for the PDFViewer. I was wondering is it possible to add a % for height ? I have also tried with the Width and this props accept the %.

here example with 100 %:
image

expected result ( I would like to have a PDF to be fully cover the page):
image

Most helpful comment

Try this:

<PDFViewer
      style={{ position: 'absolute', border: 0, height: '100%', width: '100%' }}
>
   <PDFDocument />
</PDFViewer>

I insert border: 0 because of the edge browser.

Credits: https://stackoverflow.com/a/18665613

All 14 comments

could you solve it?

No i wasn't able to solve it

Have you tried adding width and height property to pdfviewer? As I see if, it also tries to put those properties to the container of the pdfviewer

Yes I've set the height=100% and the width=100%

I have an example where the pdfviewer works correctly, let me look it up.

image

image
Do you have this like that?

after testing this syntax:

function App() { return ( <PDFViewer width={"100%"} height={"100%"}> <MyDocument /> </PDFViewer> ); }

I still have the same problem:
image

here's my MyDocument Component code (from the official documentation):

import React from "react";
import { Page, Text, View, Document, StyleSheet } from "@react-pdf/renderer";

// Create styles
const styles = StyleSheet.create({
page: {
  flexDirection: "row",
  backgroundColor: "#E4E4E4",
},
section: {
  margin: 10,
  padding: 10,
  flexGrow: 1,
},
});

// Create Document Component
export const MyDocument = () => (
   <Document>
       <Page size="A4" style={styles.page}>
           <View style={styles.section}>
              <Text>Section #1</Text>
           </View>
           <View style={styles.section}>
             <Text>Section #2</Text>
           </View>
       </Page>
</Document>
);

My temporary solution is to use window.innerHeight instead 100%.

do you have example ?

Just change height value in PDFViewer component:

<PDFViewer height={window.innerHeight} width="100%">
  <PDFDocument />
</PDFViewer>

it works, but the only (more UI related problem) is that their two scroll bars:

image

Try this:

<PDFViewer
      style={{ position: 'absolute', border: 0, height: '100%', width: '100%' }}
>
   <PDFDocument />
</PDFViewer>

I insert border: 0 because of the edge browser.

Credits: https://stackoverflow.com/a/18665613

it works !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

theobat picture theobat  路  3Comments

brandly picture brandly  路  3Comments

saratonite picture saratonite  路  3Comments

kishaningithub picture kishaningithub  路  4Comments

idrisadetunmbi picture idrisadetunmbi  路  3Comments