Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Fri Jan 25, 2019 11:11 am

hi,
i m trying to add photo in an existing table in word document, it s ok ,
but how can i add photo with borders ??? (maybe with borderStyle)
original photos dont have borders, i want spire.doc create borders for that image.

this is my working code(without adding borders):
Code: Select all
            imgPath="image.jpg";
            Document document = new Document();
            document.LoadFromFile( "input.docx", FileFormat.Docx2010);

            Table table = document.Sections[0].Tables[0] as Spire.Doc.Table;
            DocPicture picture = table.Rows[3].Cells[0].Paragraphs[0].AppendPicture(Image.FromFile(imgPath));
            picture.Width  = 60;
            picture.Height = 75;

kasimdmr
 
Posts: 6
Joined: Thu Mar 15, 2018 11:04 am

Mon Jan 28, 2019 6:46 am

Hi,

Sorry for late reply as weekend.
Sorry that our product doesn't support adding borders for image/photo at present. We have added the new feature and will let you know once there is any good news.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Mon Jan 28, 2019 7:18 am

i solved problem , before adding image, i draw rectangle to it...
but ofcourse it s better that spire.doc can handle this for us...


Code: Select all
   Image img = Image.FromFile(imageFilePath);     
            Graphics g = Graphics.FromImage(img);
            g.DrawRectangle(new Pen(Brushes.Black, 5), new Rectangle(0, 0, img.Width, img.Height));
         
            Table table = document.Sections[0].Tables[0] as Spire.Doc.Table;
            DocPicture picture = table.Rows[4].Cells[0].Paragraphs[0].AppendPicture(img);
            picture.Width = 60;
            picture.Height = 85; 

kasimdmr
 
Posts: 6
Joined: Thu Mar 15, 2018 11:04 am

Mon Jan 28, 2019 7:24 am

Hi,

Thanks for sharing your workaround.
We will let you know if the new feature is implemented.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Thu Feb 28, 2019 4:47 am

I have an existing template created through spire doc with some placeholders, which get replaced through C# code. I want to add an image in that template from C# code. I am facing a problem because if I give a placeholder for that image path, it shows the actual path but not image. Is there any way to add an image in the first column of the table in the template. Refer attachment.

aksh0614
 
Posts: 23
Joined: Mon Jul 02, 2018 3:53 am

Thu Feb 28, 2019 9:29 am

Hello Aksh,

Thanks for your post.
I simulated your scenario and tested with latest Spire.Doc Pack(hot fix) Version:7.2.4, images could be added successfully. Below is my testing code for your reference. If you were using an old version, I suggest you download the latest version to try again. If your issue still occurs and your testing code is different from mine, please share us with your existing template as well as your full code to help further look into it. You could send them to us via email (support@e-iceblue.com).
Code: Select all
 static void Main(string[] args)
 {
     Document doc = new Document();
     doc.LoadFromFile(@"sample.docx");
     //replace with image
     Image image = Image.FromFile(@"logo.png");
     ReplaceImage(doc, "{{{photo-1}}}", image);
     ReplaceImage(doc, "{{{photo}}}", image);
     doc.SaveToFile("result.docx", Spire.Doc.FileFormat.Docx2013);
 }
 private static void ReplaceImage(Document doc, string placeholder, Image image)
 {
     //Find placeholder
     TextSelection[] selections = doc.FindAllString(placeholder, false, true);
     //loop through the finds
     foreach (TextSelection selection in selections)
     {
         //Get the textrange of find
         TextRange tr = selection.GetAsOneRange();
         //Get the paragraph of textrange       
         Paragraph par = tr.OwnerParagraph as Paragraph;
         int index = par.GetIndex(tr);
         //Add a temporary paragraph
         Paragraph parTem = doc.Sections[0].AddParagraph();
         //Append picture
         DocPicture picture = parTem.AppendPicture(image);
         //Insert the picture
         par.ChildObjects.Insert(index, picture);
         //Remove the temporary paragraph
         doc.Sections[0].Body.ChildObjects.Remove(parTem);
         par.ChildObjects.Remove(tr);
     }
 }


Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Thu Feb 28, 2019 12:31 pm

Thank You!!
I will try this and let you know if worked.

aksh0614
 
Posts: 23
Joined: Mon Jul 02, 2018 3:53 am

Fri Mar 01, 2019 1:17 am

Hello Aksh,

Thanks for your quick responce. Hope everything goes well, I am looking forward to your testing result.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.Doc