My app creates MS Office Word 2007 documents from user provided data, which includes user submitted office/PDF documents.
Currently, I am able to embed documents into the Word 2007 document with the following C# code:
Code Snippet
if
( localAttachment.IsOffice2007Document )
{
openXmlPart = mainPart.AddEmbeddedPackagePart(localAttachment.MimeType);
}
else if (localAttachment.IsOffice1997_2003Document )
{
openXmlPart = mainPart.AddEmbeddedObjectPart(localAttachment.MimeType);
}
// Reads file from database to openXmlPart source stream
localAttachment.ReadContent(openXmlPart.GetStream());
After this code I insert the reference to openXmlPart into a node in the document.xml file to make it visible. This works great with all office docs (Word, Excel, PPT).
Now i need to insert PDF files in the same manner. I have tried reading the stream into both Object and Package Embedded Parts, with no luck. In the resulting office doc the OLE Object embedding is not in the embeddings folder.
I have seen this issue before, when trying to embed office documents using the wrong Embedded Part.
What do I need to do to properly embed the PDF document in the word file? I have also tried the other embedded parts (AlternateFormatImportPart and EmbededControlPersistencePart) and they do not work either.
Any ideas?