Repository: foliojs/pdfkit

Issue:
how to set display mode so it opens as full page by default
PDF's usually open with 100% width which is ugly. I would like them to open as full page by default, I know this is possible. In PHP when I make PDF's with TCPDF I can use SetDisplayMode() which works well:
http://www.tcpdf.org/doc/code/classTCPDF.html#ad99d9dea88f659fedf9fe11f30586a99

Is the same possible in pdfkit somehow?



Discussion:
You can set these options directly in the _root object (I will make a pull request to add an option in the PDFDocument constructor if there is still interest in this feature)

```
// Full page (1st page : 0)
doc._root.data.OpenAction = [0, 'Fit'];
// Display a single page
doc._root.data.PageLayout = 'SinglePage';
// Display pages in a continuous scrolling column
doc._root.data.PageLayout = 'OneColumn';
// Display pages in two continuous columns
doc._root.data.PageLayout = 'TwoColumnLeft';
```

Thanks, I've hacked the source code a bit to get what I wanted, but this looks better :). I'll keep this in mind.




Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8acdc80f..edba1fff 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@
 - Fix garbled text copying in Chrome/Edge for PDFs with >256 unique characters (#1659)
 - Fix Link accessibility issues
 - Fix Table Accessibility Issue: Operator CS/cs not allowed in this current state
+- Add pageLayout option to control how pages are displayed in PDF viewers
 - Fix Interlaced PNG with indexed transparency rendered incorrectly
 - Preserve existing PageMode instead of overwriting when adding outlines
 - Support outlines that jump to specific page positions with custom zoom level
diff --git a/docs/getting_started.md b/docs/getting_started.md
index 5538b9b6..0ae63d5d 100644
--- a/docs/getting_started.md
+++ b/docs/getting_started.md
@@ -77,6 +77,25 @@ which is used to load built-in font data into the package. It is listed as a `de
 PDFKit's `package.json`, so it isn't installed by default for Node users.
 If you forget to install it, Browserify will print an error message.
 
+## Document options
+
+When creating a PDFDocument, you can pass various options to control the document behavior.
+
+### Page Layout
+
+The `pageLayout` option specifies how pages should be displayed in a PDF viewer:
+
+| Value | Description |
+|-------|-------------|
+| `singlePage` | Display one page at a time |
+| `oneColumn` | Display pages in one column |
+| `twoColumnLeft` | Display pages in two columns, odd pages on left |
+| `twoColumnRight` | Display pages in two columns, odd pages on right |
+| `twoPageLeft` | Display two pages at a time, odd pages on left |
+| `twoPageRight` | Display two pages at a time, odd pages on right |
+
+    const doc = new PDFDocument({ pageLayout: 'twoColumnLeft' });
+
 ## Adding pages
 
 The first page of a PDFKit document is added for you automatically when you
diff --git a/lib/document.js b/lib/document.js
index 9433209f..b3296f4c 100644
--- a/lib/document.js
+++ b/lib/document.js
@@ -81,6 +81,12 @@ class PDFDocument extends stream.Readable {
       this._root.data.Lang = new String(this.options.lang);
     }
 
+    if (this.options.pageLayout) {
+      const layout = this.options.pageLayout;
+      this._root.data.PageLayout =
+        layout.charAt(0).toUpperCase() + layout.slice(1);
+    }
+
     // The current page
     this.page = null;
 


Test patch:
diff --git a/tests/unit/document.spec.js b/tests/unit/document.spec.js
index 16441787..34d17c27 100644
--- a/tests/unit/document.spec.js
+++ b/tests/unit/document.spec.js
@@ -67,4 +67,28 @@ describe('PDFDocument', () => {
 
     expect(catalog).not.toContain('/Metadata');
   });
+
+  describe('pageLayout', () => {
+    test('sets PageLayout in catalog when provided', () => {
+      const doc = new PDFDocument({ pageLayout: 'twoColumnLeft' });
+      expect(doc._root.data.PageLayout).toBe('TwoColumnLeft');
+    });
+
+    test('does not set PageLayout when not provided', () => {
+      const doc = new PDFDocument();
+      expect(doc._root.data.PageLayout).toBeUndefined();
+    });
+
+    test.each([
+      ['singlePage', 'SinglePage'],
+      ['oneColumn', 'OneColumn'],
+      ['twoColumnLeft', 'TwoColumnLeft'],
+      ['twoColumnRight', 'TwoColumnRight'],
+      ['twoPageLeft', 'TwoPageLeft'],
+      ['twoPageRight', 'TwoPageRight'],
+    ])('converts %s to %s', (input, expected) => {
+      const doc = new PDFDocument({ pageLayout: input });
+      expect(doc._root.data.PageLayout).toBe(expected);
+    });
+  });
 });