Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Sep 05, 2016 2:27 pm

Hi
How can i extract pdf inside word document as OLEObject

dekel7kedem
 
Posts: 4
Joined: Mon Sep 05, 2016 12:49 pm

Tue Sep 06, 2016 3:01 am

Dear dekel7kedem,

Thanks for your inquiry.
Here is sample code for your reference:
Code: Select all
                Document doc = new Document();
                doc.LoadFromFile(@"F:\testing\doc form\original document\8481.docx");
                //traverse section           
                foreach (Section sec in doc.Sections)
                {
                    //traverse section's body and find the Ole object
                    foreach (DocumentObject obj in sec.Body.ChildObjects)
                    {
                        if (obj is Paragraph)
                        {
                            Paragraph par = obj as Paragraph;
                            foreach (DocumentObject o in par.ChildObjects)
                            {
                                if (o.DocumentObjectType == DocumentObjectType.OleObject)
                                {                             
                                    DocOleObject Ole = o as DocOleObject;                               
                                    //If the string contains "Acrobat Document"(Word2003 format) or "AcroExch", it means the Ole is PDF document
                                string s = Ole.ObjectType;
                                byte[] by = Ole.NativeData;
                                if (s.Contains("Acrobat Document") || s.Contains("AcroExch"))
                                {
                                    File.WriteAllBytes("8481.pdf",by);
                                }
                            }
                        }
                    }
                }

Hope this can help you. If there still is issue, please provide us your sample document for testing.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Return to Spire.PDF

cron