Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions pypdf/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,21 +374,20 @@ def addAttachment(self, fname, fdata):
endobj

"""
embeddedFilesNamesDictionary = DictionaryObject()
embeddedFilesNamesDictionary.update({
NameObject("/Names"): ArrayObject(
[createStringObject(fname), filespec]
)
})
embeddedFilesDictionary = self._rootObject.setdefault(
NameObject("/Names"),
DictionaryObject())

embeddedFilesDictionary = DictionaryObject()
embeddedFilesDictionary.update({
NameObject("/EmbeddedFiles"): embeddedFilesNamesDictionary
})
# Update the root
self._rootObject.update({
NameObject("/Names"): embeddedFilesDictionary
})
embeddedFilesNamesDictionary = embeddedFilesDictionary.setdefault(
NameObject("/EmbeddedFiles"),
DictionaryObject())

embeddedFilesList = embeddedFilesNamesDictionary.setdefault(
NameObject("/Names"),
ArrayObject())

embeddedFilesList.append(createStringObject(fname))
embeddedFilesList.append(filespec)

def appendPagesFromReader(self, reader, afterPageAppend=None):
"""
Expand Down Expand Up @@ -1007,6 +1006,15 @@ def removeText(self, ignoreByteStringObject=False):

pageRef.__setitem__(NameObject('/Contents'), content)

def removeAttachments(self):
"""
removes attachments from this output.

"""
embeddedFilesDictionary = self._rootObject.get("/Names", {})
embeddedFilesDictionary.update({
NameObject("/EmbeddedFiles"): DictionaryObject()})

def addURI(self, pagenum, uri, rect, border=None):
"""
Add an URI from a rectangular area to the specified page. This uses the
Expand Down Expand Up @@ -2682,7 +2690,7 @@ def getAttachFiles(self):
:rtype: list
"""
res = []
catalog = self.trailer['/Root']
catalog = self._trailer['/Root']
# get the name tree
catalog_name = self._get_dict_entry(catalog, '/Names')
if not catalog_name:
Expand Down