When I try and pull a PDF out of a Word doc to an external file it extracts fine, but when I try and open the PDF I get an error message (There was an error opening this document. The file is damaged and could not be repaired.) When I double-click on the embedded PDF from the Word doc itself it works fine. Any ideas?
One extra note: the embedded objects are displayed as icons in the word doc, but for the pdf file the icon is blank (just white). Could this be a contributing factor?
Hello!
Thank you for you interest in Aspose products.
Are you trying to save a PDF stored in a DOC file separately? Please attach here the DOC file and the code snippet you are using to extract the PDF.
Regards,
Upon further investigation this issue is not solely with embedded PDFs. Some Word docs I extract embedded objects from works perfectly, some do not. Attached is a word doc with an embedded XLS files. The XLS file, when extracted, will not open. However, when I (recursively) use Aspose.Cells to extract the embedded objects from this file, they extract perfectly. Here is my code:
Dim doc As Aspose.Words.Document = New Aspose.Words.Document(fullpath)
Dim nodes As Aspose.Words.NodeCollection = doc.GetChildNodes(NodeType.Shape, True)
Dim shape As Aspose.Words.Drawing.Shape
Dim i As Integer = 1
For Each shape In nodes
If Not shape.OleFormat Is Nothing Then
Dim progID As String = shape.OleFormat.ProgId
Dim extension As String = ""
Select Case progID
Case "AcroExch.Document.7"
extension = ".pdf"
Case "Excel.Sheet.8"
extension = ".xls"
Case "PowerPoint.Show.8"
extension = ".ppt"
Case "Word.Document.8"
extension = ".doc"
Case "Package"
extension = ""
Case Else
extension = ""
End Select
If progID <> "Word.Picture.8" Then
filename = dir & pname & "" & "Embedded File " & counter.ToString.PadLeft(4, "0") & extension
Try
MkDir(dir & pname & "")
Catch
End Try
partname = "Embedded File " & counter.ToString.PadLeft(4, "0")
Dim s As System.IO.Stream
s = New System.IO.FileStream(filename, System.IO.FileMode.Create)
shape.OleFormat.Save(s)
s.Close()
counter += 1
End If
End If
i += 1
Next
Hi
Thank you for your reporting this problem to us. I managed to reproduce this problem on my side. I created new issue #4838 in our defect database. We will notify you as soon as it is fixed.
Best regards.