Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents. Get free and professional technical support for Spire.Presentation for .NET, Java, Android, C++, Python.

Wed Jul 14, 2021 10:10 am

Hi

Using Spire.Presentation Pro Edition we are updating presentation (pptx) files and then converting it to from pptx to pdf . We are inserting a few chart images in our presentation which are not clear when added to pptx as per the standard we need . Below is the code attached and the files generated . Would appreciate help on having clear images in our presentation files .

public void insertImage(string presentationFile)
{
Spire.Presentation.Presentation presentation = new Presentation();
presentation.LoadFromFile(presentationFile);

string strChartImagePath = "image path";

string ImageFile = "BBchart.png";
string strImagePath = strChartImagePath + @"\" + ImageFile;
Bitmap oImg = new Bitmap(strImagePath);
RectangleF recto = new RectangleF(70, 425, oImg.Width , oImg.Height );
IEmbedImage shape = presentation.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, strImagePath, recto);
shape.Line.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
shape.Line.SolidFillColor.Color = Color.FromArgb(107, 202, 186);


ImageFile = "PHPCchart.png";
strImagePath = strChartImagePath + @"\" + ImageFile;
oImg = new Bitmap(strImagePath);
RectangleF rect = new RectangleF(70, 200, oImg.Width, oImg.Height );
shape = presentation.Slides[1].Shapes.AppendEmbedImage(ShapeType.Rectangle, strImagePath, rect);
shape.Line.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
shape.Line.SolidFillColor.Color = Color.FromArgb(107, 202, 186);
oImg.Dispose(); oImg = null;

ImageFile = "PHPCGroupChart.png";
strImagePath = strChartImagePath + @"\" + ImageFile;
oImg = new Bitmap(strImagePath);
rect = new RectangleF(70, 475, oImg.Width, oImg.Height);
shape = presentation.Slides[1].Shapes.AppendEmbedImage(ShapeType.Rectangle, strImagePath, rect);
shape.Line.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
shape.Line.SolidFillColor.Color = Color.FromArgb(107, 202, 186);
oImg.Dispose(); oImg = null;

presentation.SaveToFile(presentationFile, FileFormat.Pptx2010);
}

public void PPTtoPDF(string srcFilePPT, string destinationFilePDF)
{

//create PPT document
Presentation presentation = new Presentation();

//load PPT file from disk
presentation.LoadFromFile(srcFilePPT);

//save the PPT do PDF file format
presentation.SaveToFile(destinationFilePDF, FileFormat.PDF);

System.Diagnostics.Process.Start(destinationFilePDF);


}

karendmello
 
Posts: 8
Joined: Mon Feb 08, 2021 1:33 pm

Thu Jul 15, 2021 10:00 am

Hello,

Thanks for your inquiry.
Kindly note the unit of picture is Pixel, while the unit in our Spire.Presentation is Point. In your case, you defined the rectangle size according to the picture size. Because of the different units, the rectangle size is actually larger than the real size of the picture, so the added picture is stretched in generated pptx. This causes the ambiguous images issue. To solve this problem, please refer to the following code to convert Pixel unit to Point.
Code: Select all
Bitmap oImg = new Bitmap(strImagePath);

//Convert unit
PdfUnitConvertor convertorUnit = new PdfUnitConvertor();
//Convert Pixel unit to Point
float widthInPoint = convertorUnit.ConvertUnits(oImg.Width, PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point);
float heightInPoint = convertorUnit.ConvertUnits(oImg.Height, PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point);

RectangleF recto = new RectangleF(70, 425, widthInPoint, heightInPoint);
IEmbedImage shape = presentation.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, strImagePath, recto);

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1648
Joined: Wed Apr 07, 2021 2:50 am

Fri Jul 30, 2021 9:34 am

Hello,

Hope you're doing well.
How is your issue going? Can you give us some feedback at your convenience? Thanks in advance.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1648
Joined: Wed Apr 07, 2021 2:50 am

Tue Aug 24, 2021 6:42 am

Hi

thank u for point this out , this solution worked for us

karendmello
 
Posts: 8
Joined: Mon Feb 08, 2021 1:33 pm

Tue Aug 24, 2021 11:01 am

Hi,

You're welcome.
If you have other questions about using Spire.Presentation in the future, please feel free to contact us.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1648
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.Presentation