Экспорт в PDF Обещание необработанное - PullRequest
0 голосов
/ 17 октября 2018

Я создаю приложение для iOS с React native и мне нужна кнопка, которая при нажатии экспортирует некоторые текстовые данные в файл PDF.Проблема в том, что я использую эту библиотеку и получаю следующее ошибка .

Мой код следующий:

    exportPDF = async () => {

      const page1 = PDFPage
        .create()
        .setMediaBox(200, 200)
        .drawText('You can add text and rectangles to the PDF!', {
          x: 5,
          y: 235,
          color: '#007386',
        })
        .drawRectangle({
          x: 25,
          y: 25,
          width: 150,
          height: 150,
          color: '#FF99CC',
        })
        .drawRectangle({
          x: 75,
          y: 75,
          width: 50,
          height: 50,
          color: '#99FFCC',
        });

      const page2 = PDFPage
        .create()
        .setMediaBox(250, 250)
        .drawText('You can add JPG images too!')


      // Create a new PDF in your app's private Documents directory
      const docsDir = await PDFLib.getDocumentsDirectory();
      const pdfPath = `${docsDir}/sample.pdf`;
      PDFDocument
        .create(pdfPath)
        .addPages(page1, page2)
        .write() // Returns a promise that resolves with the PDF's path
        .then(path => {
          console.log('PDF created at: ' + path);
          // Do stuff with your shiny new PDF!
        }).catch(error => console.log(error));

  }

Кто-нибудьзнаете, как исправить необработанное отклонение обещания?

...