title: Converting image file from attachment to Pdf file in python
body: <p>I am trying to convert images from the attachment of .msg file and save into PdF file. However i get the error when i tried to read the image file for converting into PdF file. Here is the part of my code </p>
  
  <pre><code>if count_attachments &gt; 0:
      for item in range(count_attachments):          
          attached = msg.Attachments.Item(item + 1)            
          extension = attached.filename.split(".")[-1]
  
          if extension == 'jpg' or extension == 'png':
              pp = PdfPages(newname)
              img_data = open(attached, 'rb').read()                
              pp.savefig(img_data)                
              pp.close()
  </code></pre>
  
  <p>Here is the error I got from the compiler</p>
  
  <pre><code>Traceback (most recent call last):
  File "email-reader1.py", line 52, in &lt;module&gt;
  img_data = open(attached, 'rb').read()
  TypeError: Can't convert 'CDispatch' object to str implicitly
  </code></pre>