Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenXML - PowerPoint - Picture Scale Height & Width

I am trying to either find or calculate the Scale Height & Width values using the OpenXML SDK of a Picture in a PowerPoint Presentation PPTX file.

I have got the image as a

Picture = DocumentFormat.OpenXml.Presentation.Picture

I have had a look in ShapeProperties and NonVisualPictureProperties but just cannot track down the values.

This is what I am trying to get programmatically when see inside PowerPoint

enter image description here

Would anyone be able to tell me where these values are hiding?

Thanks

like image 974
Trevor Daniel Avatar asked Oct 31 '22 21:10

Trevor Daniel


1 Answers

Check DocumentFormat.OpenXml.Drawing -> ShapeProperties.Transform2D.Extents. (Extent documentation). This is an absolute size, not a percent, in the wonderful OpenXML EMU (1 in = 914400 EMUs, 1 cm = 360000 EMU). As far as I can tell this is how you set image scale (absolute, not percent).

Use the OpenXML SDK tool to reflect code for an example: New speadsheet, insert image, save. Then in the openxml sdk->reflect code, ctrl+f "Transform2D" should get you what you need. For example:

using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Presentation;
using DocumentFormat.OpenXml;
using A = DocumentFormat.OpenXml.Drawing;
using P14 = DocumentFormat.OpenXml.Office2010.PowerPoint;
using P15 = DocumentFormat.OpenXml.Office2013.PowerPoint;
using A14 = DocumentFormat.OpenXml.Office2010.Drawing;
using Thm15 = DocumentFormat.OpenXml.Office2013.Theme;
using Ap = DocumentFormat.OpenXml.ExtendedProperties;
using Vt = DocumentFormat.OpenXml.VariantTypes;

