christopherdro / react-native-html-to-pdf

Convert html strings to PDF documents using React Native
MIT License
435 stars 269 forks source link

App terminated due to memory issue in Xcode #180

Closed BrettThurs10 closed 3 years ago

BrettThurs10 commented 4 years ago

Hey there, I'm running into an issue with my app. I'm certain that I've isolated the issue to this, but I can't figure out where to go from here.

2020-05-11 14:15:09.196651-0500 MyApp[1304:47101] [Unknown process name] Failed to load /System/Library/PrivateFrameworks/CorePDF.framework/Versions/A/CorePDF

My PDF is created and placed, but then my app is terminated due to excessive Memory use in Xcode.

My device is plugged in and I'm running the app on the device, not the emulator. Any help would be appreciated.

My function: ` multiPdfDoc = async (options, count) => { let pdfContent; let pdfFileName; let pdfPage; let pdfOptions; const contentGroup = [];

this.setState({
  fileStatus: `Generating ${options.friendlyName} PDF`,
});

if (count !== undefined) {
  for (
    let index = 0;
    index < utils.splitPairs(options.array).length;
    index++
  ) {
    if (typeof options.refArray === 'object') {
      await this.refs[options.refArray[index]]
        .capture()
        .then(async (uri) => {
          if (uri) {
            if (Platform.OS == 'android') {
              await RNFS.readFile(uri, 'base64').then(async (res) => {
                uri = res;
                pdfContent = `${
                  (await "<img height='920' width='100%' src='data:image/png;base64,")
                  + uri
                }'></img>`;
                await contentGroup.push(pdfContent);
              });
            } else {
              pdfContent = `${
                (await "<img height='920px' width='100%' src='") + uri
              }'></img>`;

              await contentGroup.push(pdfContent);
            }
          }
        })

        .catch((e) => {
          console.log(e);
        });
    }
  }
} else if (options == myOptions) {
  if (Platform.OS == 'android') {
    await RNFS.readFile(my1Capture, 'base64').then((res) => {
     my1Capture = res;
    });

    await RNFS.readFile(my2Capture, 'base64').then((res) => {
      my2Capture = res;
    });

    const my1page = `${
      (await "<img height='920' width='100%' src='data:image/png;base64,")
      + my1Capture
    }'></img>`;

    const my2page = `${
      (await "<img height='920' width='100%' src='data:image/png;base64,")
      + my2Capture
    }'></img>`;

    const someArr = [my1page, my2page];
    await contentGroup.push(...someArr);
  } else {
    console.log('multi pdf doc for IOS');
    const my1page = `${
      (await "<img height='920px' width='100%' src='") + my1Capture
    }'></img>`;

    const my2page = `${
      (await "<img height='920px' width='100%' src='") + my2Capture
    }'></img>`;

    contentGroup.push(my1page, my2page);
  }
} else {
  for (let index = 0; index < options.array.length; index++) {
    if (typeof options.refArray === 'object') {
      await this.refs[options.refArray[index]]
        .capture()
        .then(async (uri) => {
          if (uri) {
            if (Platform.OS == 'android') {
              await RNFS.readFile(uri, 'base64').then(async (res) => {
                uri = res;
                pdfContent = `${
                  (await "<img height='920' width='100%' src='data:image/png;base64,")
                  + uri
                }'></img>`;
                await contentGroup.push(pdfContent);
              });
            } else {
              pdfContent = `${
                (await "<img height='920px' width='100%' src='") + uri
              }'></img>`;

              await contentGroup.push(pdfContent);
            }
          }
        })

        .catch((e) => {
          console.log(`there was an error generating the pdf ${e}`);
        });
    }
  }
}

pdfFileName = `${options.cid.toString()}-${options.userid.replace(
  /['"]+/g,
  '',
)}-${Date.now()}-${options.refName}`;

activeFileName = pdfFileName;

pdfOptions = {
  // Need HTML for Form
  html: contentGroup.joinArr(''),
  // File Name
  fileName: pdfFileName,
  // File directory
  directory: 'Documents',
};
pdfPage = await RNHTMLtoPDF.convert(pdfOptions);

pdfPage;

console.log(`file path is ${pdfPage.filePath}`);

// fileStatus = options.friendlyName + ' PDF created';
// pdfLocation = pdfPage.filePath;

await this.setState({
  fileStatus: `${options.friendlyName} PDF created`,
  pdfLocation: pdfPage.filePath,
});
console.log('multi pdf doc finished');

};`

BrettThurs10 commented 4 years ago

Console.log never makes it to log 'multi pdf doc finished')

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.