2.0.0 • Published 2 years ago

@react-18-pdf/root v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

New react-pdf 2.0 was released. Read about the announcement

Lost?

This package is used to create PDFs using React. If you wish to display existing PDFs, you may be looking for react-pdf.

How to install

yarn add @react-pdf/renderer

Webpack 5

Webpack 5 doesn't include node shims automatically anymore and we must opt-in to all shims we want. To do this we have to add a few dependencies to our project:

yarn add process browserify-zlib stream-browserify util buffer assert

after the modules are installed, we need to adjust our webpack.config file:

const webpack = require("webpack");

module.exports = {
  /* ... */

  resolve: {
    fallback: {
      process: require.resolve("process/browser"),
      zlib: require.resolve("browserify-zlib"),
      stream: require.resolve("stream-browserify"),
      util: require.resolve("util"),
      buffer: require.resolve("buffer"),
      assert: require.resolve("assert"),
    }
  },
  plugins: [
    new webpack.ProvidePlugin({
      Buffer: ["buffer", "Buffer"],
      process: "process/browser",
    }),
  ]

  /* ... */
}

How it works

import React from 'react';
import { Document, Page, Text, View, StyleSheet } from '@react-pdf/renderer';

// Create styles
const styles = StyleSheet.create({
  page: {
    flexDirection: 'row',
    backgroundColor: '#E4E4E4'
  },
  section: {
    margin: 10,
    padding: 10,
    flexGrow: 1
  }
});

// Create Document Component
const MyDocument = () => (
  <Document>
    <Page size="A4" style={styles.page}>
      <View style={styles.section}>
        <Text>Section #1</Text>
      </View>
      <View style={styles.section}>
        <Text>Section #2</Text>
      </View>
    </Page>
  </Document>
);

Web. Render in DOM

import React from 'react';
import ReactDOM from 'react-dom';
import { PDFViewer } from '@react-pdf/renderer';

const App = () => (
  <PDFViewer>
    <MyDocument />
  </PDFViewer>
);

ReactDOM.render(<App />, document.getElementById('root'));

Node. Save in a file

import React from 'react';
import ReactPDF from '@react-pdf/renderer';

ReactPDF.render(<MyDocument />, `${__dirname}/example.pdf`);

Contributors

This project exists thanks to all the people who contribute. Looking to contribute? Please check our [contribute] document for more details about how to setup a development environment and submitting code.

Sponsors

Thank you to all our sponsors! [Become a sponsors]

Backers

Thank you to all our backers! [Become a backer]

License

MIT © Diego Muracciole

FOSSA Status


npm.io

