public static ShapeRange PasteShapesFromClipboard(PowerPointSlide slide) { try { // Note: Some copied objects are pasted on currentSlide rather than the desired slide (e.g. jpg from desktop), // so we must check whether it is pasted correctly, else we cut-and-paste it into the correct slide. int initialSlideShapesCount = slide.Shapes.Count; ShapeRange pastedShapes = slide.Shapes.Paste(); int finalSlideShapesCount = slide.Shapes.Count; if (pastedShapes.Count >= 1 && finalSlideShapesCount == initialSlideShapesCount) { pastedShapes.Cut(); pastedShapes = slide.Shapes.Paste(); } return(pastedShapes); } catch (COMException e) { // May be thrown if there is placeholder shape in clipboard Logger.LogException(e, "PasteShapeFromClipboard"); return(null); } }
public static void Execute(PowerPointPresentation pres, PowerPointSlide slide, ShapeRange pastingShapes, float slideWidth, float slideHeight) { pastingShapes = ShapeUtil.GetShapesWhenTypeNotMatches(slide, pastingShapes, Microsoft.Office.Core.MsoShapeType.msoPlaceholder); if (pastingShapes.Count == 0) { return; } Shape pastingShape = pastingShapes[1]; if (pastingShapes.Count > 1) { pastingShape = pastingShapes.Group(); } // Temporary house the latest clipboard shapes ShapeRange origClipboardShapes = ClipboardUtil.PasteShapesFromClipboard(pres, slide); // Compression of large image(s) Shape shapeToFitSlide = GraphicsUtil.CompressImageInShape(pastingShape, slide); // Bring the same original shapes back into clipboard, preserving original size origClipboardShapes.Cut(); shapeToFitSlide.LockAspectRatio = Microsoft.Office.Core.MsoTriState.msoTrue; PPShape ppShapeToFitSlide = new PPShape(shapeToFitSlide); ResizeShape(ppShapeToFitSlide, slideWidth, slideHeight); ppShapeToFitSlide.VisualCenter = new System.Drawing.PointF(slideWidth / 2, slideHeight / 2); }
private static ShapeRange PasteWithCorrectSlideCheck(PowerPointSlide slide, bool isPasteSpecial = false, PpPasteDataType pasteType = PpPasteDataType.ppPasteDefault) { // Note: Some copied objects are pasted on currentSlide rather than the desired slide (e.g. jpg from desktop), // so we must check whether it is pasted correctly, else we cut-and-paste it into the correct slide. int initialSlideShapesCount = slide.Shapes.Count; ShapeRange pastedShapes = null; if (!isPasteSpecial) { pastedShapes = slide.Shapes.Paste(); } else { pastedShapes = slide.Shapes.PasteSpecial(pasteType); } int finalSlideShapesCount = slide.Shapes.Count; if (pastedShapes.Count >= 1 && finalSlideShapesCount == initialSlideShapesCount) { pastedShapes.Cut(); if (!isPasteSpecial) { pastedShapes = slide.Shapes.Paste(); } else { pastedShapes = slide.Shapes.PasteSpecial(pasteType); } } return(pastedShapes); }
public static Shape SafeCut(this Shapes shapes, ShapeRange selection) { return(PPLClipboard.Instance.LockAndRelease(() => { selection.Cut(); return shapes.PasteSpecial(PpPasteDataType.ppPastePNG)[1]; })); }
internal static PowerPointBgEffectSlide GenerateEffectSlide(PowerPointSlide curSlide, Selection selection, bool generateOnRemainder) { PowerPointSlide dupSlide = null; try { ShapeRange shapeRange = ShapeUtil.GetShapeRange(selection); if (shapeRange.Count != 0) { dupSlide = curSlide.Duplicate(); } shapeRange.Cut(); PowerPointBgEffectSlide effectSlide = PowerPointBgEffectSlide.BgEffectFactory(curSlide.GetNativeSlide(), generateOnRemainder); if (dupSlide != null) { if (generateOnRemainder) { dupSlide.Delete(); } else { dupSlide.MoveTo(curSlide.Index); curSlide.Delete(); } } return(effectSlide); } catch (InvalidOperationException e) { MessageBox.Show(e.Message); return(null); } catch (COMException) { if (dupSlide != null) { dupSlide.Delete(); } MessageBox.Show(TextCollection.EffectsLabText.ErrorSelectAtLeastOneShape); return(null); } catch (Exception e) { if (dupSlide != null) { dupSlide.Delete(); } ErrorDialogBox.ShowDialog(CommonText.ErrorTitle, e.Message, e); return(null); } }
internal static PowerPointBgEffectSlide GenerateEffectSlide(PowerPointSlide curSlide, Selection selection, bool generateOnRemainder) { PowerPointSlide dupSlide = null; try { ShapeRange shapeRange = selection.ShapeRange; if (selection.HasChildShapeRange) { shapeRange = selection.ChildShapeRange; } if (shapeRange.Count != 0) { dupSlide = curSlide.Duplicate(); } shapeRange.Cut(); var effectSlide = PowerPointBgEffectSlide.BgEffectFactory(curSlide.GetNativeSlide(), generateOnRemainder); if (dupSlide != null) { if (generateOnRemainder) { dupSlide.Delete(); } else { dupSlide.MoveTo(curSlide.Index); curSlide.Delete(); } } return(effectSlide); } catch (InvalidOperationException e) { MessageBox.Show(e.Message); return(null); } catch (COMException) { if (dupSlide != null) { dupSlide.Delete(); } MessageBox.Show("Please select at least 1 shape"); return(null); } catch (Exception e) { if (dupSlide != null) { dupSlide.Delete(); } ErrorDialogBox.ShowDialog("Error", e.Message, e); return(null); } }
private static PowerPointBgEffectSlide PrepareForeground(ShapeRange oriShapeRange, ShapeRange copyShapeRange, Slide refSlide, PowerPointSlide newSlide) { try { // crop in the original slide and put into clipboard var croppedShape = MakeFrontImage(oriShapeRange); croppedShape.Cut(); // swap the uncropped shapes and cropped shapes var pastedCrop = newSlide.Shapes.Paste(); // calibrate pasted shapes pastedCrop.Left -= 12; pastedCrop.Top -= 12; // ungroup front image if necessary if (pastedCrop[1].Type == Core.MsoShapeType.msoGroup) { pastedCrop[1].Ungroup(); } copyShapeRange.Cut(); oriShapeRange = refSlide.Shapes.Paste(); oriShapeRange.Fill.ForeColor.RGB = 0xaaaaaa; oriShapeRange.Fill.Transparency = 0.7f; oriShapeRange.Line.Visible = Core.MsoTriState.msoTrue; oriShapeRange.Line.ForeColor.RGB = 0x000000; Utils.Graphics.MakeShapeViewTimeInvisible(oriShapeRange, refSlide); oriShapeRange.Select(); // finally add transition to the new slide newSlide.Transition.EntryEffect = PpEntryEffect.ppEffectFadeSmoothly; newSlide.Transition.Duration = 0.5f; return new PowerPointBgEffectSlide(newSlide.GetNativeSlide()); } catch (Exception e) { var errorMessage = CropToShape.GetErrorMessageForErrorCode(e.Message); errorMessage = errorMessage.Replace("Crop To Shape", "Blur/Recolor Remainder"); newSlide.Delete(); throw new InvalidOperationException(errorMessage); } }