GitHub
ComponentsDocument

Document

This component represents the PDF document itself. It must be the root of your tree element structure, and under no circumstances should it be used as child of another react-pdf component. In addition, it should only have children of type <Page />.

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

const MyDocument = () => (
  <Document title="Invoice" author="Acme Inc.">
    <Page size="A4">
      <Text>First page</Text>
    </Page>
    <Page size="A4">
      <Text>Second page</Text>
    </Page>
  </Document>
);
Show preview

Valid props

Prop nameDescriptionTypeDefault
titleSets title info on the document's metadataStringundefined
authorSets author info on the document's metadataStringundefined
subjectSets subject info on the document's metadataStringundefined
keywordsSets keywords associated info on the document's metadataStringundefined
creatorSets creator info on the document's metadataString"react-pdf"
producerSets producer info on the document's metadataString"react-pdf"
pdfVersionSets PDF version for generated documentString"1.3"
conformanceProduces PDF/A output with the given conformance level. See morePDFConformanceundefined
languageSets PDF default languageStringundefined
pageModeSpecifying how the document should be displayed when openedPageModeuseNone
pageLayoutThis controls how (some) PDF viewers choose to show pagesPageLayoutsinglePage
creationDateSets the creation date on the document's metadataDateundefined
modificationDateSets the modification date on the document's metadataDateundefined
ownerPasswordSets an owner password on the document. Owner password is required for setting permissionsStringundefined
userPasswordSets a user password on the document. When set, viewers will ask for the password before opening the fileStringundefined
permissionsDefines document permissions. Requires ownerPassword to be set. See morePermissionsundefined
onRenderCallback after document renders. Receives document blob argument in webFunctionundefined

PageMode type

pageMode prop can take one of the following values. Take into account some viewers might ignore this setting.

ValueDescription
useNoneNeither document bookmarks nor thumbnail images visible
useOutlinesDocument bookmarks visible
useThumbsThumbnail images visible
fullScreenFull-screen mode, with no menu bar, window controls, or any other window visible
useOCOptional content group panel visible
useAttachmentsAttachments panel visible

Conformance type

conformance produces an archival PDF/A file: the document gets XMP conformance metadata and an sRGB OutputIntent, and pdfVersion defaults to what the chosen level requires (1.4 for PDF/A-1, 1.7 for PDF/A-2 and PDF/A-3) unless you set it yourself.

ValueDescription
PDF/A-1Alias of PDF/A-1b, based on PDF 1.4
PDF/A-1bPDF/A-1 level B conformance
PDF/A-2Alias of PDF/A-2b, based on PDF 1.7
PDF/A-2bPDF/A-2 level B conformance
PDF/A-3Alias of PDF/A-3b, based on PDF 1.7
PDF/A-3bPDF/A-3 level B conformance

Only b-level (visual appearance) conformance is supported. PDF/A requires every font to be embedded, so register your own fonts with Font.register — documents using the built-in standard 14 fonts will not fully validate.

Permissions type

permissions prop accepts an object with the following optional boolean fields. All default to true when an owner password is set without specifying permissions.

ValueDescription
printingWhether the user can print the document
modifyingWhether the user can modify the document
copyingWhether the user can copy text and images
annotatingWhether the user can add or modify annotations
fillingFormsWhether the user can fill in form fields
contentAccessibilityWhether content can be extracted for accessibility purposes
documentAssemblyWhether the user can assemble the document (insert, rotate, delete pages)

PageLayout type

pageLayout prop can take one of the following values. Take into account some viewers might ignore this setting.

ValueDescription
singlePageDisplay one page at a time
oneColumnDisplay the pages in one column
twoColumnLeftDisplay the pages in two columns, with odd numbered pages on the left
twoColumnRightDisplay the pages in two columns, with odd numbered pages on the right
twoPageLeftDisplay the pages two at a time, with odd-numbered pages on the left
twoPageRightDisplay the pages two at a time, with odd-numbered pages on the right

On this page