abbrevababJSONStreamacornacorn-globalsacorn-import-assertionsacorn-walkagentkeepaliveagent-baseansi-regexabs-svg-pathajvaggregate-erroramdefineaprobaare-we-there-yetajv-keywordsansi-escapesarr-flattenarr-diffarr-unionarray-differansi-colorsansi-stylesany-promisearray-unionanymatcharray-uniqarray-uniquearia-queryarray-equalargparsearrifyarray-find-indexarray-ifyarray-includesarray.prototype.flatarray.prototype.flatmapassign-symbolsarray.prototype.reduceasapasn1assertast-typesatobast-types-flowast-transformassert-plusasync-limiterasynckitbabel-plugin-dynamic-import-nodeastral-regexatob-liteavailable-typed-arraysbabel-plugin-polyfill-corejs2babel-plugin-polyfill-corejs3babel-plugin-polyfill-regeneratorbaseaws4aws-sign2balanced-matchaxe-coreaxobject-querybabel-preset-jestbabel-plugin-jest-hoistbase64-jsbabel-plugin-istanbulbefore-after-hookbetter-path-resolvebrace-expansionbcrypt-pbkdfblobbinary-extensionsblob-streamblbracesbluebirdbrowserslistbrotlibreakwordbrowser-resolvebuffer-frombrowserify-optionalbrowser-process-hrtimebuiltin-modulesbuffer-crc32builtinsbserbtoa-litecache-basecall-me-maybecaller-callsitecaller-pathcamelcasebufferbyte-sizecaniuse-litebylinebytes-iecbrowserify-zlibcacachecall-bindcamelcase-keyscallsitescaselesscapture-exitchownrclass-utilschardetchokidarchrome-trace-eventci-job-numbercliuicloneclone-deepcharcodescodepointscode-point-atcollection-visitclean-stackcli-cursorci-infocli-widthcli-truncatecolor-stringcolumnifycocommondircolor-convertconcat-mapcomponent-emittercolor-namecolor-supportcoloretteconsole-control-stringscombined-streamcommandercompare-funcconfig-chainconfusing-browser-globalsconcat-streamconventional-changelog-angularconvert-source-mapcopy-descriptorconventional-changelog-preset-loaderconventional-changelog-corecore-jscore-js-compatconventional-changelog-writercore-util-isconventional-commits-filtercross-spawnconventional-recommended-bumpconventional-commits-parsercopy-concurrentlycore-js-purecosmiconfigcssomcrypto-jscssstylecsv-generatecross-fetchcsvcsv-stringifycsv-parsecurrently-unhandleddebugdashdashcyclistdecamelizedamerau-levenshteindargsdecode-uri-componentdedentdataloaderdata-urlsdeepmergedefaultsdateformatdebuglogdecompress-responsedefine-propertydelegatesdetect-indentdecamelize-keysdeep-isdefine-propertiesdelayed-streamdfadetect-newlinedeep-equaldezalgodetect-libcduplexerdevtools-protocoldot-propdeprecationdiff-sequenceselectron-to-chromiumemoji-regexend-of-streamdir-globdomexceptiondoctrinedotenvduplexifyenquirerecc-jsbnerror-exencodingenhanced-resolveenv-pathsenvinfoerr-codees-abstractes-shim-unscopableses-module-lexeres-array-method-boxes-properlyes6-object-assignescape-string-regexpes-to-primitivees6-promiseescaladeeslint-import-resolver-nodeescodegeneslint-config-airbnb-baseeslint-visitor-keyses6-promisifyeslint-utilseslint-module-utilseslint-scopeestree-walkerespreeesprimaeventemitter3esqueryexecaesutilsexpand-bracketsestimoestraverseextend-shallowesrecurseeventsextglobexitexec-shextendexpectexternal-editorextendable-errorextract-zipfast-globfiggy-puddingfast-levenshteinfast-json-stable-stringifyextsprintffast-deep-equalfind-cache-dirfd-slicerfb-watchmanfiguresfind-upfastqfill-rangefilter-objfind-chrome-binfile-entry-cachefor-infind-yarn-workspace-root2flat-cachefragment-cachefs-extraflush-write-streamfs-readdir-recursivefs.realpathflattedfunction-bindfor-eachforever-agentgaugefrom2gensyncfs-minipassfunction.prototype.namefs-constantsfunctions-have-namesfs-write-stream-atomicfunctional-red-black-treeget-pkg-repogenfunget-valueget-caller-fileget-streamget-intrinsicget-own-enumerable-property-symbolsgit-raw-commitsget-portget-symbol-descriptionglobgit-remote-origin-urlget-stdinglob-parentglobalsgetpassgit-semver-tagsgit-url-parsegraceful-fsgit-upgitconfiglocalglob-to-regexpglurgrapheme-splitterhandlebarshasglobbyhar-schemagrowlyhas-flaghard-rejectionhas-unicodehas-valueshas-valueform-datahomedir-polyfillhar-validatorhosted-git-infohas-bigintshas-tostringtaghas-ansihas-symbolshas-property-descriptorshsl-to-hexhsl-to-rgb-for-realshtml-escaperhttp-proxy-agenthttp-cache-semanticshtml-encoding-snifferhuman-idhttp-signaturehttps-proxy-agenthumanize-msignoreimport-localhuman-signalsimurmurhashieee754iconv-litehypheninflightimport-freshiferrinheritsignore-walkindent-stringis-accessor-descriptorinfer-ownerinit-package-jsonis-arrayishiniinternal-slotinvariantis-argumentsis-bufferis-builtin-moduleis-ciis-core-moduleinquireris-data-descriptoris-descriptoris-directoryis-extglobis-extendableipis-boolean-objectis-fullwidth-code-pointis-bigintis-globis-binary-pathis-moduleis-callableis-numberis-date-objectis-plain-objis-objis-plain-objectis-referenceis-generator-fnis-finiteis-generator-functionis-regexis-nanis-streamis-negative-zerois-regexpis-number-objectis-sshis-shared-array-bufferis-text-pathis-stringis-symbolis-subdiris-windowsis-typed-arrayisarrayis-unicode-supportedisexeisobjectis-typedarrayis-utf8is-urlis-weakrefis-wslistanbul-lib-coverageisstreamistanbul-lib-reportistanbul-lib-source-mapsistanbul-lib-instrumentistanbul-reportsjest-changed-filesjest-clijest-diffjest-eachjest-docblockjest-fetch-mockjest-configjest-environment-jsdomjest-get-typejest-environment-nodejest-leak-detectorjest-matcher-utilsjest-haste-mapjest-pnp-resolverjest-mockjest-message-utiljest-regex-utiljest-resolvejest-resolve-dependenciesjest-runnerjest-runtimejs-tokensjest-serializerjest-validatejs-yamljest-utiljson-parse-better-errorsjsescjest-snapshotjest-jasmine2jest-watcherjsbnjest-workerjson-schemajsonfilejsdomjson-schema-traversejson-stable-stringify-without-jsonifyjson5json-parse-even-better-errorskind-ofjsonparsejson-stringify-safejsx-ast-utilsjsprimlanguage-subtag-registrykleurlevenload-json-fileleft-padlanguage-tagslevnlocate-pathlines-and-columnslilconfiglodash.debouncelistr2load-yaml-fileloader-runnerlodash.getlodash._reinterpolatelodash.clonedeeplodash.sortbylodashlodash.ismatchlodash.startcaselodash.templatelodash.setlodash.unescapelodash.uniqmake-dirmagic-stringloud-rejectionlodash.templatesettingslog-updatemap-visitlog-symbolsmap-cachelru-cachemacos-releasemerge2merge-streammicromatchmake-fetch-happenmakeerrormap-objmedia-engineloose-envifyminimatchminimistmeowmime-dbmime-typesmixin-deepmimic-fnmin-indentminimist-optionsminizlibmimic-responseminipassmixmemississippimsmultimatchmkdirpmkdirp-classicmkdirp-promisenanomatchmodify-valuesmove-concurrentlymute-streammznice-trynannatural-comparenanoidnode-environment-flagsnode-releasesnanospinnernode-fetch-npmneo-asyncnode-fetchnode-gypnode-notifiernode-int64normalize-pathnormalize-package-datanpm-package-argnormalize-urlnormalize-svg-pathnpmlognumber-is-nannoptnpm-run-pathnpm-lifecycleobject-copyobject-assignnpm-bundlednpm-normalize-package-binnpm-pick-manifestnpm-packlistobject-visitoauth-signnwsapiobject-isobject-inspectobject.pickobject.assignonceobject-keysobject.entriesobject.fromentriesobject.getownpropertydescriptorsobject.hasownobject.valuesoctokit-pagination-methodsoptionatoros-homedironetimeos-tmpdirp-finallyp-limitp-locateoutdentp-mapos-namep-queuep-tryosenvp-filterpakop-pipep-waterfallp-each-seriesparse-jsonp-reduceparse-github-repo-urlp-map-seriesparent-moduleparallel-transformpascalcaseparse-passwdparse-urlpath-is-absoluteparse-svg-pathpath-keypath-typepath-dirnameparse5pifypicomatchpath-existspendpath-parseparse-pathpiratespkg-dirpinkieposix-character-classespixelmatchperformance-nowpinkie-promisepicocolorsplease-upgrade-nodepnprocess-nextick-argspngjsprelude-lspostcss-value-parserpreferred-pmprocesspretty-formatprogresspromise-retrypromise-polyfillproto-listpromise-inflightpromzardpromptspumpprotoduckprop-typesprotocolsproxy-from-envpumpifypseudomappslpuppeteer-corepunycodequeuerandombytesqqsqueue-microtaskquery-stringquick-lrureact-isreact-reconcilerreadread-package-jsonreadable-streamread-cmd-shimread-package-treeread-pkgregenerateread-yaml-fileregenerator-transformregenerator-runtimereaddir-scoped-modulesregex-notread-pkg-upregjsgenregexpu-coreregjsparserreaddirprepeat-elementrealpath-nativerepeat-stringredentregenerate-unicode-propertiesrepeatingregexpprequire-main-filenameresolveresolve-cwdregexp.prototype.flagsremove-trailing-separatorrequestresolve-fromretrequest-promise-corerequire-directoryrequest-promise-nativerestore-cursorretryresolve-urlrestructurerfdcreusifysafe-regexrsvprun-parallelrun-asyncrxjsrun-queuesafe-buffersemverserialize-javascriptset-blockingset-valueshallow-cloneshebang-commandshebang-regexsaxsanesignal-exitsafer-bufferschema-utilsshellwordsside-channelsemver-compareslashsimple-concatsimple-getsimple-swizzlesnapdragonschedulersnapdragon-nodesnapdragon-utilsisteransisort-keysslice-ansisource-mapsize-limitsource-map-resolvesource-map-supportsource-map-urlsmartwrapsourcemap-codecslidesmart-buffersocks-proxy-agentspawndamnitspdx-correctsplit-stringsocksspdx-expression-parsespdx-exceptionsspdx-license-idssplit2splitstatic-extendsprintf-jssplit-on-firstssim.jsssrisshpkstream-browserifystealthy-requirestack-utilsstring-widthstream-eachstream-shiftstream-transformstrict-uri-encodestrip-ansistring-lengthstrip-bomstrip-eofstring-argvstrip-final-newlinestring.prototype.trimendstrong-log-transformerstring.prototype.matchallstringify-objectstring_decoderstring.prototype.trimstartstrip-json-commentssupports-preserve-symlinks-flagsvg-arc-to-cubic-beziertablestrip-indenttartar-fstersertar-streamsymbol-treetemp-writetemp-dirterm-sizetapableterser-webpack-pluginthroughtiny-inflatetext-extensionstext-tabletest-excludeto-fast-propertiesto-object-pathto-regexthenify-allthenifythrough2throattmptmpltrim-newlinestough-cookietsconfig-pathsto-regex-rangetr46tslibtype-checktweetnacltunnel-agenttty-tabletype-festsupports-colorunicode-match-property-ecmascriptunicode-canonical-property-names-ecmascriptunicode-match-property-value-ecmascriptunicode-trieunicode-property-aliases-ecmascripttypedarrayunion-valueuid-numberuglify-jsuniversalifyunset-valueunbzip2-streamupathumaskurixutil-deprecateunique-filenameuseunique-sluguniversal-user-agentutilv8flagsuri-jsvalidate-npm-package-nameutil-promisifywalkerwcwidthutil.promisifyuuidv8-compile-cachevalidate-npm-package-licenseunbox-primitiveverrorw3c-hr-timewatchpackwebidl-conversionswebpackwhichwebpack-sourceswhatwg-fetchwhatwg-urlwhatwg-mimetypewide-alignwhatwg-encodingwhich-typed-arraywhich-pmwhich-modulewhich-boxed-primitivewordwrapwrite-file-atomicwrap-ansiwrite-pkgwrappywrite-json-fileword-wrapy18nwindows-releasexml-name-validatorwsxtendyallistwriteyamlyargs-parseryargsyocto-queueyauzl
2.0.0

2 years ago