We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Attachments (Excel - Word - PDF - Image )

Hello,

The problem we have is that when you attach certain files ,
such as Word or Excel lose size . Attach files to Excel spreadsheet contains a specific image that can be of different sizes,
in some cases print correctly in the final report, but in some cases when the image is of a small size it widens losing the original size.

1. Resultado_Actual.docx ( as currently printed. ) 2. Code ( Script used to attach and assign properties to attachments)
3. 001.xlsx (Excel files attached to our reports that are generated with the wrong size in the final report)



How can we solve this problem

Regards.

Hi Rodrigo,

Looks like some part of the code is missing. Can you please share a standalone console application to reproduce the issue and a document to show your expected output? Sorry for the inconvenience.

Best Regards,

#222222;mso-ansi-language:
EN” lang=“EN”>1.<span style=“font:7.0pt “Times New Roman””> Hello, Attached as requested.
<span style=“mso-fareast-font-family:“Courier New”;color:#222222;mso-ansi-language:
EN” lang=“EN”>2.<span style=“font:7.0pt “Times New Roman””>
<span style=“font-size:12.0pt;font-family:“Times New Roman”,serif;color:#222222;
mso-ansi-language:EN” lang=“EN”>Regards .
<!–[if gte mso 10]> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Tabla normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman",serif;}

<![endif]–>

Hi Rodrigo,

Sorry, the document in your application goes through several methods and it was not very helpful in understanding the issue.

To be more precise, can you please share a document to show your expected output? This will help us understand your requirement.

Best Regards,

Hello,

The process is as follows :

We need to print certain number of files that a single final document. So what we do is upload documents (Attach ) , these files can be Word , Excel or PDF .

In some cases users up excel containing images which when processed in some cases prints correctly but in some cases printed with some distortion in the final document .

We attach the following files:

1. Resultado_Actual.docx : shows how out as distorted in size and width.

2. Resultado_esperado.docx : as we need to display.

3. Attachments to excel . ( Example1 , example2 , example3)

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Tabla normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman",serif;}

<![endif]–>

Hi Rodrigo,

Sorry, It is difficult to reproduce the issue using your application as document goes through several methods and it is not very clear which section is being used as current section.

I have extracted following part of code from your application which converts Excel files into images and then inserts those images in Word document and I get attached output at my end which looks correct.

string[] excelFiles = new string[] { "ejemplo1.xlsx", "ejemplo2.xlsx", "ejemplo3.xlsx" };

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

<?xml:namespace prefix = "o" ns = "urn:schemas-microsoft-com:office:office" />

builder.Font.Name = "Arial Narrow";

builder.Font.Size = 9.5;

foreach (string excelFile in excelFiles)

{

Workbook book = new Workbook(excelFile);

Worksheet sheet = book.Worksheets[0];

if (sheet.PageSetup.Orientation.ToString() == "Portrait")

{

Section section = builder.CurrentSection;

section.PageSetup.Orientation = Aspose.Words.Orientation.Portrait;

}

else

{

Section section = builder.CurrentSection;

section.PageSetup.Orientation = Aspose.Words.Orientation.Landscape;

}

Aspose.Words.PageSetup pageSetup = builder.PageSetup;

Double AltoTabla = pageSetup.PageHeight - pageSetup.TopMargin - pageSetup.BottomMargin + 50;

Double TamanoPagina = pageSetup.PageWidth - pageSetup.LeftMargin - pageSetup.RightMargin + 150;

ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();

imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;

imgOptions.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

imgOptions.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

imgOptions.OnlyArea = true;

imgOptions.IsCellAutoFit = true;

imgOptions.Quality = 100;

imgOptions.VerticalResolution = 300;

imgOptions.HorizontalResolution = 300;

SheetRender sr = new SheetRender(sheet, imgOptions);

System.Drawing.Bitmap bitmap = sr.ToImage(0);

System.Drawing.Size s = bitmap.Size;

//bitmap.Save(excelFile + ".png");

if (s.Width < TamanoPagina) { TamanoPagina = s.Width; }

if (s.Height < AltoTabla) { AltoTabla = s.Height; }

builder.InsertOleObject("Adjunto", true, true, bitmap.GetThumbnailImage(Convert.ToInt32(TamanoPagina), Convert.ToInt32(AltoTabla), null, IntPtr.Zero));

builder.InsertBreak(Aspose.Words.BreakType.SectionBreakNewPage);

}

doc.Save("Result.docx");

Can you please share a simple code example to reproduce the issue without using much methods?

Best Regards,

Hello Muhammad ,

As you mentioned, it seems, there is nothing wrong with the code that performs the conversion exceli in image files.

Then for you to understand , we provide the following examples to help us find the problem

1. excels files containing the images to be printed in the final document.

2. resultado_Actual.docx Word file you can view the way it is printing.
You can validate that converts it to a size that does not correspond to the original image.
It is distorted in the final document.

3. Resultado_esperado.docx file is the way we hope we can print.

Already in a previous post we’ve shared the code we use and it is the segment that you mentioned which is responsible for the conversion,
which we believe is failing somewhere that is not printing the right way

Regards!

Hi Rodrigo,

Thanks for sharing these samples and details. We are further investigating it and will update you soon.

Best Regards,

Hi Rodrigo,

In fact the following line is affecting your images because actual width and height of the images is lot more than the specified in this line.

builder.InsertOleObject("Adjunto", true, true, bitmap.GetThumbnailImage(Convert.ToInt32(TamanoPagina), Convert.ToInt32(AltoTabla), null, IntPtr.Zero));<?xml:namespace prefix = "o" ns = "urn:schemas-microsoft-com:office:office" />

You can replace this line with the following code to see your desired result e.g.

Aspose.Words.Drawing.Shape shape = builder.InsertOleObject(“Adjunto”, true,
true, bitmap);

shape.Width
= shape.Width * 1.5;

shape.Height = shape.Height * 1.5;

Also, it would be better to use Landscape orientation as the images are too big to fit in Portrait orientation.

Aspose.Words.PageSetup pageSetup = builder.PageSetup;

builder.PageSetup.PaperSize
= PaperSize.Legal;

pageSetup.Orientation = Orientation.Landscape;<o:p></o:p>

Best Regards,

This issue has been solved .

Thank you so much