I found questions about deleting all images, but can't find anything specific to what I need.
I'm making answer keys for a math course book. I have a Word document of the book, but don't want to update the answer key each time I update the course book (change order of questions / formatting / ...). I want to write all the answers in the course book directly, and then save as PDF both WITH and WITHOUT the answers.
For text I can do this (create new style --> write all answers with this style selected --> modify style colour to white if I don't want to print the answers). However, some questions have to be solved by drawing. I either can make these drawings again in Word, or I would insert an image (scan of the drawing on paper).
So, I need a way to mark certain images with some kind of tag. I thought maybe the Alt-Text could be useful, but I can't find a way to get the Alt-Text of images in a PDF with Python. But if there is any other kind of marker/tag that I can place on the images that can be read, that's fine too.
Then, I want to have 2 PDF documents: one without those specific images (student version), and one with those images (answer key). I don't mind if it is done in Word directly on the .docx file, or after the fact on the PDF file (preferably with Python)
EDIT: I have found a much better solution that does rely on the Alt-Text, which is with a VBA script. See below for details.
I have found a solution to my specific problem, but have to preface it by saying it is not about the Alt-Text of the PDF file.
Thanks to a Reddit post suggesting to ask ChatGPT, because the AI actually did give me an idea about using Text Boxes in Word, which I then adapted in the following way:
Setup
To toggle the images
[Keyword]
[Keyword]
into the Alt-Text of a Figure / Drawing / Text Box / ShapeSub Hide_Answer_Key()
For Each shp In ActiveDocument.Shapes
If shp.AlternativeText = "Keyword" Then
shp.Visible = msoFalse ' Makes the shape invisible '
End If
Next shp
End Sub
[Keyword]
are now hidden. To unhide them again, run a second script that's exactly the same except change msoFalse
to msoTrue
.Caveats:
Benefits: