{"size": 1011, "ext": "js", "max_stars_repo_path": "example/index.js", "max_stars_repo_name": "Magicianred/jsx-pdf", "max_stars_repo_stars_event_min_datetime": "2018-07-27T11:08:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T18:53:21.000Z", "max_issues_repo_path": "example/index.js", "max_issues_repo_name": "Magicianred/jsx-pdf", "max_issues_repo_issues_event_min_datetime": "2018-07-27T15:40:19.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T09:19:41.000Z", "max_forks_repo_path": "example/index.js", "max_forks_repo_name": "schibsted/jsx-pdf", "max_forks_repo_forks_event_min_datetime": "2018-07-25T14:59:36.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-20T03:09:01.000Z"}
{"max_stars_count": 108, "max_issues_count": 55, "max_forks_count": 18, "avg_line_length": 21.9782608696, "max_line_length": 94, "alphanum_fraction": 0.6607319486}
/* eslint-disable no-console */

import fs from 'fs';
import path from 'path';
import PDFMake from 'pdfmake';

import { OpenSans } from './font-descriptors';

// library
import JsxPdf from '../dst';

// PDF to render
import PDF from './components/root';

// metrics
const start = Date.now();

try {
  console.log('Generating PDF...');

  // here's where the PDF is created
  const config = {
    copyrightYear: 2018,
  };

  const pdfMake = new PDFMake({
    OpenSans,
  });

  const stream = pdfMake.createPdfKitDocument(
    JsxPdf.renderPdf(<PDF config={config} />),
  );

  // write the stream to a file; this could also be streamed to an HTTP connection, stdout etc
  stream.on('finish', () => console.log('PDF generated'));
  stream.pipe(fs.createWriteStream(path.resolve(__dirname, 'example.pdf')));
  stream.end();
} catch (err) {
  console.error('PDF generation failed');
  console.error(err);
} finally {
  // metrics
  const end = Date.now();
  console.error(`Took ${(end - start).toFixed(0)}ms`);
}
