/// <summary> /// Sets a background picture for a table cell (a:tc). /// </summary> /// <remarks> /// <![CDATA[ /// <a:tc> /// <a:txBody> /// <a:bodyPr/> /// <a:lstStyle/> /// <a:p> /// <a:endParaRPr lang="fr-FR" dirty="0"/> /// </a:p> /// </a:txBody> /// <a:tcPr> (TableCellProperties) /// <a:blipFill dpi="0" rotWithShape="1"> /// <a:blip r:embed="rId2"/> /// <a:srcRect/> /// <a:stretch> /// <a:fillRect b="12000" r="90000" t="14000"/> /// </a:stretch> /// </a:blipFill> /// </a:tcPr> /// </a:tc> /// ]]> /// </remarks> private static void SetTableCellPropertiesWithBackgroundPicture(PptxSlide slide, A.TableCellProperties tcPr, Cell.BackgroundPicture backgroundPicture) { if (backgroundPicture.Content == null) { return; } ImagePart imagePart = slide.AddPicture(backgroundPicture.Content, backgroundPicture.ContentType); A.BlipFill blipFill = new A.BlipFill(); A.Blip blip = new A.Blip() { Embed = slide.GetIdOfImagePart(imagePart) }; A.SourceRectangle srcRect = new A.SourceRectangle(); A.Stretch stretch = new A.Stretch(); A.FillRectangle fillRect = new A.FillRectangle() { Top = backgroundPicture.Top, Right = backgroundPicture.Right, Bottom = backgroundPicture.Bottom, Left = backgroundPicture.Left }; stretch.AppendChild(fillRect); blipFill.AppendChild(blip); blipFill.AppendChild(srcRect); blipFill.AppendChild(stretch); tcPr.AppendChild(blipFill); }
private ODW.Inline CreateInlineDrawing_v2() { // DW.Inline.EditId : ??? (<wp:inline wp14:editId="">) //if (_name == null) // throw new PBException("missing image name"); //if (width != null && height == null) // throw new PBException("missing height (width has a value)"); //if (width == null && height != null) // throw new PBException("missing width (height has a value)"); // <wp:inline> ODW.Inline inline = new ODW.Inline() { DistanceFromTop = 0, // distT DistanceFromBottom = 0, // distB DistanceFromLeft = 0, // distL DistanceFromRight = 0 // distR //EditId = "50D07946" // wp14:editId }; // <wp:extent> inline.AppendChild(new ODW.Extent() { Cx = _emuWidth, Cy = _emuHeight }); // <wp:effectExtent> inline.AppendChild(new ODW.EffectExtent() { LeftEdge = 0L, TopEdge = 0L, RightEdge = 0L, BottomEdge = 0L }); // <wp:docPr> // Id = (UInt32Value)1U, Name = "Picture 1" inline.AppendChild(new ODW.DocProperties() { Id = _id, Name = _name, Description = _pictureElement.Description }); // <wp:cNvGraphicFramePr>, <a:graphicFrameLocks> { NoChangeAspect = true } inline.AppendChild(new ODW.NonVisualGraphicFrameDrawingProperties(new OA.GraphicFrameLocks())); // <a:graphic> OA.Graphic graphic = new OA.Graphic(); // <a:graphicData> OA.GraphicData graphicData = new OA.GraphicData() { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" }; // <pic:pic> ODP.Picture picture = new ODP.Picture(); // <pic:nvPicPr> ODP.NonVisualPictureProperties pictureProperties = new ODP.NonVisualPictureProperties(); // <pic:cNvPr> pictureProperties.AppendChild(new ODP.NonVisualDrawingProperties() { Id = (UInt32Value)0U, Name = "Image" }); // <pic:cNvPicPr> pictureProperties.AppendChild(new ODP.NonVisualPictureDrawingProperties()); picture.AppendChild(pictureProperties); // <pic:blipFill> ODP.BlipFill blipFill = new ODP.BlipFill(); // <a:blip> // CompressionState = A.BlipCompressionValues.Print OA.Blip blip = new OA.Blip() { Embed = _embeddedReference, CompressionState = _pictureElement.CompressionState }; // $$pb todo comment // <a:extLst> OA.BlipExtensionList blipExtensions = new OA.BlipExtensionList(); // <a:ext> blipExtensions.AppendChild(new OA.BlipExtension() { Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}" }); blip.AppendChild(blipExtensions); // $$pb todo comment end blipFill.AppendChild(blip); // <a:stretch> OA.Stretch stretch = new OA.Stretch(); // <a:fillRect> stretch.AppendChild(new OA.FillRectangle()); blipFill.AppendChild(stretch); picture.AppendChild(blipFill); // <pic:spPr> ODP.ShapeProperties shapeProperties = new ODP.ShapeProperties(); // <a:xfrm> OA.Transform2D transform2D = new OA.Transform2D(); // new A.Offset // <a:off> transform2D.AppendChild(new OA.Offset() { X = 0L, Y = 0L }); // <a:ext> transform2D.AppendChild(new OA.Extents() { Cx = _emuWidth, Cy = _emuHeight }); shapeProperties.AppendChild(transform2D); // <a:prstGeom> // Preset = A.ShapeTypeValues.Rectangle OA.PresetGeometry presetGeometry = new OA.PresetGeometry() { Preset = _pictureElement.PresetShape }; // <a:avLst> presetGeometry.AppendChild(new OA.AdjustValueList()); shapeProperties.AppendChild(presetGeometry); picture.AppendChild(shapeProperties); graphicData.AppendChild(picture); graphic.AppendChild(graphicData); inline.AppendChild(graphic); return inline; }
private ODW.Inline CreateInlineDrawing_v2() { int width; int height; zimg.CalculateImageWidthHeight(_pictureElement.File, _pictureElement.Width, _pictureElement.Height, out width, out height); long emuWidth = OXmlTools.PixelToEmus(width); long emuHeight = OXmlTools.PixelToEmus(height); // DW.Inline.EditId : ??? (<wp:inline wp14:editId="">) //if (_name == null) // throw new PBException("missing image name"); //if (width != null && height == null) // throw new PBException("missing height (width has a value)"); //if (width == null && height != null) // throw new PBException("missing width (height has a value)"); // <wp:inline> ODW.Inline inline = new ODW.Inline() { DistanceFromTop = 0, // distT DistanceFromBottom = 0, // distB DistanceFromLeft = 0, // distL DistanceFromRight = 0 // distR //EditId = "50D07946" // wp14:editId }; // <wp:extent> inline.AppendChild(new ODW.Extent() { Cx = emuWidth, Cy = emuHeight }); // <wp:effectExtent> inline.AppendChild(new ODW.EffectExtent() { LeftEdge = 0L, TopEdge = 0L, RightEdge = 0L, BottomEdge = 0L }); // <wp:docPr> // Id = (UInt32Value)1U, Name = "Picture 1" inline.AppendChild(new ODW.DocProperties() { Id = _id, Name = _name, Description = _pictureElement.Description }); // <wp:cNvGraphicFramePr>, <a:graphicFrameLocks> { NoChangeAspect = true } inline.AppendChild(new ODW.NonVisualGraphicFrameDrawingProperties(new OA.GraphicFrameLocks())); // <a:graphic> OA.Graphic graphic = new OA.Graphic(); // <a:graphicData> OA.GraphicData graphicData = new OA.GraphicData() { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" }; // <pic:pic> ODP.Picture picture = new ODP.Picture(); // <pic:nvPicPr> ODP.NonVisualPictureProperties pictureProperties = new ODP.NonVisualPictureProperties(); // <pic:cNvPr> pictureProperties.AppendChild(new ODP.NonVisualDrawingProperties() { Id = (UInt32Value)0U, Name = "Image" }); // <pic:cNvPicPr> pictureProperties.AppendChild(new ODP.NonVisualPictureDrawingProperties()); picture.AppendChild(pictureProperties); // <pic:blipFill> ODP.BlipFill blipFill = new ODP.BlipFill(); // <a:blip> // CompressionState = A.BlipCompressionValues.Print OA.Blip blip = new OA.Blip() { Embed = _embeddedReference, CompressionState = _pictureElement.CompressionState }; // $$pb todo comment // <a:extLst> OA.BlipExtensionList blipExtensions = new OA.BlipExtensionList(); // <a:ext> blipExtensions.AppendChild(new OA.BlipExtension() { Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}" }); blip.AppendChild(blipExtensions); // $$pb todo comment end blipFill.AppendChild(blip); // <a:stretch> OA.Stretch stretch = new OA.Stretch(); // <a:fillRect> stretch.AppendChild(new OA.FillRectangle()); blipFill.AppendChild(stretch); picture.AppendChild(blipFill); // <pic:spPr> ODP.ShapeProperties shapeProperties = new ODP.ShapeProperties(); // <a:xfrm> OA.Transform2D transform2D = new OA.Transform2D(); // new A.Offset // <a:off> transform2D.AppendChild(new OA.Offset() { X = 0L, Y = 0L }); // <a:ext> transform2D.AppendChild(new OA.Extents() { Cx = emuWidth, Cy = emuHeight }); shapeProperties.AppendChild(transform2D); // <a:prstGeom> // Preset = A.ShapeTypeValues.Rectangle OA.PresetGeometry presetGeometry = new OA.PresetGeometry() { Preset = _pictureElement.PresetShape }; // <a:avLst> presetGeometry.AppendChild(new OA.AdjustValueList()); shapeProperties.AppendChild(presetGeometry); picture.AppendChild(shapeProperties); graphicData.AppendChild(picture); graphic.AppendChild(graphicData); inline.AppendChild(graphic); return(inline); }
public A.Graphic Create() { // Graphic Object, <a:graphic> A.Graphic graphic = new A.Graphic(); // Graphic Object Data, <a:graphicData> A.GraphicData graphicData = new A.GraphicData() { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" }; // Picture, <pic:pic> // possible child : NonVisualPictureProperties <pic:nvPicPr>, BlipFill <pic:blipFill>, ShapeProperties <pic:spPr>, // DocumentFormat.OpenXml.Office2010.Drawing.Pictures.ShapeStyle <pic14:style>, DocumentFormat.OpenXml.Office2010.Drawing.Pictures.OfficeArtExtensionList <pic14:extLst> PIC.Picture picture = new PIC.Picture(); // Non-Visual Picture Properties, <pic:nvPicPr> picture.NonVisualPictureProperties = new PIC.NonVisualPictureProperties(); // Non-Visual Drawing Properties, <pic:cNvPr> picture.NonVisualPictureProperties.NonVisualDrawingProperties = new PIC.NonVisualDrawingProperties() { Id = 0, Name = "Image" }; // Non-Visual Picture Drawing Properties, <pic:cNvPicPr> picture.NonVisualPictureProperties.NonVisualPictureDrawingProperties = new PIC.NonVisualPictureDrawingProperties(); // Picture Fill, <pic:blipFill> picture.BlipFill = new PIC.BlipFill(); // Blip, <a:blip> picture.BlipFill.Blip = new A.Blip() { Embed = _embeddedReference, CompressionState = _compressionState }; // <a:extLst> //A.BlipExtensionList blipExtensions = new A.BlipExtensionList(); // <a:ext> //blipExtensions.AppendChild(new A.BlipExtension() { Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}" }); //picture.BlipFill.Blip.AppendChild(blipExtensions); // Source Rectangle, <a:srcRect> picture.BlipFill.SourceRectangle = new A.SourceRectangle() { Bottom = 0, Left = 0, Right = 0, Top = 0 }; // Stretch, <a:stretch> A.Stretch stretch = new A.Stretch(); // Fill Rectangle, <a:fillRect> stretch.AppendChild(new A.FillRectangle()); picture.BlipFill.AppendChild(stretch); // Shape Properties, <pic:spPr> picture.ShapeProperties = new PIC.ShapeProperties(); // Transform2D, <a:xfrm> picture.ShapeProperties.Transform2D = new A.Transform2D(); if (_rotation != 0) // Rotation, <a:xfrm rot> picture.ShapeProperties.Transform2D.Rotation = _rotation; if (_horizontalFlip) // Horizontal Flip, <a:xfrm flipH> picture.ShapeProperties.Transform2D.HorizontalFlip = _horizontalFlip; if (_verticalFlip) // Vertical Flip, <a:xfrm flipV> picture.ShapeProperties.Transform2D.VerticalFlip = _verticalFlip; // Offset, <a:off> picture.ShapeProperties.Transform2D.Offset = new A.Offset() { X = 0, Y = 0 }; // <a:ext> picture.ShapeProperties.Transform2D.Extents = new A.Extents() { Cx = _width, Cy = _height }; // Preset geometry, <a:prstGeom> // Preset Shape, <a:prstGeom prst> A.PresetGeometry presetGeometry = new A.PresetGeometry() { Preset = _presetShape }; // Shape Adjust Values, <a:avLst> presetGeometry.AppendChild(new A.AdjustValueList()); picture.ShapeProperties.AppendChild(presetGeometry); graphicData.AppendChild(picture); graphic.AppendChild(graphicData); return graphic; }
/// <summary> /// Creates an image paragraph. /// </summary> /// <param name="relationshipId">The relationship id.</param> /// <param name="name">The name.</param> /// <param name="description">The description.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <returns>The <see cref="Paragraph" /> containing the image.</returns> private DocumentFormat.OpenXml.Wordprocessing.Paragraph CreateImageParagraph( string relationshipId, string name, string description, double width, double height) { // http://msdn.microsoft.com/en-us/library/documentformat.openxml.drawing.extents.aspx // http://polymathprogrammer.com/2009/10/22/english-metric-units-and-open-xml/ // cx (Extent Length) // Specifies the length of the extents rectangle in EMUs. This rectangle shall dictate the size of the object as displayed (the result of any scaling to the original object). // Example: Consider a DrawingML object specified as follows: // <… cx="1828800" cy="200000"/> // The cx attributes specifies that this object has a height of 1828800 EMUs (English Metric Units). end example] // The possible values for this attribute are defined by the ST_PositiveCoordinate simple type (§20.1.10.42). // cy (Extent Width) // Specifies the width of the extents rectangle in EMUs. This rectangle shall dictate the size of the object as displayed (the result of any scaling to the original object). // Example: Consider a DrawingML object specified as follows: // < … cx="1828800" cy="200000"/> // The cy attribute specifies that this object has a width of 200000 EMUs (English Metric Units). end example] // The possible values for this attribute are defined by the ST_PositiveCoordinate simple type (§20.1.10.42). var paragraph1 = new DocumentFormat.OpenXml.Wordprocessing.Paragraph { RsidParagraphAddition = "00D91137", RsidRunAdditionDefault = "00AC08EB" }; var run1 = new Run(); var runProperties1 = new RunProperties(); var noProof1 = new NoProof(); runProperties1.AppendChild(noProof1); var drawing1 = new Drawing(); var inline1 = new Inline { DistanceFromTop = 0U, DistanceFromBottom = 0U, DistanceFromLeft = 0U, DistanceFromRight = 0U }; var extent1 = new Extent { Cx = 5753100L, Cy = 3600450L }; extent1.Cx = (long)(width * 914400); extent1.Cy = (long)(height * 914400); var effectExtent1 = new EffectExtent { LeftEdge = 0L, TopEdge = 0L, RightEdge = 0L, BottomEdge = 0L }; var docProperties1 = new DocProperties { Id = 1U, Name = name, Description = description }; var nonVisualGraphicFrameDrawingProperties1 = new NonVisualGraphicFrameDrawingProperties(); var graphicFrameLocks1 = new GraphicFrameLocks { NoChangeAspect = true }; graphicFrameLocks1.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main"); nonVisualGraphicFrameDrawingProperties1.AppendChild(graphicFrameLocks1); var graphic1 = new Graphic(); graphic1.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main"); var graphicData1 = new GraphicData { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" }; var picture1 = new Picture(); picture1.AddNamespaceDeclaration("pic", "http://schemas.openxmlformats.org/drawingml/2006/picture"); var nonVisualPictureProperties1 = new NonVisualPictureProperties(); var nonVisualDrawingProperties1 = new NonVisualDrawingProperties { Id = 0U, Name = name, Description = description }; var nonVisualPictureDrawingProperties1 = new NonVisualPictureDrawingProperties(); var pictureLocks1 = new PictureLocks { NoChangeAspect = true, NoChangeArrowheads = true }; nonVisualPictureDrawingProperties1.AppendChild(pictureLocks1); nonVisualPictureProperties1.AppendChild(nonVisualDrawingProperties1); nonVisualPictureProperties1.AppendChild(nonVisualPictureDrawingProperties1); var blipFill1 = new BlipFill(); var blip1 = new Blip { Embed = relationshipId }; var blipExtensionList1 = new BlipExtensionList(); var blipExtension1 = new BlipExtension { Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}" }; var useLocalDpi1 = new UseLocalDpi { Val = false }; useLocalDpi1.AddNamespaceDeclaration("a14", "http://schemas.microsoft.com/office/drawing/2010/main"); blipExtension1.AppendChild(useLocalDpi1); blipExtensionList1.AppendChild(blipExtension1); blip1.AppendChild(blipExtensionList1); var sourceRectangle1 = new SourceRectangle(); var stretch1 = new Stretch(); var fillRectangle1 = new FillRectangle(); stretch1.AppendChild(fillRectangle1); blipFill1.AppendChild(blip1); blipFill1.AppendChild(sourceRectangle1); blipFill1.AppendChild(stretch1); var shapeProperties1 = new ShapeProperties { BlackWhiteMode = BlackWhiteModeValues.Auto }; var transform2D1 = new Transform2D(); var offset1 = new Offset { X = 0L, Y = 0L }; var extents1 = new Extents { Cx = extent1.Cx, Cy = extent1.Cy }; transform2D1.AppendChild(offset1); transform2D1.AppendChild(extents1); var presetGeometry1 = new PresetGeometry { Preset = ShapeTypeValues.Rectangle }; var adjustValueList1 = new AdjustValueList(); presetGeometry1.AppendChild(adjustValueList1); var noFill1 = new NoFill(); var outline1 = new Outline(); var noFill2 = new NoFill(); outline1.AppendChild(noFill2); shapeProperties1.AppendChild(transform2D1); shapeProperties1.AppendChild(presetGeometry1); shapeProperties1.AppendChild(noFill1); shapeProperties1.AppendChild(outline1); picture1.AppendChild(nonVisualPictureProperties1); picture1.AppendChild(blipFill1); picture1.AppendChild(shapeProperties1); graphicData1.AppendChild(picture1); graphic1.AppendChild(graphicData1); inline1.AppendChild(extent1); inline1.AppendChild(effectExtent1); inline1.AppendChild(docProperties1); inline1.AppendChild(nonVisualGraphicFrameDrawingProperties1); inline1.AppendChild(graphic1); drawing1.AppendChild(inline1); run1.AppendChild(runProperties1); run1.AppendChild(drawing1); paragraph1.AppendChild(run1); return paragraph1; }