Word file Inline image adjustment

In Interop.word I can adjustment Inline image using below code.  Can you convert it in docio fileformat. I try this and it is not working.
Interop code:
                 //image adjustment Inline image
                    foreach (Range r4 in objParagraph.Range.Words)  //para.Range.Words
                    {
                        if (r4.InlineShapes.Count > 0)
                        {
                            foreach (InlineShape r5 in r4.InlineShapes)
                            {
                                if (r5.Height > 24)
                                {
                                    r5.ScaleHeight = (r5.ScaleHeight * 0.75F);
                                    r5.ScaleWidth = (r5.ScaleWidth * 0.75F);
                                    r5.Select();
                                    r5.Range.Font.Position = -(Convert.ToInt32(Math.Round(r5.Height * 0.5F) - Math.Round(r5.Height * 0.16F))); //-14;                                
                                }
                                else if (r5.Height > 15)
                                {
                                    r5.ScaleHeight = (r5.ScaleHeight * 0.9F);
                                    r5.ScaleWidth = (r5.ScaleWidth * 0.9F);
                                    r5.Select();
                                    r5.Range.Font.Position = -(Convert.ToInt32(Math.Round(r5.Height * 0.5F) - Math.Round(r5.Height * 0.4F))); //-14; 
                                }
                                else
                                {
                                    r5.Range.Font.Position = -3;
                                }
                            }
                        }
                    }

In Docio (not working): (Inline image)
                                                      //image position adjustment
                                                        if (picture.Height > 24)
                                                        {

                                                            picture.HeightScale = (picture.HeightScale * 0.75F);
                                                            picture.WidthScale = (picture.WidthScale * 0.75F);                                                            
                                                            //r5.Select();
                                                            picture.HorizontalPosition = -(Convert.ToInt32(Math.Round(picture.Height * 0.5F) - Math.Round(picture.Height * 0.16F))); //-14;                                
                                                        }
                                                        else if (picture.Height > 15)
                                                        {
                                                            picture.HeightScale = (picture.HeightScale * 0.9F);
                                                            picture.WidthScale = (picture.WidthScale * 0.9F);
                                                            //r5.Select();
                                                            //r5.Range.Font.Position = -(Convert.ToInt32(Math.Round(picture.Height * 0.5F) - Math.Round(picture.Height * 0.4F))); //-14; 
                                                            picture.HorizontalPosition = -(Convert.ToInt32(Math.Round(picture.Height * 0.5F) - Math.Round(picture.Height * 0.4F))); //-14; 

                                                        }
                                                        else
                                                        {
                                                            //r5.Range.Font.Position = -3;
                                                            picture.HorizontalPosition = -3;
                                                        }

In word file I can do this using shortcut "Ctrl+D" open the Font property setting  window. Image attact



17 Replies

MJ Mohanaselvam Jothi Syncfusion Team May 3, 2018 06:43 AM UTC

Hi Irshad,

Thank you for contacting Syncfusion support.

We will expose an API to set font properties for the picture in our 2018 Volume 2 release which is available on end of May, 2018. We suggest you kindly use that API to set the position of the picture to achieve your requirement.

Please refer the below code example which will be available in 2018 Volume 2 release to set position as per your requirement:
 
//Sets vertical position in the font properties of picture. 
picture.CharacterFormat.Position = -14; 
 


Please let us know if you have any other questions.

Regards,
Mohanaselvam J
 



IA Irshad Ahmed May 30, 2018 06:10 AM UTC

In Interop.word I can get the listNumber of a numbered list by below code

var listNumber = objParagraph.Range.ListFormat.ListString; 

In Docio How can I get the listNumber ?

Also in Interop.word I can go the Next Paragraph by below code

objParagraph.Range.Next(1).Text;

How can I do this in Docio ? 



MJ Mohanaselvam Jothi Syncfusion Team May 30, 2018 08:33 AM UTC

Hi Irshad,

Thank you for your update.

Regarding list number:
Currently Essential DocIO doesn’t provide support for retrieving list number from the list paragraph in the Word document. We have already logged this as a feature request in our database. We will let you know once this feature is implemented.

If your requirement is to convert Word document into Text file and need to preserve list number in that converted Text file means, we suggest you to perform Word document to Text file conversion using DocIO, which also preserves the list number text of list paragraph in the resultant Text file.
Please refer the below UG documentation to know more about Word document into Text file conversion using DocIO:
https://help.syncfusion.com/file-formats/docio/text

Otherwise, could you please provide us the details on your end requirement of accessing the list number from the list paragraph?. Thereby we will analyze for alternate feasible solution in line with your requirement and we will provide you the more details.

Regarding accessing text of next Paragraph:
To achieve your requirement, we suggest you to use NextSibling API of DocIO to access the next sibling item of the paragraph. The next item of paragraph might be another paragraph, table or Block content control in the Word document.
Please refer the below code example to get text from the next paragraph in the Word document using DocIO:
 
//Loads an existing Text document 
WordDocument document = new WordDocument("Template.docx", FormatType.Docx); 
 
