Giter Club home page Giter Club logo

Comments (9)

xks19943 avatar xks19943 commented on July 19, 2024 6

add trustAllCerts={false} i fixed my problem 。 you can try <Pdf
style={{
width: pxToDp(355),
height: pxToDp(245),
}}
trustAllCerts={false}
source={source}
onError={(e)=>{
console.log('Pdf onError ' + JSON.stringify(e));
}}
/>

from react-native-pdf.

denisbevilacqua avatar denisbevilacqua commented on July 19, 2024

Same issue here! I am using RN 0.72.6.

from react-native-pdf.

igorpimentel23 avatar igorpimentel23 commented on July 19, 2024

same! expo sdk 50.0.2

from react-native-pdf.

Matzielab avatar Matzielab commented on July 19, 2024

I also have this issue in Expo and needed the app out asap so i did a workaround.

In my case i could download the pdf and store it in the bundled assets on android and only load from url on ios. But since it's expo and it builds the android folder itself, i wrote a plugin for it.

The plugin js file i placed in the root of my project

// withCopyPdf.js
const { withDangerousMod } = require("@expo/config-plugins");
const fs = require("fs");
const path = require("path");

module.exports = function withCopyPdf(config, { pdfFilename }) {
  return withDangerousMod(config, [
    "android",
    async config => {

      // Replace the path with the path to where you keep your pdf
      const filePath = path.join(
        config.modRequest.projectRoot,
        "assets",
        "documents",
        pdfFilename
      );

      const destPath = path.join(
        config.modRequest.platformProjectRoot,
        "app",
        "src",
        "main",
        "assets",
        pdfFilename
      );

      if (!fs.existsSync(filePath)) {
        throw new Error(`File ${filePath} does not exist`);
      }

      if (!fs.existsSync(path.dirname(destPath))) {
        fs.mkdirSync(path.dirname(destPath), { recursive: true });
      }

      fs.copyFileSync(filePath, destPath);

      return config;
    },
  ]);
};

In my case i had the pdf in my js source at assets/documents/pdfFilename.pdf

then i updated my app.config.json plugin array like this

"plugins": [
      ["./withCopyPdf", { "pdfFilename": "pdfFilename.pdf" }],
]

Then i can use it in my app like this:

const source = Platform.OS === "ios"
    ? {
        uri: "https://remote-pdf.com/pdfFilename.pdf",
        cache: true,
      }
    : { uri: "bundle-assets://pdfFilename.pdf" };

Hope it can help anyone needing a quick workaround until this issue is solved.

from react-native-pdf.

denisbevilacqua avatar denisbevilacqua commented on July 19, 2024

In my case, I was able to show a PDF in React Native 0.72 using another library called react-native-view-pdf.

from react-native-pdf.

esinanturan avatar esinanturan commented on July 19, 2024

For me the issue was with SSL certificate when I load the file from https it worked i hope it helps

from react-native-pdf.

18482048531 avatar 18482048531 commented on July 19, 2024

add trustAllCerts={false} i fixed my problem 。 you can try <Pdf style={{ width: pxToDp(355), height: pxToDp(245), }} trustAllCerts={false} source={source} onError={(e)=>{ console.log('Pdf onError ' + JSON.stringify(e)); }} />

you are right!think you

from react-native-pdf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.