1

Here is what I am trying

const [pdf, setPdf] = useState("")

let image = "data:application/pdf;base64," + curr.Body.toString('base64');

setPdf(image)

<WebView
            style={styles.pdf}
            useWebKit={true}
            originWhitelist={['*']}
            scrollEnabled={true}
            mediaPlaybackRequiresUserAction={true}
            source={{
                html: `
            <html>
            <object data="${pdf}" type="application/pdf">
                <embed 
                    scrollbar="1" 
                    src="${pdf}" 
                    type="application/pdf" 
                   
                />
            </object>
            </html>
            ` }}
        />

the below is what i am getting. The PDF contains 5 pages but i am getting only one on the screen.

enter image description here

help me to get the full pdf to the view.

vijay
  • 53
  • 2
  • 12

2 Answers2

0

try to wrap your code with a ScrollView to make the content visible/scrollable :

<SafeAreaView style={{flex: 1}}>
      <ScrollView
        style={{ width: '100%' }}
        contentContainerStyle={{ flexGrow: 1 }}
      >
        <WebView
            style={styles.pdf}
            useWebKit={true}
            originWhitelist={['*']}
            scrollEnabled={true}
            mediaPlaybackRequiresUserAction={true}
            source={{
                html: `
            <html>
            <object data="${pdf}" type="application/pdf">
                <embed 
                    scrollbar="1" 
                    src="${pdf}" 
                    type="application/pdf" 
                   
                />
            </object>
            </html>
            ` }}
        />
      </ScrollView>
    </SafeAreaView>

Or you can use a library dedicated for reading pdfs, such as : https://www.npmjs.com/package/rn-pdf-reader-js Here is an example :

<PDFReader
    style={{flex:1, flexGrow:1}}
        source={{
          uri: 'http://www.africau.edu/images/default/sample.pdf',
        }}
      />
chikabala
  • 653
  • 6
  • 24
0

This is by default/design.

Safari renderer will render only 1st page on iOS.

https://caniuse.com/pdf-viewer

When displaying PDFs inline rather than separately, iOS Safari will only display the first page of the document.

moljac
  • 946
  • 9
  • 12