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.

Thu Aug 06, 2020 10:40 am

Hi

Thanks for your inquiry.
Our Spire.Doc doesn't support inserting base64 data into Word directly. But you can save the base64 to image file, and then insert the image into Word using our Spire.Doc. Here is the code for your reference. If there is still any question, please feel free to write back.
Code: Select all
 
string[] str = base64Str.Split(',');
//convert base64 to image
byte[] imageBytes = Convert.FromBase64String(str[1]);
MemoryStream memoryStream = new MemoryStream(imageBytes, 0,imageBytes.Length);
memoryStream.Write(imageBytes, 0, imageBytes.Length);
Image image = Image.FromStream(memoryStream);
Document document = new Document();
//create a section
Section section = document.AddSection();
//create a paragraph
Paragraph paragraph = section.AddParagraph();
//append the image in document
paragraph.AppendPicture(image);
//save the document
document.SaveToFile("result.docx", FileFormat.Docx);


Sincerely,
Lynn
E-iceblue support team
User avatar

lynn.zhang
 
Posts: 57
Joined: Mon Jul 27, 2020 2:27 am

Thu Aug 06, 2020 12:52 pm

When getting OleObject then how to read the image in that oleObject .please suggest as soon as possible

babalipatil
 
Posts: 7
Joined: Tue Aug 04, 2020 11:15 am

Thu Aug 06, 2020 1:04 pm

DocOleObject docOle = dom as DocOleObject;
var GetType = docOle.ObjectType;
if (GetType == "ChemDraw.Document.6.0")
{
// how to convert ole object to image or bitmap
//how to get image data from oleobject

string base64 =Convert.ToBase64String(docOle.NativeData); // using this getting same native data for all images.
}

babalipatil
 
Posts: 7
Joined: Tue Aug 04, 2020 11:15 am

Fri Aug 07, 2020 3:02 am

Hi

Thanks for your inquiry.
Kindly note that our Spire.Doc follows specification of the Microsoft Word. I did some investigations but didn't find the "ChemDraw.Document.6.0" file could be directly inserted into Word as OLE object. How did you do that? Could you please send us your word sample that contains the ChemDraw.Document.6.0 object to help us do further investigation? You could attach your file here or send it to us via email ([email protected]). Thanks in advance.

Sincerely,
Lynn
E-iceblue support team
User avatar

lynn.zhang
 
Posts: 57
Joined: Mon Jul 27, 2020 2:27 am

Fri Aug 07, 2020 5:14 am

Attached word Doc ...

babalipatil
 
Posts: 7
Joined: Tue Aug 04, 2020 11:15 am

Fri Aug 07, 2020 9:42 am

Hi

Thanks for your inquiry.
You can refer to the following code to export ole objects in your document as images. If there is any question, please feel free to write back.
Code: Select all
  MY CODE:
            //Create document and load file from disk
            Document doc = new Document();
            doc.LoadFromFile(@"C:\Users\Test1\Desktop\chem.docx");

            int i = 0;
            //Traverse through all sections of the word document   
            foreach (Section sec in doc.Sections)
            {
                //Traverse through all tables
                foreach (Table table in sec.Tables)
                {
                    foreach (TableRow row in table.Rows)
                    {
                        foreach (TableCell cell in row.Cells)
                        {
                            foreach (DocumentObject obj in cell.ChildObjects)
                            {
                                //find the paragraph
                                if (obj is Paragraph)
                                {
                                    Paragraph par = obj as Paragraph;
                                    foreach (DocumentObject o in par.ChildObjects)
                                    {
                                        //check whether the object is OLE
                                        if (o.DocumentObjectType == DocumentObjectType.OleObject)
                                        {
                                            DocOleObject Ole = o as DocOleObject;
                                            string s = Ole.ObjectType;

                                            //check whether the object type is "ChemDraw.Document.6.0"
                                            if (s == "ChemDraw.Document.6.0")
                                            {
                                                //Save as image
                                                Image img = Ole.OlePicture.Image;
                                                img.Save("Result" + i + ".png");
                                                i++;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }



Sincerely,
Lynn
E-iceblue support team
User avatar

lynn.zhang
 
Posts: 57
Joined: Mon Jul 27, 2020 2:27 am

Fri Aug 07, 2020 10:03 am

Thank You...
But ole.OlePicture.Image // getting error because DocPicture does contain defination of Image

babalipatil
 
Posts: 7
Joined: Tue Aug 04, 2020 11:15 am

Mon Aug 10, 2020 11:19 am

Hi

Thanks for your feedback.
Please note the Ole is an object, it will be presented in word in the form of a picture. And our Spire.Doc will parse the Ole object in the following structure (see attached screenshot), in fact, the image of DocOleObject is pointing to the DocPicture, hence, they have the same image data. This is not an error, it is determined by the internal analysis mechanism of our Spire.Doc. Hope I make it clear. If there is any misunderstanding, please feel free to write back.

Sincerely,
Lynn
E-iceblue support team
User avatar

lynn.zhang
 
Posts: 57
Joined: Mon Jul 27, 2020 2:27 am

Return to Spire.PDF