//Gets the paragraph in the section.  
WParagraph paragraph = document.LastSection.Paragraphs[0]; 
//Gets next sibling item of paragraph. 
IEntity entity = paragraph.NextSibling; 
 
//Iterates to next item till get the next paragraph. 
while (entity != null && !(entity is WParagraph)) 
{ 
    //Accesses the next body item (should be either paragraph, table or Block content control) as IEntity 
    entity = entity.NextSibling != null ? entity.NextSibling : null; 
} 
 
//If current paragraph contains next sibling as paragraph, then gets text from that paragraph. 
string paragraphText = entity != null ? (entity as WParagraph).Text : null; 
 
//Saves and closes the Word document. 
document.Save("Sample.docx", FormatType.Docx); 
document.Close(); 


Please refer the below UG documentation link to know more about iterating into the Word document using DocIO:
Iterating through document elements
Iterating through table elements


Please let us know if you have any other questions.

Regards,
Mohanaselvam J
 
 



IA Irshad Ahmed June 1, 2018 03:10 AM UTC

You Said that "ESSENTIAL STUDIO 2018 Volume 2 release which is available on end of May, 2018". But it is not available yet



MJ Mohanaselvam Jothi Syncfusion Team June 1, 2018 12:48 PM UTC

Hi Irshad,

We regret for the inconvenience caused. Our Essential Studio 2018 Volume 2 release is expected to be available on 8th June 2018.

Regards,
Mohanaselvam J
 



IA Irshad Ahmed June 29, 2018 02:07 AM UTC

I am using latest fileformat version 16 volume 2 . In my asp.net web form site.

Register the license key in Application_Start method of Global.asax.cs

void Application_Start(object sender, EventArgs e)
{
	//Register Syncfusion license
	Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("My LICENSE KEY");
}
i have added the key. I am getting embed equation .why is that.


MJ Mohanaselvam Jothi Syncfusion Team June 29, 2018 08:48 AM UTC

Hi Irshad,

Thank you for your update.

From the given details, we suspect that the problem might be due to the contents in your input Word document and not related to license key. We need to investigate with your input Word document to analyze the reported problem at our end. So, could you please provide us the input Word document along with the complete code snippets which used at your end. Thereby, we will analyze further on the reported problem and provide you the appropriate solution at the earliest.

Note: If you have any confidential data in your Word document, please replace with some dummy data and provide us the same. We just need your document to recreate the problem you face.

Please let us know if you have any other questions.

Regards,
Mohanaselvam J
 



IA Irshad Ahmed July 18, 2018 07:54 AM UTC

In Docio How can I get the listNumber ?
Document is attached for detail 

Attachment: Example_doc_297210bb.rar


DB Dilli Babu Nandha Gopal Syncfusion Team July 20, 2018 03:39 PM UTC

Hi Irshad, 
 
Thank you for your patience. 
 
We have created a direct-trac incident for the reported query and you can follow up the query through the incident. The incident can be tracked from the following link. 
 
Regards, 
Dilli babu 



IA Irshad Ahmed July 24, 2018 10:34 AM UTC

file attached for detail. version 16.2.0.41


Attachment: question_syncfusion_77ca52cb.rar


DB Dilli Babu Nandha Gopal Syncfusion Team July 26, 2018 09:57 AM UTC

Hi Irshad,

Thank you for your update.

Yes, the mentioned WParagraph.Text property will display all the text of paragraph including the field codes. You can see this field code in Microsoft Word application by toggling the field (ALT+F9).

If your requirement is to get the text from WParagraph without field code, then kindly use below workaround method in your project.
  
        /// <summary>
        /// Gets the paragraph text by ignoring field codes.
        /// </summary>
        private string GetDisplayText(WParagraph paragraph)
        {
            
string text = string.Empty;
           
bool isFieldCode = false;
           
foreach(Entity child in paragraph.Items)
            {
               
if (child is WOleObject || child is WField)
                    isFieldCode =
true;
               
else if (isFieldCode && child is WFieldMark
                    && (child
as WFieldMark).Type == FieldMarkType.FieldSeparator)
                    isFieldCode =
false;
               
else if (!isFieldCode && child is WTextRange)
                    text += (child
as WTextRange).Text;
            }
           
return text;
        }
  

Note: The above method will not work when field extends to multiple paragraphs and same paragraph have multiple fields. You can also customize this method as per your requirement

Regarding WOleObject content:


We could not retrieve the above marked content, since this is an WOleObject not a text.

Please let us know if you have any questions.

 
Regards, 
Dilli babu. 



IA Irshad Ahmed August 7, 2018 10:54 AM UTC

