Skip to main content

Posts

How to Extract Images from Word Documents with Python

Word files may contain screenshots, product photos, diagrams, logos, and other embedded images. When these images need to be reused separately, saving them one by one from Microsoft Word is inefficient, especially when a document contains dozens of pictures. This article shows how to extract images from Word documents with Python and save them as separate image files. Prerequisites Make sure Python is installed on your computer, then install the required package: pip install Spire.Doc Step 1: Load the Word Document in Python First, import the required modules and load the document with the LoadFromFile method: import queue from spire.doc import * from spire.doc.common import * doc = Document () doc . LoadFromFile ( " Sample.docx " ) The document is now available for traversing its internal objects. Step 2: Find Images in the Word Document Images in a Word document are represented as DocPicture objects. Because pictures may appear inside different document ob...

How to Attach Files to a PDF with Python

A PDF does not always have to contain everything directly on its pages. A project report, for example, may need the original Excel data used to generate its charts. An invoice may need supporting documents, while a technical report may need to include configuration files, logs, or other reference material. Instead of sending these files separately, they can be embedded directly in the PDF. There are two useful ways to do this. A file can be attached to the PDF as a whole, or it can be placed at a specific location on a page as an attachment annotation. This article shows how to handle both cases with Python. Document Attachments vs. Attachment Annotations Before adding a file, it helps to understand the difference between the two approaches. A document-level attachment belongs to the PDF itself. It does not appear in the visible page content. Users typically access it through the Attachments panel in a PDF reader. An attachment annotation , on the other hand, is placed on a particular...