-
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.
The method `.clone(pdf_dest,[force_duplicate])` clones the objects and all referenced objects. If an object is already cloned, the already cloned object is returned (unless force_duplicate is set) mainly for internal use but can be used on a page for pageObject/DictionnaryObject/[Encoded/Decoded/Content]Stream an extra parameter ignore_fields list that provide the list of fields that should not be cloned. When available, the pointer to an object is available in `indirect_obj` attribute. New API for add_page/insert_page that : * returns the cloned page object * ignore_fields can be provided as a parameter. ## Others * file is closed at the end of PdfWriter.write when a filename is provided * Breaking Change: `add_outline_item` now has a parameter before which is not the last parameter ## Update * The public API of PdfMerger has been added to PdfWriter (ready to make PdfMerger an alias of it) * Process properly Outline merging * Process properly Named destinated Deals with #1194, #1322, #471, #1337
- Loading branch information
Showing
13 changed files
with
1,695 additions
and
160 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -702,6 +702,7 @@ def add_outline_item( | |
title, | ||
page_number, | ||
parent, | ||
None, | ||
color, | ||
bold, | ||
italic, | ||
|
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,65 @@ | ||
"""Helpers for working with PDF types.""" | ||
|
||
from io import BufferedReader, BufferedWriter, BytesIO, FileIO | ||
from pathlib import Path | ||
from typing import Any, Dict, List, Optional, Tuple, Union | ||
|
||
try: | ||
# Python 3.8+: https://peps.python.org/pep-0586 | ||
from typing import Protocol # type: ignore[attr-defined] | ||
except ImportError: | ||
from typing_extensions import Protocol # type: ignore[misc] | ||
|
||
from ._utils import StrByteType | ||
|
||
|
||
class PdfObjectProtocol(Protocol): | ||
indirect_reference: Any | ||
|
||
def clone( | ||
self, | ||
pdf_dest: Any, | ||
force_duplicate: bool = False, | ||
ignore_fields: Union[Tuple[str, ...], List[str], None] = (), | ||
) -> Any: | ||
... | ||
|
||
def _reference_clone(self, clone: Any, pdf_dest: Any) -> Any: | ||
... | ||
|
||
def get_object(self) -> Optional["PdfObjectProtocol"]: | ||
... | ||
|
||
|
||
class PdfReaderProtocol(Protocol): # pragma: no cover | ||
@property | ||
def pdf_header(self) -> str: | ||
... | ||
|
||
@property | ||
def strict(self) -> bool: | ||
... | ||
|
||
@property | ||
def xref(self) -> Dict[int, Dict[int, Any]]: | ||
... | ||
|
||
@property | ||
def pages(self) -> List[Any]: | ||
... | ||
|
||
def get_object(self, indirect_reference: Any) -> Optional[PdfObjectProtocol]: | ||
... | ||
|
||
|
||
class PdfWriterProtocol(Protocol): # pragma: no cover | ||
_objects: List[Any] | ||
_id_translated: Dict[int, Dict[int, int]] | ||
|
||
def get_object(self, indirect_reference: Any) -> Optional[PdfObjectProtocol]: | ||
... | ||
|
||
def write( | ||
self, stream: Union[Path, StrByteType] | ||
) -> Tuple[bool, Union[FileIO, BytesIO, BufferedReader, BufferedWriter]]: | ||
... |
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
Oops, something went wrong.