Probelem in oleObject image Extraction (size is too big)
My code is 
 if (item.EntityType == EntityType.OleObject)
                    {
                        //break;
                        imageflag = true;
                        WOleObject oleObject = item as WOleObject;

                        //Extract the equation and save as picture
                        if (oleObject.ObjectType == "Equation.3")
                        {
                            WPicture pic = oleObject.OlePicture;
                            Bitmap bitmap = null;
                            Metafile metaFile = pic.Image as Metafile;
                            GraphicsUnit gUnit = GraphicsUnit.Display;
                            System.Drawing.Size size = System.Drawing.Size.Ceiling(metaFile.GetBounds(ref gUnit).Size);
                            bitmap = new Bitmap(size.Width, size.Height);//size.Width, size.Height)
                            using (Graphics g = Graphics.FromImage(bitmap))
                            {
                                // g.DrawImageUnscaled(metaFile, System.Drawing.Point.Empty);
                                g.DrawImageUnscaled(metaFile, System.Drawing.Point.Empty);
                                g.Dispose();
                            }
                            //Save the picture
                            if (Directory.Exists(Server.MapPath("~/Uploads/images/" + "DocNo-" + DocumentNo)))
                            {
                                bitmap.Save(Server.MapPath("~/Uploads/images/") + "DocNo-" + DocumentNo + "/" + "QuestionNo-" + questionNumber + "imgNo-" + images + "(" + Math.Round(pic.Height).ToString() + "x" + Math.Round(pic.Width).ToString() + ")" + ".PNG", ImageFormat.Png);
                                //string path = "***Uploads/images/" + "DocNo-" + DocumentNo + "/" + "QuestionNo-" + questionNumber + "imgNo-" + images + "(" + (size.Height).ToString() + "x" + size.Width.ToString() + ")" + ".Jpeg***"; //fs.Name;                                                        
                                //questionstat.Append(path);
                                images++;
                            }
                            else
                            {
                                Directory.CreateDirectory((Server.MapPath("~/Uploads/images/" + "DocNo-" + DocumentNo)));
                                bitmap.Save(Server.MapPath("~/Uploads/images/") + "DocNo-" + DocumentNo + "/" + "QuestionNo-" + questionNumber + "imgNo-" + images + "(" + Math.Round(pic.Height).ToString() + "x" + Math.Round(pic.Width).ToString() + ")" + ".PNG", ImageFormat.Png);
                                //string path = "***Uploads/images/" + "DocNo-" + DocumentNo + "/" + "QuestionNo-" + questionNumber + "imgNo-" + images + "(" + (size.Height).ToString() + "x" + size.Width.ToString() + ")" + ".Jpeg***"; //fs.Name;                                                        
                                //questionstat.Append(path);
                                images++;
                            }
                        }

                    }

Attachment: quest_2_math_a750231d.rar


DB Dilli Babu Nandha Gopal Syncfusion Team August 8, 2018 01:37 PM UTC

Hi Irshad, 
 
The image size depends on the size of the bitmap in which image is drawn. So, we request to set the bitmap size with respective OleObject picture’s size while creating bitmap instance which we have done in the following code example 
 
Code example 
WPicture pic = oleObject.OlePicture; 
Bitmap bitmap = new Bitmap((int)pic.Width + 50,(int)pic.Height + 50); 
 
Please let us know whether your requirement has been fulfilled or not. 
 
Regards, 
Dilli babu.


IA Irshad Ahmed November 14, 2018 10:08 AM UTC

In synfusion Docio I want to access private property or member. How can i do that for  "DocxProps"  and  LockAspectRatio: ((Syncfusion.DocIO.DLS.WPicture)(item)).LockAspectRatio

if (item.EntityType == EntityType.Picture)
(((Syncfusion.DocIO.DLS.WPicture)(item)).DocxProps).Count; 


DB Dilli Babu Nandha Gopal Syncfusion Team November 14, 2018 12:31 PM UTC

Hi Irshad, 

Thank you for your update. 

Kindly share us your requirement/scenario in which DocxProps and LockAspectRatio members are required. This information will be helpful for us to analyze the feasibility to expose these members as public or provide you the better possible solution

Regards, 
Dilli babu. 



IA Irshad Ahmed December 3, 2018 10:31 AM UTC

Interop.word I can check and get TransparencyColor. In order to avoid duplicate images
if (r5.PictureFormat.TransparencyColor == -2147483648) //if no TransparencyColor then duplicate image 

How i do it in Docio.

Note:Some time I get duplicate images  while reading word document  oleObject and picture,  which i need to filter . I need these  DocxProps and LockAspectRatio method to identitfy then.
if(DocxProps.count >0 and LockAspectRatio==true)
then it is normal image


Attachment: duplicate_img_8de47598.zip


DB Dilli Babu Nandha Gopal Syncfusion Team December 5, 2018 05:44 PM UTC

Hi Irshad, 

Thank you for your update. 

Based on your end requirement(as per if condition clause in your last update), we have prepared a sample application to get the normal images in the Word document by excluding the duplicate images. Please find the sample from the below link: 

Note: Please find the input in the “Data” folder of above sample, which contains Word document with OLE object (duplicate image) and normal images. 

In this sample we have done the following things: 
1. Loads an existing Word document. 
2. Iterated the document elements. 
3. Exclude the images of OLE Object and get the normal images. 

Please let us know if the sample fulfills your requirement. 

Regards, 
Dilli babu. 


Loader.
Up arrow icon