Skip to content

Commit

Permalink
feat: add page mode support (#1868)
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomura authored Jun 6, 2022
1 parent 4fadb48 commit ce8762f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .changeset/lucky-wombats-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@react-pdf/pdfkit': minor
'@react-pdf/renderer': minor
'@react-pdf/types': minor
---

feat: add page mode support
4 changes: 4 additions & 0 deletions packages/pdfkit/src/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ class PDFDocument extends stream.Readable {
this._root.data.PageLayout = capitalize(this.options.pageLayout);
}

if (this.options.pageMode) {
this._root.data.PageMode = capitalize(this.options.pageMode);
}

// The current page
this.page = null;

Expand Down
2 changes: 1 addition & 1 deletion packages/pdfkit/src/mixins/outline.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default {
this.outline.endOutline();
if (this.outline.children.length > 0) {
this._root.data.Outlines = this.outline.dictionary;
this._root.data.PageMode = 'UseOutlines';
this._root.data.PageMode = this._root.data.PageMode || 'UseOutlines';
}
}
};
3 changes: 2 additions & 1 deletion packages/renderer/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const pdf = initialValue => {

const render = async (compress = true) => {
const props = container.document.props || {};
const { pdfVersion, language, pageLayout } = props;
const { pdfVersion, language, pageLayout, pageMode } = props;

const ctx = new PDFDocument({
compress,
Expand All @@ -43,6 +43,7 @@ const pdf = initialValue => {
displayTitle: true,
autoFirstPage: false,
pageLayout,
pageMode,
});

const layout = await layoutDocument(container.document, fontStore);
Expand Down
4 changes: 1 addition & 3 deletions packages/types/bookmark.ts → packages/types/bookmark.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ interface ExpandedBookmark {
expanded?: true | false;
}

export type Bookmark =
| string
| ExpandedBookmark
export type Bookmark = string | ExpandedBookmark;
19 changes: 17 additions & 2 deletions packages/types/node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,21 @@ interface PageProps extends BaseProps {
orientation?: Orientation;
}

type PageLayout = 'singlePage' | 'oneColumn' | 'twoColumnLeft' | 'twoColumnRight' | 'twoPageLeft' | 'twoPageRight'
type PageLayout =
| 'singlePage'
| 'oneColumn'
| 'twoColumnLeft'
| 'twoColumnRight'
| 'twoPageLeft'
| 'twoPageRight';

type PageMode =
| 'useNone'
| 'useOutlines'
| 'useThumbs'
| 'fullScreen'
| 'useOC'
| 'useAttachments';

interface DocumentProps {
title?: string;
Expand All @@ -46,7 +60,8 @@ interface DocumentProps {
keywords?: string;
creator?: string;
producer?: string;
pageLayout?: PageLayout
pageLayout?: PageLayout;
pageMode?: PageMode;
}

interface TextInstanceNode {
Expand Down

0 comments on commit ce8762f

Please sign in to comment.