Parameters ---------- filename : str or path-like or file-like Output target; if a string, a file will be opened for writing. metadata : dict from strings to strings and dates Information dictionary object (see PDF reference section 10.2.1
(self, filename, metadata=None)
| 624 | """PDF file object.""" |
| 625 | |
| 626 | def __init__(self, filename, metadata=None): |
| 627 | """ |
| 628 | Parameters |
| 629 | ---------- |
| 630 | filename : str or path-like or file-like |
| 631 | Output target; if a string, a file will be opened for writing. |
| 632 | |
| 633 | metadata : dict from strings to strings and dates |
| 634 | Information dictionary object (see PDF reference section 10.2.1 |
| 635 | 'Document Information Dictionary'), e.g.: |
| 636 | ``{'Creator': 'My software', 'Author': 'Me', 'Title': 'Awesome'}``. |
| 637 | |
| 638 | The standard keys are 'Title', 'Author', 'Subject', 'Keywords', |
| 639 | 'Creator', 'Producer', 'CreationDate', 'ModDate', and |
| 640 | 'Trapped'. Values have been predefined for 'Creator', 'Producer' |
| 641 | and 'CreationDate'. They can be removed by setting them to `None`. |
| 642 | """ |
| 643 | super().__init__() |
| 644 | |
| 645 | self._object_seq = itertools.count(1) # consumed by reserveObject |
| 646 | self.xrefTable = [[0, 65535, 'the zero object']] |
| 647 | self.passed_in_file_object = False |
| 648 | self.original_file_like = None |
| 649 | self.tell_base = 0 |
| 650 | fh, opened = cbook.to_filehandle(filename, "wb", return_opened=True) |
| 651 | if not opened: |
| 652 | try: |
| 653 | self.tell_base = filename.tell() |
| 654 | except OSError: |
| 655 | fh = BytesIO() |
| 656 | self.original_file_like = filename |
| 657 | else: |
| 658 | fh = filename |
| 659 | self.passed_in_file_object = True |
| 660 | |
| 661 | self.fh = fh |
| 662 | self.currentstream = None # stream object to write to, if any |
| 663 | fh.write(b"%PDF-1.4\n") # 1.4 is the first version to have alpha |
| 664 | # Output some eight-bit chars as a comment so various utilities |
| 665 | # recognize the file as binary by looking at the first few |
| 666 | # lines (see note in section 3.4.1 of the PDF reference). |
| 667 | fh.write(b"%\254\334 \253\272\n") |
| 668 | |
| 669 | self.rootObject = self.reserveObject('root') |
| 670 | self.pagesObject = self.reserveObject('pages') |
| 671 | self.pageList = [] |
| 672 | self.fontObject = self.reserveObject('fonts') |
| 673 | self._extGStateObject = self.reserveObject('extended graphics states') |
| 674 | self.hatchObject = self.reserveObject('tiling patterns') |
| 675 | self.gouraudObject = self.reserveObject('Gouraud triangles') |
| 676 | self.XObjectObject = self.reserveObject('external objects') |
| 677 | self.resourceObject = self.reserveObject('resources') |
| 678 | |
| 679 | root = {'Type': Name('Catalog'), |
| 680 | 'Pages': self.pagesObject} |
| 681 | self.writeObject(self.rootObject, root) |
| 682 | |
| 683 | self.infoDict = _create_pdf_info_dict('pdf', metadata or {}) |
nothing calls this directly
no test coverage detected