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.

Mon Jul 22, 2024 9:02 am

Hello,

I want to resize an image in a word document, so i use the following code:

https://www.e-iceblue.com/Tutorials/Spi ... -in-C.html

But it's strange because the final image's size is not 50*50 !

The size of the final image maintains the initial image ratio,

Is there an option to force resizing?

vincentjam
 
Posts: 15
Joined: Tue Apr 13, 2021 10:08 am

Tue Jul 23, 2024 7:17 am

Hello,

Thank you for your inquiry.
Our current version (Spire.Doc Pack (hot fix) Version: 12.7.3) supports setting whether the aspect ratio of an image is locked. You can add "picture.AspectRatioLocked = false" and test it again. If there are still issues, please provide us with your document for further investigation. You can upload them here or send them to us via email (support@e-iceblue.com). Thank you in advance for your assistance.

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 231
Joined: Mon Jul 15, 2024 5:40 am

Tue Jul 23, 2024 8:48 am

With aspectratiolocked, i have the same problem. But maybe my code is not correct :

p = row.Cells[col].AddParagraph();
switch (col)
{
case 0:
{
string curFile = Rap.PathImage + Pth.Image;
if (File.Exists(curFile))
{
Image image = Image.FromFile(curFile);
DocPicture pic = p.AppendPicture(image);
pic.AspectRatioLocked = false;
pic.Width = 90;
pic.Height = 90;
}

break;
}

vincentjam
 
Posts: 15
Joined: Tue Apr 13, 2021 10:08 am

Tue Jul 23, 2024 10:07 am

Hello,

Thank you for your inquiry.
I did a preliminary test using the latest Version (spir.doc for. NET Version:12.7.3) and the following sample code, but it didn't reproduce the problem you mentioned. I have attached my tesing files for your reference, if only your testing file has the problem, please provide us with your original input file. You can upload it here or email it to us (support@e-iceblue.com). Thanks in advance.

Code: Select all
//Create a word document
 Document doc = new Document();
 //Load the file
 doc.LoadFromFile(@"in.docx");
 //Get the first secion
 Section section = doc.Sections[0];
 Spire.Doc.Table tb1 = section.Tables[0] as Spire.Doc.Table;
 //Get the first paragraph
 Paragraph paragraph = tb1[0, 0].Paragraphs[0];
 System.Drawing.Image image = System.Drawing.Image.FromFile(@"1.png");
 DocPicture pic = paragraph.AppendPicture(image);
 //Reset the image size of the first paragraph
 pic.AspectRatioLocked = true;
 pic.Width = 200f;
 pic.Height = 200f;
 //Save the document
 string output = @"output.docx";
 doc.SaveToFile(output, FileFormat.Docx);
 // Dispose the document
 doc.Dispose();


Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 231
Joined: Mon Jul 15, 2024 5:40 am

Tue Jul 23, 2024 11:27 am

Incredible, the same code doesn't work, i use Spire.doc v 12.7.3

A small video : https://www.edibatec.org/Download/Temp/BugSpire.wmv

vincentjam
 
Posts: 15
Joined: Tue Apr 13, 2021 10:08 am

Wed Jul 24, 2024 6:25 am

Hello,

Thank you for feedback.
In my previous code, "pic. AspectRatioLocked = true" means to lock the aspect ratio of the image. If you want to unlock the aspect ratio of the image, it should be set to "pic. AspectRatioLocked = false", you can try again. If your issue still occurs, provide us with your testing file.

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 231
Joined: Mon Jul 15, 2024 5:40 am

Wed Jul 24, 2024 7:47 am

Hello,

Ok but your sample code is wrong, if i want to have the same result AspectRatioLocked must be set to false

vincentjam
 
Posts: 15
Joined: Tue Apr 13, 2021 10:08 am

Wed Jul 24, 2024 10:01 am

Hello,

Thank you for your feedback.
We apologize for the inconvenience caused. If there is any other question, please feel free to contact us.

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 231
Joined: Mon Jul 15, 2024 5:40 am

Return to Spire.Doc

cron