{"id":4728,"date":"2021-07-30T05:07:32","date_gmt":"2021-07-30T05:07:32","guid":{"rendered":"https:\/\/studysection.com\/blog\/?p=4728"},"modified":"2021-07-30T05:07:32","modified_gmt":"2021-07-30T05:07:32","slug":"view-pdf-in-react-native-app","status":"publish","type":"post","link":"https:\/\/studysection.com\/blog\/view-pdf-in-react-native-app\/","title":{"rendered":"View PDF in React Native App"},"content":{"rendered":"<p>React Native is a cross-platform <a href=\"https:\/\/studysection.com\/blog\/javascript-coding-standards\/\">JavaScript<\/a> framework for developing natively rendering mobile applications for iOS and Android. It\u2019s based on the React framework which is developed by Facebook for building UI interfaces.<\/p>\n<p>It has a large community, so that&#8217;s why it has many libraries to make development easier. I was working on a project, in which I needed to show PDF inside my app. I was wondering how to do that. Then I found the react-native-pdf package. It is too easy and good, anyone having little knowledge of react native can implement it in his app.<\/p>\n<p>Today, I am gonna tell you how you can add this feature to your app. So, let&#8217;s get started.<\/p>\n<p>1. Firstly, you need to install the library. You can refer to its documentation for installation <a href=\"https:\/\/www.npmjs.com\/package\/react-native-view-pdf\">here<\/a>.<br \/>\n2. Create a new page with the name whatever you want then add the below code to that file.<\/p>\n<p><code>import React, { Component } from 'react';<br \/>\nimport { View } from 'react-native';<br \/>\nimport PDFView from 'react-native-view-pdf'; <\/p>\n<p>class PDFView extends Component {<br \/>\n   state = {<br \/>\n       data: '',<br \/>\n       isParsed: false,<br \/>\n   }<\/p>\n<p>   componentDidMount() {<br \/>\n       this.setState({data:'base64 pdf content'}) \/\/ load PDF content with base64 string of the file.<br \/>\n   }<\/p>\n<p>render() {<br \/>\n       const resourceType = 'base64'; \/\/ set resource type to base64<br \/>\n       return (<br \/>\n     &lt;View style={{ flex: 1 }}><br \/>\n       &lt;PDFView<br \/>\n         fadeInDuration={250.0} \/\/It will smoothly fade the view when loading is completed.<br \/>\n         style={{ flex: 1 }}<br \/>\n         resource={this.state.data}<br \/>\n         resourceType={resourceType}<br \/>\n         onLoad={() => console.log(`PDF rendered`)}<br \/>\n         onError={(error) => console.log('Cannot render PDF', error)}<br \/>\n       \/>  \/\/ This is the component which is provided by the library to abstract the difficulties from the developers.<br \/>\n     &lt;\/View><br \/>\n       );<br \/>\n   }<br \/>\n}<\/p>\n<p>export default PDFView;<\/code><\/p>\n<p>3. Now, add this Component to the App.js file of your application. Then run your application, and you will be able to see the screen on your emulator\/device as shown below.<\/p>\n<p><small>If you have knowledge of financial accounting and you are in search of a good job, financial accounting certification can help you reach your desired goals. StudySection provides <a href=\"https:\/\/www.studysection.com\/financial-accounting-foundation\">Financial accounting certification <\/a>for beginner level as well as expert level people in the commerce stream. You can appear in the certification exam for free to get certified.<\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>React Native is a cross-platform JavaScript framework for developing natively rendering mobile applications for iOS and Android. It\u2019s based on<\/p>\n","protected":false},"author":1,"featured_media":4734,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[523,352,686,347],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>View PDF in React Native App<\/title>\n<meta name=\"description\" content=\"React Native is a cross-platform JavaScript framework for developing natively rendering mobile applications for iOS and Android.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/studysection.com\/blog\/view-pdf-in-react-native-app\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"View PDF in React Native App\" \/>\n<meta property=\"og:description\" content=\"React Native is a cross-platform JavaScript framework for developing natively rendering mobile applications for iOS and Android.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/studysection.com\/blog\/view-pdf-in-react-native-app\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog Posts on famous people, innovations and educational topics\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/studysection\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-30T05:07:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/07\/View-PDF-in-React-Native-App.png\" \/>\n\t<meta property=\"og:image:width\" content=\"450\" \/>\n\t<meta property=\"og:image:height\" content=\"300\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"admin-studysection-blog\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@studysection\" \/>\n<meta name=\"twitter:site\" content=\"@studysection\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin-studysection-blog\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/studysection.com\/blog\/view-pdf-in-react-native-app\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/view-pdf-in-react-native-app\/\"},\"author\":{\"name\":\"admin-studysection-blog\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\"},\"headline\":\"View PDF in React Native App\",\"datePublished\":\"2021-07-30T05:07:32+00:00\",\"dateModified\":\"2021-07-30T05:07:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/studysection.com\/blog\/view-pdf-in-react-native-app\/\"},\"wordCount\":244,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"keywords\":[\"App\",\"Native\",\"pdf\",\"React\"],\"articleSection\":[\"Learn and Grow\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/studysection.com\/blog\/view-pdf-in-react-native-app\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/studysection.com\/blog\/view-pdf-in-react-native-app\/\",\"url\":\"https:\/\/studysection.com\/blog\/view-pdf-in-react-native-app\/\",\"name\":\"View PDF in React Native App\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/#website\"},\"datePublished\":\"2021-07-30T05:07:32+00:00\",\"dateModified\":\"2021-07-30T05:07:32+00:00\",\"description\":\"React Native is a cross-platform JavaScript framework for developing natively rendering mobile applications for iOS and Android.\",\"breadcrumb\":{\"@id\":\"https:\/\/studysection.com\/blog\/view-pdf-in-react-native-app\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/studysection.com\/blog\/view-pdf-in-react-native-app\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/studysection.com\/blog\/view-pdf-in-react-native-app\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/studysection.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"View PDF in React Native App\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/studysection.com\/blog\/#website\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"name\":\"Blog Posts on famous people, innovations and educational topics\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/studysection.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/studysection.com\/blog\/#organization\",\"name\":\"StudySection\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"contentUrl\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"width\":920,\"height\":440,\"caption\":\"StudySection\"},\"image\":{\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/studysection\",\"https:\/\/twitter.com\/studysection\",\"https:\/\/www.instagram.com\/study.section\/\",\"https:\/\/www.linkedin.com\/company\/studysection\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\",\"name\":\"admin-studysection-blog\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"caption\":\"admin-studysection-blog\"},\"url\":\"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"View PDF in React Native App","description":"React Native is a cross-platform JavaScript framework for developing natively rendering mobile applications for iOS and Android.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/studysection.com\/blog\/view-pdf-in-react-native-app\/","og_locale":"en_US","og_type":"article","og_title":"View PDF in React Native App","og_description":"React Native is a cross-platform JavaScript framework for developing natively rendering mobile applications for iOS and Android.","og_url":"https:\/\/studysection.com\/blog\/view-pdf-in-react-native-app\/","og_site_name":"Blog Posts on famous people, innovations and educational topics","article_publisher":"https:\/\/www.facebook.com\/studysection","article_published_time":"2021-07-30T05:07:32+00:00","og_image":[{"width":450,"height":300,"url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/07\/View-PDF-in-React-Native-App.png","type":"image\/png"}],"author":"admin-studysection-blog","twitter_card":"summary_large_image","twitter_creator":"@studysection","twitter_site":"@studysection","twitter_misc":{"Written by":"admin-studysection-blog","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/studysection.com\/blog\/view-pdf-in-react-native-app\/#article","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/view-pdf-in-react-native-app\/"},"author":{"name":"admin-studysection-blog","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402"},"headline":"View PDF in React Native App","datePublished":"2021-07-30T05:07:32+00:00","dateModified":"2021-07-30T05:07:32+00:00","mainEntityOfPage":{"@id":"https:\/\/studysection.com\/blog\/view-pdf-in-react-native-app\/"},"wordCount":244,"commentCount":0,"publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"keywords":["App","Native","pdf","React"],"articleSection":["Learn and Grow"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/studysection.com\/blog\/view-pdf-in-react-native-app\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/studysection.com\/blog\/view-pdf-in-react-native-app\/","url":"https:\/\/studysection.com\/blog\/view-pdf-in-react-native-app\/","name":"View PDF in React Native App","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/#website"},"datePublished":"2021-07-30T05:07:32+00:00","dateModified":"2021-07-30T05:07:32+00:00","description":"React Native is a cross-platform JavaScript framework for developing natively rendering mobile applications for iOS and Android.","breadcrumb":{"@id":"https:\/\/studysection.com\/blog\/view-pdf-in-react-native-app\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/studysection.com\/blog\/view-pdf-in-react-native-app\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/studysection.com\/blog\/view-pdf-in-react-native-app\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/studysection.com\/blog\/"},{"@type":"ListItem","position":2,"name":"View PDF in React Native App"}]},{"@type":"WebSite","@id":"https:\/\/studysection.com\/blog\/#website","url":"https:\/\/studysection.com\/blog\/","name":"Blog Posts on famous people, innovations and educational topics","description":"","publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/studysection.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/studysection.com\/blog\/#organization","name":"StudySection","url":"https:\/\/studysection.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","contentUrl":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","width":920,"height":440,"caption":"StudySection"},"image":{"@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/studysection","https:\/\/twitter.com\/studysection","https:\/\/www.instagram.com\/study.section\/","https:\/\/www.linkedin.com\/company\/studysection"]},{"@type":"Person","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402","name":"admin-studysection-blog","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","caption":"admin-studysection-blog"},"url":"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/"}]}},"views":1428,"_links":{"self":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/4728"}],"collection":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/comments?post=4728"}],"version-history":[{"count":9,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/4728\/revisions"}],"predecessor-version":[{"id":4738,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/4728\/revisions\/4738"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media\/4734"}],"wp:attachment":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media?parent=4728"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/categories?post=4728"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/tags?post=4728"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}