-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAINT: Rename PdfWriter.create_viewer_preferences to PdfWriter.create…
- Loading branch information
1 parent
02f2aa6
commit b899d3d
Showing
6 changed files
with
86 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Adding Viewer Preferences | ||
|
||
It is possible to set viewer preferences of the PDF file. | ||
These properties are described in Section 12.2 of the [PDF 1.7 specification](https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf). | ||
|
||
Note that the `\ViewerPreferences` dictionary does not exist by default. | ||
If it's not already present, it must be created by calling the `create_viewer_preferences` method | ||
of the `PdfWriter` object. | ||
|
||
If viewer preferences exist in a PDF file being read with `PdfReader`, | ||
you can access them as properties of the `viewer_preferences` properties. | ||
Otherwise, the `viewer_preferences` property will be set to `None`. | ||
|
||
## Example | ||
|
||
```python | ||
from pypdf import PdfWriter | ||
from pypdf.generic import ArrayObject, NumberObject | ||
|
||
writer = PdfWriter() | ||
|
||
writer.create_viewer_preferences() | ||
|
||
# /HideToolbar | ||
writer.viewer_preferences.hide_toolbar = True | ||
# /HideMenubar | ||
writer.viewer_preferences.hide_menubar = True | ||
# /HideWindowUI | ||
writer.viewer_preferences.hide_windowui = True | ||
# /FitWindow | ||
writer.viewer_preferences.fit_window = True | ||
# /CenterWindow | ||
writer.viewer_preferences.center_window = True | ||
# /DisplayDocTitle | ||
writer.viewer_preferences.display_doctitle = True | ||
|
||
# /NonFullScreenPageMode | ||
writer.viewer_preferences.non_fullscreen_pagemode = "/UseNone" # default | ||
writer.viewer_preferences.non_fullscreen_pagemode = "/UseOutlines" | ||
writer.viewer_preferences.non_fullscreen_pagemode = "/UseThumbs" | ||
writer.viewer_preferences.non_fullscreen_pagemode = "/UseOC" | ||
|
||
# /Direction | ||
writer.viewer_preferences.direction = "/L2R" # default, | ||
writer.viewer_preferences.direction = "/R2L" | ||
|
||
# /ViewArea | ||
writer.viewer_preferences.view_area = "/CropBox" | ||
# /ViewClip | ||
writer.viewer_preferences.view_clip = "/CropBox" | ||
# /PrintArea | ||
writer.viewer_preferences.print_area = "/CropBox" | ||
# /PrintClip | ||
writer.viewer_preferences.print_clip = "/CropBox" | ||
|
||
# /PrintScaling | ||
writer.viewer_preferences.print_scaling = "/None" | ||
writer.viewer_preferences.print_scaling = "/AppDefault" # default according to PDF spec | ||
|
||
# /Duplex | ||
writer.viewer_preferences.duplex = "/Simplex" | ||
writer.viewer_preferences.duplex = "/DuplexFlipShortEdge" | ||
writer.viewer_preferences.duplex = "/DuplexFlipLongEdge" | ||
|
||
# /PickTrayByPDFSize | ||
writer.viewer_preferences.pick_tray_by_pdfsize = True | ||
# /PrintPageRange | ||
writer.viewer_preferences.print_pagerange = ArrayObject( | ||
[NumberObject("1"), NumberObject("10"), NumberObject("20"), NumberObject("30")] | ||
) | ||
# /NumCopies | ||
writer.viewer_preferences.num_copies = 2 | ||
|
||
for i in range(40): | ||
writer.add_blank_page(10, 10) | ||
|
||
with open("output.pdf", "wb") as output_stream: | ||
writer.write(output_stream) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters