def attachment_extract(self, infile):
path_infile = self.dataDir + infile
# Open document
pdfDocument = Document(path_infile)
# Get embedded files collection
embeddedFiles = pdfDocument.EmbeddedFiles
# Get count of the embedded files
print ( "Total files : %d " % (embeddedFiles.Count))
count = 1
# Loop through the collection to get all the attachments
for fileSpecification in embeddedFiles:
print("Name: " + fileSpecification.Name)
print("Description: " + fileSpecification.Description)
print("Mime Type: " + fileSpecification.MIMEType)
# Check if parameter object contains the parameters
if (fileSpecification.Params != None):
print("CheckSum: " + fileSpecification.Params.CheckSum)
print("Creation Date: " + fileSpecification.Params.CreationDate)
print("Modification Date " + fileSpecification.Params.ModDate)
print("Size: " + fileSpecification.Params.Size)
# Get the attachment and write to file or stream
File.WriteAllBytes(self.dataDir + count + "_out" + ".txt", fileSpecification.Contents)
count+=1