private void insertLink(Slide slide, PageUrl pageUrl, int objId) { slide.SlidePart.AddHyperlinkRelationship(new System.Uri(pageUrl.url, System.UriKind.Absolute), true, "rId" + objId); P.Shape shape = new P.Shape(); P.NonVisualShapeProperties nonVisualShapeProperties1 = new P.NonVisualShapeProperties() { NonVisualDrawingProperties = new P.NonVisualDrawingProperties() { Id = (UInt32Value)2U, Name = "矩形 1", HyperlinkOnClick = new A.HyperlinkOnClick() { Id = "rId" + objId } }, NonVisualShapeDrawingProperties = new P.NonVisualShapeDrawingProperties(), ApplicationNonVisualDrawingProperties = new P.ApplicationNonVisualDrawingProperties() }; P.ShapeProperties shapeProperties = new P.ShapeProperties() { Transform2D = new A.Transform2D() { Offset = new A.Offset() { X = pageUrl.origin.Width * ImageInfoUtils.RATE, Y = pageUrl.origin.Height * ImageInfoUtils.RATE }, Extents = new A.Extents() { Cx = pageUrl.size.Width * ImageInfoUtils.RATE, Cy = pageUrl.size.Height * ImageInfoUtils.RATE } } }; A.PresetGeometry presetGeometry = new A.PresetGeometry() { Preset = A.ShapeTypeValues.Rectangle, AdjustValueList = new A.AdjustValueList() }; A.NoFill noFill = new A.NoFill(); A.Outline outline = new A.Outline(); A.NoFill noFill2 = new A.NoFill(); outline.Append(noFill2); shapeProperties.Append(presetGeometry); shapeProperties.Append(noFill); shapeProperties.Append(outline); P.ShapeStyle shapeStyle1 = new P.ShapeStyle(); A.LineReference lineReference = new A.LineReference() { Index = (UInt32Value)2U }; A.SchemeColor schemeColor = new A.SchemeColor() { Val = A.SchemeColorValues.Accent1 }; A.Shade shade1 = new A.Shade() { Val = 50000 }; schemeColor.Append(shade1); lineReference.Append(schemeColor); A.FillReference fillReference = new A.FillReference() { Index = (UInt32Value)1U }; A.SchemeColor schemeColor2 = new A.SchemeColor() { Val = A.SchemeColorValues.Accent1 }; fillReference.Append(schemeColor2); A.EffectReference effectReference = new A.EffectReference() { Index = (UInt32Value)0U }; A.SchemeColor schemeColor3 = new A.SchemeColor() { Val = A.SchemeColorValues.Accent1 }; effectReference.Append(schemeColor3); A.FontReference fontReference = new A.FontReference() { Index = A.FontCollectionIndexValues.Minor }; A.SchemeColor schemeColor4 = new A.SchemeColor() { Val = A.SchemeColorValues.Light1 }; fontReference.Append(schemeColor4); shapeStyle1.Append(lineReference); shapeStyle1.Append(fillReference); shapeStyle1.Append(effectReference); shapeStyle1.Append(fontReference); P.TextBody textBody = new P.TextBody(); A.BodyProperties bodyProperties = new A.BodyProperties() { RightToLeftColumns = false, Anchor = A.TextAnchoringTypeValues.Center }; A.ListStyle listStyle = new A.ListStyle(); A.Paragraph paragraph = new A.Paragraph(); A.ParagraphProperties paragraphProperties = new A.ParagraphProperties() { Alignment = A.TextAlignmentTypeValues.Center }; A.EndParagraphRunProperties endParagraphRunProperties = new A.EndParagraphRunProperties() { Language = "zh-CN", AlternativeLanguage = "en-US" }; paragraph.Append(paragraphProperties); paragraph.Append(endParagraphRunProperties); textBody.Append(bodyProperties); textBody.Append(listStyle); textBody.Append(paragraph); shape.Append(nonVisualShapeProperties1); shape.Append(shapeProperties); shape.Append(shapeStyle1); shape.Append(textBody); slide.CommonSlideData.ShapeTree.AppendChild(shape); }
/// <summary> /// Check the notes page size and reset values /// </summary> /// <param name="pDoc">oxml doc to change</param> public static void ChangeNotesPageSize(PresentationDocument pDoc) { if (pDoc == null) { throw new ArgumentNullException("pDoc = null"); } // Get the presentation part of document PresentationPart presentationPart = pDoc.PresentationPart; if (presentationPart != null) { Presentation p = presentationPart.Presentation; // Step 1 : Resize the presentation notesz prop // if the notes size is already the default, no need to make any changes if (p.NotesSize.Cx != 6858000 || p.NotesSize.Cy != 9144000) { // setup default size NotesSize defaultNotesSize = new NotesSize() { Cx = 6858000L, Cy = 9144000L }; // first reset the notes size values p.NotesSize = defaultNotesSize; // now save up the part p.Save(); } // Step 2 : loop the shapes in the notes master and reset their sizes // need to find a way to flag a file if the notes master and/or notes slides become corrupt // hiding behind a setting checkbox for now if (Properties.Settings.Default.ResetNotesMaster == true) { // we need to reset sizes in the notes master for each shape ShapeTree mSt = presentationPart.NotesMasterPart.NotesMaster.CommonSlideData.ShapeTree; foreach (var mShp in mSt) { if (mShp.ToString() == StringResources.dfopShape) { PShape ps = (PShape)mShp; NonVisualDrawingProperties nvdpr = ps.NonVisualShapeProperties.NonVisualDrawingProperties; Transform2D t2d = ps.ShapeProperties.Transform2D; // use default values if (nvdpr.Name == StringResources.pptHeaderPlaceholder1) { t2d.Offset.X = 0L; t2d.Offset.Y = 0L; t2d.Extents.Cx = 2971800L; t2d.Extents.Cy = 458788L; } if (nvdpr.Name == StringResources.pptDatePlaceholder2) { t2d.Offset.X = 3884613L; t2d.Offset.Y = 0L; t2d.Extents.Cx = 2971800L; t2d.Extents.Cy = 458788L; } if (nvdpr.Name == StringResources.pptSlideImagePlaceholder3) { t2d.Offset.X = 685800L; t2d.Offset.Y = 1143000L; t2d.Extents.Cx = 5486400L; t2d.Extents.Cy = 3086100L; } if (nvdpr.Name == StringResources.pptNotesPlaceholder4) { t2d.Offset.X = 685800L; t2d.Offset.Y = 4400550L; t2d.Extents.Cx = 5486400L; t2d.Extents.Cy = 3600450L; } if (nvdpr.Name == StringResources.pptFooterPlaceholder5) { t2d.Offset.X = 0L; t2d.Offset.Y = 8685213L; t2d.Extents.Cx = 2971800L; t2d.Extents.Cy = 458787L; } if (nvdpr.Name == StringResources.pptSlideNumberPlaceholder6) { t2d.Offset.X = 3884613L; t2d.Offset.Y = 8685213L; t2d.Extents.Cx = 2971800L; t2d.Extents.Cy = 458787L; } } } // Step 3 : we need to delete the size values for placeholders on each notes slide foreach (var slideId in p.SlideIdList.Elements <SlideId>()) { SlidePart slidePart = presentationPart.GetPartById(slideId.RelationshipId) as SlidePart; ShapeTree st = slidePart.NotesSlidePart.NotesSlide.CommonSlideData.ShapeTree; List <RunProperties> rpList = slidePart.NotesSlidePart.NotesSlide.Descendants <RunProperties>().ToList(); foreach (var s in st) { // we only want to make changes to the shapes if (s.ToString() == StringResources.dfopShape) { PShape ps = (PShape)s; Transform2D t2d = ps.ShapeProperties.Transform2D; TextBody tb = ps.TextBody; // if the transform exists, delete it for each shape if (t2d != null) { t2d.Remove(); } // if there are drawing paragraph props, reset the margin and indent to 0 if (ps.TextBody != null) { foreach (var x in tb.ChildElements) { if (x.ToString() == "DocumentFormat.OpenXml.Drawing.Paragraph") { Paragraph para = (Paragraph)x; if (para.ParagraphProperties != null) { if (para.ParagraphProperties.LeftMargin != null) { para.ParagraphProperties.LeftMargin = 0; } if (para.ParagraphProperties.Indent != null) { para.ParagraphProperties.Indent = 0; } } } } } } else if (s.ToString() == StringResources.dfopPresentationPicture) { DocumentFormat.OpenXml.Presentation.Picture pic = (DocumentFormat.OpenXml.Presentation.Picture)s; Transform2D t2d = pic.ShapeProperties.Transform2D; // there are times when pictures get moved with the rest of the slide objects, need to reset those back if (t2d != null) { t2d.Offset.X = 217831L; t2d.Offset.Y = 4470109L; t2d.Extents.Cx = 3249763L; t2d.Extents.Cy = 2795946L; } } } foreach (RunProperties r in rpList) { r.FontSize = 1200; } } } } }