// Generates content of slidePart1.
private void GenerateSlidePart1Content(SlidePart slidePart1)
{
    Slide slide1 = new Slide();
    slide1.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main");
    slide1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
    slide1.AddNamespaceDeclaration("p", "http://schemas.openxmlformats.org/presentationml/2006/main");

    CommonSlideData commonSlideData1 = new CommonSlideData();

    ShapeTree shapeTree1 = new ShapeTree();

    NonVisualGroupShapeProperties nonVisualGroupShapeProperties1 = new NonVisualGroupShapeProperties();
    NonVisualDrawingProperties nonVisualDrawingProperties1 = new NonVisualDrawingProperties(){ Id = (UInt32Value)1U, Name = "" };
    NonVisualGroupShapeDrawingProperties nonVisualGroupShapeDrawingProperties1 = new NonVisualGroupShapeDrawingProperties();
    ApplicationNonVisualDrawingProperties applicationNonVisualDrawingProperties1 = new ApplicationNonVisualDrawingProperties();

    nonVisualGroupShapeProperties1.Append(nonVisualDrawingProperties1);
    nonVisualGroupShapeProperties1.Append(nonVisualGroupShapeDrawingProperties1);
    nonVisualGroupShapeProperties1.Append(applicationNonVisualDrawingProperties1);

    GroupShapeProperties groupShapeProperties1 = new GroupShapeProperties();

    A.TransformGroup transformGroup1 = new A.TransformGroup();
    A.Offset offset1 = new A.Offset(){ X = 0L, Y = 0L };
    A.Extents extents1 = new A.Extents(){ Cx = 0L, Cy = 0L };
    A.ChildOffset childOffset1 = new A.ChildOffset(){ X = 0L, Y = 0L };
    A.ChildExtents childExtents1 = new A.ChildExtents(){ Cx = 0L, Cy = 0L };

    transformGroup1.Append(offset1);
    transformGroup1.Append(extents1);
    transformGroup1.Append(childOffset1);
    transformGroup1.Append(childExtents1);

    groupShapeProperties1.Append(transformGroup1);

    Picture picture1 = new Picture();

    NonVisualPictureProperties nonVisualPictureProperties1 = new NonVisualPictureProperties();
    NonVisualDrawingProperties nonVisualDrawingProperties2 = new NonVisualDrawingProperties(){ Id = (UInt32Value)4U, Name = "Picture 3" };

    NonVisualPictureDrawingProperties nonVisualPictureDrawingProperties1 = new NonVisualPictureDrawingProperties();
    A.PictureLocks pictureLocks1 = new A.PictureLocks(){ NoChangeAspect = true };

    nonVisualPictureDrawingProperties1.Append(pictureLocks1);
    ApplicationNonVisualDrawingProperties applicationNonVisualDrawingProperties2 = new ApplicationNonVisualDrawingProperties();

    nonVisualPictureProperties1.Append(nonVisualDrawingProperties2);
    nonVisualPictureProperties1.Append(nonVisualPictureDrawingProperties1);
    nonVisualPictureProperties1.Append(applicationNonVisualDrawingProperties2);

    BlipFill blipFill1 = new BlipFill();

    A.Blip blip1 = new A.Blip(){ Embed = "rId2" };

    A.BlipExtensionList blipExtensionList1 = new A.BlipExtensionList();

    A.BlipExtension blipExtension1 = new A.BlipExtension(){ Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}" };

    A14.UseLocalDpi useLocalDpi1 = new A14.UseLocalDpi(){ Val = false };
    useLocalDpi1.AddNamespaceDeclaration("a14", "http://schemas.microsoft.com/office/drawing/2010/main");

    blipExtension1.Append(useLocalDpi1);

    blipExtensionList1.Append(blipExtension1);

    blip1.Append(blipExtensionList1);

    A.Stretch stretch1 = new A.Stretch();
    A.FillRectangle fillRectangle1 = new A.FillRectangle();

    stretch1.Append(fillRectangle1);

    blipFill1.Append(blip1);
    blipFill1.Append(stretch1);

    ShapeProperties shapeProperties1 = new ShapeProperties();

    A.Transform2D transform2D1 = new A.Transform2D();
    A.Offset offset2 = new A.Offset(){ X = 1524000L, Y = 0L };
    A.Extents extents2 = new A.Extents(){ Cx = 9144000L, Cy = 6858000L };

    transform2D1.Append(offset2);
    transform2D1.Append(extents2);

    A.PresetGeometry presetGeometry1 = new A.PresetGeometry(){ Preset = A.ShapeTypeValues.Rectangle };
    A.AdjustValueList adjustValueList1 = new A.AdjustValueList();

    presetGeometry1.Append(adjustValueList1);

    shapeProperties1.Append(transform2D1);
    shapeProperties1.Append(presetGeometry1);

    picture1.Append(nonVisualPictureProperties1);
    picture1.Append(blipFill1);
    picture1.Append(shapeProperties1);

    shapeTree1.Append(nonVisualGroupShapeProperties1);
    shapeTree1.Append(groupShapeProperties1);
    shapeTree1.Append(picture1);

    CommonSlideDataExtensionList commonSlideDataExtensionList1 = new CommonSlideDataExtensionList();

    CommonSlideDataExtension commonSlideDataExtension1 = new CommonSlideDataExtension(){ Uri = "{BB962C8B-B14F-4D97-AF65-F5344CB8AC3E}" };

    P14.CreationId creationId1 = new P14.CreationId(){ Val = (UInt32Value)568547621U };
    creationId1.AddNamespaceDeclaration("p14", "http://schemas.microsoft.com/office/powerpoint/2010/main");

    commonSlideDataExtension1.Append(creationId1);

    commonSlideDataExtensionList1.Append(commonSlideDataExtension1);

    commonSlideData1.Append(shapeTree1);
    commonSlideData1.Append(commonSlideDataExtensionList1);

    ColorMapOverride colorMapOverride1 = new ColorMapOverride();
    A.MasterColorMapping masterColorMapping1 = new A.MasterColorMapping();

    colorMapOverride1.Append(masterColorMapping1);

    slide1.Append(commonSlideData1);
    slide1.Append(colorMapOverride1);

    slidePart1.Slide = slide1;
}
like image 94
BurnsBA Avatar answered Nov 15 '22 05:11

BurnsBA