Powerpoint needs to "repair" the file?
Hi Steve, this is an awesome library. I just started using it--apologies if my issue is simplistic or if I can find the answer elsewhere. I didn't see this in the docs or any previous issue--I am creating a pptx and serving it via Apache. I have the mimetype set to application/vnd.openxmlformats-officedocument.presentationml.presentation per one of your other issue comments. The file downloads fine from Chrome and FF, but when I open it, I get a "PowerPoint found a problem with content in the file...PowerPoint can attempt to repair the file. If you trust the source of this file, click Repair."
It's just a simple ppt with text and some images. Googling identifies a problem with "block / unblock" for Windows, but even after I unblock the file on Windows, PowerPoint still has an issue and wants to repair it (Mac and Windows 7 VM).
Have you seen this issue before? My Python code follows your examples. Thanks!
First step should probably be to narrow down when the corruption is occurring.
What happens when you generate the .pptx code locally, without sending it over HTTP?
Hi, I am having a similar issue not sure if I should open a new issue or not. I have found it to be dependent on the length of slides. Once I create more than 8 slides, I encounter the repair message on Mac (not sure about Windows). Here's the diff: http://pastebin.com/9UqYA9ms. Please let me know if there is anything else I can do to track it down. This library is awesome, thank you for your work on it!
If I save the pptx directly to disk without passing it through HTTP, I get the same error when I open it. So I assume that means my content itself is bad—are there guidelines for how I should format / clean that up? Would it help if I post some code or example content? I’m basically taking XML content, parsing it out with Beautiful Soup into chunks, and putting each text chunk (or image) into a slide.
Thanks!
El abr 16, 2014, a las 3:18 PM, scanny [email protected] escribió:
First step should probably be to narrow down when the corruption is occurring.
What happens when you generate the .pptx code locally, without sending it over HTTP?
— Reply to this email directly or view it on GitHub.
A could approaches might be helpful:
- If you can post the code you're using in a Gist, I might be able to notice something
- If you do a before and after diff using opc-diag you may be able to narrow down what the corruption is, that usually leads pretty quickly to the source.
Is your content raw XML or are you reading plain text or whatever from it? I'm not sure what happens with XML escaping is why I ask.
@jon85 nothing is jumping out at me from the diff, they all seem pretty innocuous. Can you post the code in a Gist or pastebin?
@jon85 one idea would be to just add eight slides without adding any content to them, that would rule out the diffs in app.xml and core.xml. The other idea I have is to just add the last slide, the one that pushes it over the edge, in case it turns out that's the trigger rather than the number of slides.
@jon85 the remaining diffs seem to fall into two categories:
- adding a
<p:xfrm>element (and children) to a group shape, I expect this is the shape tree for those slides. That's a difference it's probably worth me fixing. It shouldn't be a problem, and has never been before, but there's no good reason not to just pop this element in there when a new slide is created. - There is a uniform adjustment on the table size. This would probably indicate a difference in how the table size is calculated. That's worth looking into. I don't think it's causing this problem, but still worth figuring out what's happening there.
I don't think either of those help you, but will be things I'll want to look into related to this issue.
@scanny thanks for getting back so quick. I appreciate it! I'm trying to filter my code to track down the exact cause and it seems to be coming from the fact that I open an existing presentation and build slides from there in order to apply my company's theme (adds a border and a logo). If I just create a new presentation and add 10 slides with no content it works fine, but if I open the reference and then add 10 slides it causes the error.
Edit: I now see in my original presentation.xml, I have
<p:sldIdLst>
<p:sldId id="264" r:id="rId5"/>
</p:sldIdLst>
It looks like when it gets to the 9th slide, there is a duplicate id="264"
Whats the best way to handle this?
@scanny, thanks for the two suggestions, I'll play around with the tool and let you know. It'll take some digging since I have nothing to diff against to look for corruption--I am using a raw XML structure as input but creating strings from the content, before I pass it to python-pptx. I need to check and verify that it really is just strings going into the slides. My situation seems a bit different than @jon85 since I am not opening an existing presentation, rather I am creating one from scratch. I also managed to get one or two files without the error, but it is inconsistent...
@cjshawMIT What you do is compare the corrupted file against the same file after letting PowerPoint repair it. Then you can see what PowerPoint thought needed fixing.
There's some noise in the diff because it does things like update the document properties and so on, but usually it will yield to a few minutes study to point out a problem. Happy to look at the diff if you Gist it or whatever.
@cjshawMIT sorry didn't mean to take over your thread. It initially seemed the two were related. I definitely recommend using opc-diag to compare the generated file with the file generated after being repaired by PowerPoint if possible.
@jon85 Ooh, interesting. That would explain it.
It would appear the .add_slide() method isn't being diligent enough about ensuring the slideId is unique. Let me have a look.
Want to start a separate issue for this? I don't think it's related to @cjshawMIT's issue.
@jon85 ah, yes, the logic in pptx.oxml.presentation.CT_SlideIdList._next_id is not at all adequate. This one definitely needs a fix.
@jon85 , no worries, the two issues do seem very related!
@scanny , ahh, haha, smart! That makes much more sense; sorry, I'm a little dense. So the diff output is below. You're right, most of it seems like basic document properties, except for the last couple of items:
https://gist.github.com/cjshawMIT/3fa37d826bdabb1db13e
And my code is here:
https://gist.github.com/cjshawMIT/64b21fb7b23465148e7d
I've tried not including the images, just doing 1 slide, but still have the problem. Thanks for taking a look at this!
So I figured out what was wrong--I was using deepcopy to duplicate the slide templates. I'm using the slide templates multiple times in a loop, and I wasn't sure if there would be issues with referencing the same object multiple times. Apparently you do a great job of handling this already and deepcopy is not needed! It must be making an imperfect copy of the template somehow, or subtly changing something in the object so that it conflicts with the pptx spec. Taking out the deepcopy gives a good output file that PowerPoint accepts. --Thanks @scanny !!
@cjshawMIT The slide layout that's passed in when making a new slide is strictly used as a reference, so it's natural and not uncommon for one of them to be referenced by several slides. At the end of the slide layout object graph are the lxml objects that represent the actual XML in the .pptx file. I'm not at all sure what happens if you deepcopy those, but I'm sure it isn't pretty :)
and glad to hear you got it working :)
when i remove shape i got this error.