diff --git a/en/python-net/developer-guide/manage-presentation/convert-presentation/convert-powerpoint/convert-powerpoint-to-markdown/_index.md b/en/python-net/developer-guide/manage-presentation/convert-presentation/convert-powerpoint/convert-powerpoint-to-markdown/_index.md index c655ac5b9..846db7469 100644 --- a/en/python-net/developer-guide/manage-presentation/convert-presentation/convert-powerpoint/convert-powerpoint-to-markdown/_index.md +++ b/en/python-net/developer-guide/manage-presentation/convert-presentation/convert-powerpoint/convert-powerpoint-to-markdown/_index.md @@ -28,92 +28,80 @@ keywords: description: "Convert PowerPoint and OpenDocument slides—PPT, PPTX, ODP—to clean Markdown with Aspose.Slides for Python via .NET, automate documentation and keep formatting." --- -{{% alert color="info" %}} +## **Convert Presentations to Markdown** -Support for PowerPoint to markdown conversion was implemented in [Aspose.Slides 23.7](https://docs.aspose.com/slides/python-net/aspose-slides-for-python-net-23-7-release-notes/). +The example below shows the simplest way to convert a PowerPoint presentation to Markdown using Aspose.Slides for Python via .NET with default settings. -{{% /alert %}} +1. Instantiate a [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) to load the presentation. +1. Call `save` to export it as a Markdown file. -{{% alert color="warning" %}} - -PowerPoint to markdown export is **without images** by default. If you want to export a PowerPoint document containing images, you need to set `saveOptions.export_type = MarkdownExportType.VISUAL` also set the `base_path` where the images referenced in the markdown document will be saved. - -{{% /alert %}} - -## **Convert PowerPoint to Markdown** - -1. Create an instance of the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class to represent a presentation object. -2. Use the [Save](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/#methods) method to save the object as a markdown file. - -This Python code shows you how to convert PowerPoint to markdown: +Use the Python snippet below to perform the conversion: ```python import aspose.slides as slides -with slides.Presentation("pres.pptx") as pres: - pres.save("pres.md", slides.export.SaveFormat.MD) +with slides.Presentation("presentation.pptx") as presentation: + presentation.save("presentation.md", slides.export.SaveFormat.MD) ``` -## Convert PowerPoint to Markdown Flavor +## **Convert Presentations to Markdown Flavor** -Aspose.Slides allows you to convert PowerPoint to markdown (containing basic syntax), CommonMark, GitHub flavored markdown, Trello, XWiki, GitLab, and 17 other markdown flavors. +Aspose.Slides allows you to convert presentations to Markdown formats, including basic Markdown, CommonMark, GitHub-flavored Markdown, Trello, XWiki, GitLab, and 17 other Markdown flavors. -This Python code shows you how to convert PowerPoint to CommonMark: +The following Python example shows how to convert a PowerPoint presentation to CommonMark: ```python -from aspose.slides import Presentation -from aspose.slides.dom.export.markdown.saveoptions import MarkdownSaveOptions, Flavor -from aspose.slides.export import SaveFormat +import aspose.slides as slides -with Presentation("pres.pptx") as pres: - saveOptions = MarkdownSaveOptions() - saveOptions.flavor = Flavor.COMMONMARK +save_options = slides.export.MarkdownSaveOptions() +save_options.flavor = slides.export.Flavor.COMMON_MARK - pres.save("pres.md", SaveFormat.MD, saveOptions) +with slides.Presentation("presentation.pptx") as presentation: + presentation.save("presentation.md", slides.export.SaveFormat.MD, save_options) ``` -The 23 supported markdown flavors are [listed under the Flavor enumeration](https://reference.aspose.com/slides/python-net/aspose.slides.dom.export.markdown.saveoptions/flavor/) from the [MarkdownSaveOptions](https://reference.aspose.com/slides/python-net/aspose.slides.dom.export.markdown.saveoptions/markdownsaveoptions/) class. +The 23 supported Markdown flavors are listed in the [Flavor](https://reference.aspose.com/slides/python-net/aspose.slides.dom.export.markdown.saveoptions/flavor/) enumeration of the [MarkdownSaveOptions](https://reference.aspose.com/slides/python-net/aspose.slides.dom.export.markdown.saveoptions/markdownsaveoptions/) class. -## **Convert Presentation Containing Images to Markdown** +## **Convert Presentations Containing Images to Markdown** -The [MarkdownSaveOptions](https://reference.aspose.com/slides/python-net/aspose.slides.dom.export.markdown.saveoptions/markdownsaveoptions/) class provides properties and enumerations that allow you to use certain options or settings for the resulting markdown file. The [MarkdownExportType](https://reference.aspose.com/slides/python-net/aspose.slides.dom.export.markdown.saveoptions/markdownexporttype/) enum, for example, can be set to values that determine how images are rendered or handled: `Sequential`, `TextOnly`, `Visual`. +The [MarkdownSaveOptions](https://reference.aspose.com/slides/python-net/aspose.slides.dom.export.markdown.saveoptions/markdownsaveoptions/) class provides properties and enumerations that let you configure the resulting Markdown file. For example, the [MarkdownExportType](https://reference.aspose.com/slides/python-net/aspose.slides.dom.export.markdown.saveoptions/markdownexporttype/) enum controls how images are handled: `SEQUENTIAL`, `TEXT_ONLY`, or `VISUAL`. ### **Convert Images Sequentially** -If you want the images to appear individually one after the other in the resulting markdown, you have to choose the sequential option. This Python code shows you how to convert a presentation containing images to markdown: +If you want images to appear individually—one after another—in the generated Markdown, choose the `SEQUENTIAL` option. The Python example below shows how to convert a presentation with images to Markdown. ```python import aspose.slides as slides -with slides.Presentation("pres.pptx") as pres: - markdownSaveOptions = slides.export.MarkdownSaveOptions() - markdownSaveOptions.show_hidden_slides = True - markdownSaveOptions.show_slide_number = True - markdownSaveOptions.flavor = slides.export.Flavor.GITHUB - markdownSaveOptions.export_type = slides.export.MarkdownExportType.SEQUENTIAL - markdownSaveOptions.new_line_type = slides.export.NewLineType.WINDOWS - - pres.save("doc.md", [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ], slides.export.SaveFormat.MD, markdownSaveOptions) +save_options = slides.export.MarkdownSaveOptions() +save_options.show_hidden_slides = True +save_options.show_slide_number = True +save_options.flavor = slides.export.Flavor.GITHUB +save_options.export_type = slides.export.MarkdownExportType.SEQUENTIAL +save_options.new_line_type = slides.export.NewLineType.WINDOWS + +slide_indices = [1, 3, 5] + +with slides.Presentation("presentation.pptx") as presentation: + presentation.save("presentation.md", slide_indices, slides.export.SaveFormat.MD, save_options) ``` ### **Convert Images Visually** -If you want the images to appear together in the resulting markdown, you have to choose the visual option. In this case, images will be saved to the current directory of the application (and a relative path will be built for them in the markdown document), or you can specify your preferred path and folder name. +If you want the images to appear together in the resulting Markdown, choose the `VISUAL` option. In this mode, images are saved to the application’s current directory (and the Markdown document uses relative paths), or you can specify a custom output path and folder name. -This Python code demonstrates the operation: +The Python example below demonstrates this operation: ```python -from aspose.slides import Presentation -from aspose.slides.dom.export.markdown.saveoptions import MarkdownSaveOptions, MarkdownExportType -from aspose.slides.export import SaveFormat - -with Presentation("pres.pptx") as pres: - outPath = "c:\\documents" +import os +import aspose.slides as slides - saveOptions = MarkdownSaveOptions() - saveOptions.export_type = MarkdownExportType.VISUAL - saveOptions.images_save_folder_name = "md-images" - saveOptions.base_path = outPath +save_options = slides.export.MarkdownSaveOptions() +save_options.export_type = slides.export.MarkdownExportType.VISUAL +save_options.images_save_folder_name = "md-images" +save_options.base_path = "c:\\documents" - pres.save(outPath + "\\pres.md", SaveFormat.MD, saveOptions) +with slides.Presentation("presentation.pptx") as presentation: + file_path = os.path.join(save_options.base_path, "presentation.md") + presentation.save(file_path, slides.export.SaveFormat.MD, save_options) ``` diff --git a/en/python-net/developer-guide/manage-presentation/convert-presentation/convert-powerpoint/convert-powerpoint-to-png/_index.md b/en/python-net/developer-guide/manage-presentation/convert-presentation/convert-powerpoint/convert-powerpoint-to-png/_index.md index ca2e7b843..69167d36d 100644 --- a/en/python-net/developer-guide/manage-presentation/convert-presentation/convert-powerpoint/convert-powerpoint-to-png/_index.md +++ b/en/python-net/developer-guide/manage-presentation/convert-presentation/convert-powerpoint/convert-powerpoint-to-png/_index.md @@ -22,72 +22,68 @@ keywords: description: "Convert PowerPoint and OpenDocument presentations to high-quality PNG images quickly with Aspose.Slides for Python via .NET, ensuring precise, automated results." --- -## **About PowerPoint to PNG Conversion** +## **Overview** -The PNG (Portable Network Graphics) format is not as popular as JPEG (Joint Photographic Experts Group), but it still very popular. +Aspose.Slides for Python via .NET makes it straightforward to convert PowerPoint presentations to PNG. You load a presentation, iterate through its slides, render each one to a raster image, and save the result as PNG files. This is ideal for generating slide previews, embedding slides in web pages, or producing static assets for downstream processing. -**Use case:** When you have a complex image and size is not an issue, PNG is a better image format than JPEG. +## **Convert Slides to PNG** -{{% alert title="Tip" color="primary" %}} You may want to check out Aspose free **PowerPoint to PNG Converters**: [PPTX to PNG](https://products.aspose.app/slides/conversion/pptx-to-png) and [PPT to PNG](https://products.aspose.app/slides/conversion/ppt-to-png). They are a live implementation of the process described on this page. {{% /alert %}} - -## **Convert PowerPoint to PNG** +This section shows the simplest possible example of converting a PowerPoint presentation to PNG images using Aspose.Slides for Python via .NET. Go through these steps: 1. Instantiate the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class. -2. Get the slide object from the [Presentation.Slides](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) collection under the [ISlide](https://reference.aspose.com/slides/python-net/aspose.slides/islide/) interface. -3. Use a [ISlide.GetImage](https://reference.aspose.com/slides/python-net/aspose.slides/islide/) method to get the thumbnail for each slide. -4. Use the [IPresentation.SaveMethod(String, SaveFormat, ISaveOptions](https://reference.aspose.com/slides/python-net/aspose.slides/ipresentation/) method to save the slide thumbnail to the PNG format. +1. Get a slide from the `Presentation.slides` collection (see the [Slide](https://reference.aspose.com/slides/python-net/aspose.slides/slide/) class). +1. Use the `Slide.get_image` method to generate a thumbnail of the slide. +1. Use the `Presentation.save` method to save the slide thumbnail in PNG format. -This Python code shows you how to convert a PowerPoint presentation to PNG: +This Python code shows how to convert a PowerPoint presentation to PNG: ```py import aspose.slides as slides -pres = slides.Presentation("pres.pptx") - -for index in range(pres.slides.length): - slide = pres.slides[index] - with slide.get_image() as image: - image.save("slide_{i}.png".format(i = index), slides.ImageFormat.PNG) +with slides.Presentation("presentation.pptx") as presentation: + for index, slide in enumerate(presentation.slides): + with slide.get_image() as image: + image.save(f"slide_{index}.png", slides.ImageFormat.PNG) ``` -## **Convert PowerPoint to PNG With Custom Dimensions** +## **Convert Slides to PNG with Custom Dimensions** -If you want to obtain PNG files around a certain scale, you can set the values for `desiredX` and `desiredY`, which determine the dimensions of the resulting thumbnail. +To export slides to PNG at a custom scale, call `Slide.get_image` with horizontal and vertical scale factors. These multipliers resize the output relative to the slide’s original dimensions—for example, `2.0` doubles both width and height. Use equal values for `scale_x` and `scale_y` to preserve the aspect ratio. -This code in Python demonstrates the described operation: +This Python code demonstrates the described operation: ```py import aspose.slides as slides -pres = slides.Presentation("pres.pptx") +scale_x = 2 +scale_y = scale_x -scaleX = 2 -scaleY = 2 -for index in range(pres.slides.length): - slide = pres.slides[index] - with slide.get_image(scaleX, scaleY) as image: - image.save("slide_{index}.png".format(index=index), slides.ImageFormat.PNG) +with slides.Presentation("presentation.pptx") as presentation: + for index, slide in enumerate(presentation.slides): + with slide.get_image(scale_x, scale_y) as image: + image.save(f"slide_{index}.png", slides.ImageFormat.PNG) ``` -## **Convert PowerPoint to PNG With Custom Size** - -If you want to obtain PNG files around a certain size, you can pass your preferred `width` and `height` arguments for `ImageSize`. +## **Convert Slides to PNG with Custom Size** -This code shows you how to convert a PowerPoint to PNG while specifying the size for the images: +If you want to generate PNG files at a specific size, pass your desired `width` and `height` values. The code below shows how to convert a PowerPoint to PNG while specifying the image size: ```py import aspose.slides as slides import aspose.pydrawing as drawing -pres = slides.Presentation(path + "pres.pptx") - size = drawing.Size(960, 720) -for index in range(pres.slides.length): - slide = pres.slides[index] - with slide.get_image(size) as image: - image.save("slide_{index}.png".format(index=index), slides.ImageFormat.PNG) +with slides.Presentation("presentation.pptx") as presentation: + for index, slide in enumerate(presentation.slides): + with slide.get_image(size) as image: + image.save(f"slide_{index}.png", slides.ImageFormat.PNG) ``` +{{% alert title="Tip" color="primary" %}} + +You may want to try Aspose’s free **PowerPoint-to-PNG converters**—[PPTX to PNG](https://products.aspose.app/slides/conversion/pptx-to-png) and [PPT to PNG](https://products.aspose.app/slides/conversion/ppt-to-png). They provide a live implementation of the process described on this page. + +{{% /alert %}} diff --git a/en/python-net/developer-guide/powerpoint-animation/_index.md b/en/python-net/developer-guide/powerpoint-animation/_index.md index 5b8a5fdc8..f84508cec 100644 --- a/en/python-net/developer-guide/powerpoint-animation/_index.md +++ b/en/python-net/developer-guide/powerpoint-animation/_index.md @@ -29,22 +29,26 @@ keywords: description: "Explore the capabilities of Aspose.Slides for Python via .NET in handling PowerPoint animations. This general overview highlights key features and offers insights to enhance your presentations." --- -Since presentations are meant to present something, their visual appearance and interactive behavior is always considered while creating them. +## **Overview** -**PowerPoint animation** plays an important role in order to make presentation eye-catching and attractive for the viewers. Aspose.Slides for Python via .NET offers a wide range of options to add animation to PowerPoint presentation: +Presentations are designed to convey information, so their visual appearance and interactive behavior are key considerations during creation. -- apply various types of PowerPoint animation effects on shapes, charts, tables, OLE Objects and other presentation elements. -- use multiple PowerPoint animation effects on a shape. -- use animation timeline to control animation effects. -- create custom animation. +**PowerPoint animation** plays an important role in making a presentation eye-catching and engaging for viewers. Aspose.Slides for Python via .NET provides a wide range of options to add animation to a PowerPoint presentation. You can: -In Aspose.Slides for Python via .NET, various animations effects can be applied on the shapes. As every element on the slide including text, pictures, OLE Object, table etc is considered as a shape, it means we can apply animation effect on every element of a slide. +- Apply various animation effects to shapes, charts, tables, OLE objects, and other elements. +- Use multiple animation effects on a single shape. +- Control effects through the animation timeline. +- Create custom animations. + +In Aspose.Slides for Python via .NET, animation effects can be applied to shapes. Because every element on a slide—including text, pictures, OLE objects, and tables—is treated as a shape, you can apply animation effects to any element on the slide. + +The [aspose.slides.animation](https://reference.aspose.com/slides/python-net/aspose.slides.animation/) namespace provides the classes for working with PowerPoint animations. -[**Aspose.Slides.Animation**](https://reference.aspose.com/slides/python-net/aspose.slides.animation/) **namespace** provides classes to work with PowerPoint animations. ## **Animation Effects** -Aspose.Slides supports **150+ animation effects**, including basic animation effects like Bounce, PathFootball, Zoom effect and specific animation effects as OLEObjectShow, OLEObjectOpen. You can find a full listing of animation effects in [**EffectType** ](https://reference.aspose.com/slides/python-net/aspose.slides.animation/effecttype/)enumeration. -Additionally, these animation effects can be used in combination with them: +Aspose.Slides supports **150+ animation effects**, including basic effects such as Bounce, PathFootball, and Zoom, as well as specialized effects like OLEObjectShow and OLEObjectOpen. You can find the full list in the [EffectType](https://reference.aspose.com/slides/python-net/aspose.slides.animation/effecttype/) enumeration. + +Additionally, these animation effects can be combined with the following effects: - [ColorEffect](https://reference.aspose.com/slides/python-net/aspose.slides.animation/coloreffect/) - [CommandEffect](https://reference.aspose.com/slides/python-net/aspose.slides.animation/commandeffect/) @@ -54,36 +58,51 @@ Additionally, these animation effects can be used in combination with them: - [RotationEffect](https://reference.aspose.com/slides/python-net/aspose.slides.animation/rotationeffect) - [ScaleEffect](https://reference.aspose.com/slides/python-net/aspose.slides.animation/scaleeffect/) - [SetEffect](https://reference.aspose.com/slides/python-net/aspose.slides.animation/seteffect/) + ## **Custom Animation** -It is possible to create your own **custom animations** in Aspose.Slides. -This can be achieved if you combine several behaviours together into a new custom animation. -[**Behaviour**](https://reference.aspose.com/slides/python-net/aspose.slides.animation/behavior/) is a building unit of any PowerPoint animation effect. All animation effects are actually a set of behaviours composed into one strategy. You can combine behaviours into a custom animation once and reuse it in other presentations. If you add a new behaviour into a standard PowerPoint animation effect - it will be another custom animation. For example, you can add repeat behaviour to an animation to make it repeat a few times. +You can create your own **custom animations** in Aspose.Slides by combining multiple behaviors into a single effect. + +[Behavior](https://reference.aspose.com/slides/python-net/aspose.slides.animation/behavior/) is the basic building block of any PowerPoint animation effect. Every animation effect is essentially a set of behaviors arranged into one strategy or timeline. You can assemble behaviors into a custom animation once and reuse it across other presentations. If you add a new behavior to a standard PowerPoint animation effect, it becomes a custom animation—for example, adding a repeat behavior to make the animation play several times. + +[Animation Point](https://reference.aspose.com/slides/python-net/aspose.slides.animation/point/) marks the moment or position at which a behavior is applied (a keyframe). -[**Animation Point**](https://reference.aspose.com/slides/python-net/aspose.slides.animation/point/) is a point where behaviour should be applied. ## **Animation Time Line** -[**Sequence**](https://reference.aspose.com/slides/python-net/aspose.slides.animation/sequence/) is a collection of animation effects, applied on a concrete shape. -[**Timeline**](https://reference.aspose.com/slides/python-net/aspose.slides.animation/animationtimeline/) is a set of Sequences used in a concrete slide. It is an animation engine represented since PowerPoint 2002. In previous Powerpoint versions, it was challenging to add animation effects to presentation, which could be achieved only with different workarounds. Timeline comes to replace on old AnimationSettings class and provide more clear object model for PowerPoint animation. One slide can have only one animation timeline. +[Sequence](https://reference.aspose.com/slides/python-net/aspose.slides.animation/sequence/) is a collection of animation effects applied to a specific shape. + +[Timeline](https://reference.aspose.com/slides/python-net/aspose.slides.animation/animationtimeline/) is the set of sequences used on a specific slide. It was introduced in PowerPoint 2002. In earlier versions of PowerPoint, adding animation effects was difficult and often required workarounds. Timeline replaces the old `AnimationSettings` class and provides a clearer object model for PowerPoint animation. Each slide can have only one animation timeline. + ## **Interactive Animation** -[**Trigger**](https://reference.aspose.com/slides/python-net/aspose.slides.animation/effecttriggertype/) allows to define user actions (e.g. button click), that will make a certain animation start. Triggers have been added into the latest PowerPoint version only. + +[Trigger](https://reference.aspose.com/slides/python-net/aspose.slides.animation/effecttriggertype/) allows you to define user actions (e.g., a button click) that start a specific animation. Triggers were added only in the latest versions of PowerPoint. + ## **Shape Animation** -Aspose.Slides allows to apply animation to shapes, that can be actually text, rectangle, line, frame, OLE Object, etc. -{{% alert color="primary" %}} +Aspose.Slides lets you apply animations to shapes—such as text, rectangles, lines, frames, OLE objects, and more. + +{{% alert color="primary" %}} + Read more [**About Shape Animation**](/slides/python-net/shape-animation/). + {{% /alert %}} ## **Animated Charts** -To create animated charts, you should use all the same classes as for the shapes. However, it is possible to use PowerPoint animation only on chart categories or chart series. You can also apply animation effect to a category element or series element. -{{% alert color="primary" %}} +To create animated charts, use the same classes as you do for shapes. However, PowerPoint animations can be applied only to chart categories or chart series. You can also apply an animation effect to an individual category element or series element. + +{{% alert color="primary" %}} + Read more [**About Animated Charts**](/slides/python-net/animated-charts/). + {{% /alert %}} ## **Animated text** -Except animated text, it is also possible to apply animation to a paragraph. -{{% alert color="primary" %}} +In addition to animating text, you can apply animation to a paragraph. + +{{% alert color="primary" %}} + Read more [**About Animated Text**](/slides/python-net/animated-text/). -{{% /alert %}} \ No newline at end of file + +{{% /alert %}} diff --git a/en/python-net/developer-guide/presentation-content/manage-text/extract-text-from-presentation/_index.md b/en/python-net/developer-guide/presentation-content/manage-text/extract-text-from-presentation/_index.md index 266c739cc..5ca355297 100644 --- a/en/python-net/developer-guide/presentation-content/manage-text/extract-text-from-presentation/_index.md +++ b/en/python-net/developer-guide/presentation-content/manage-text/extract-text-from-presentation/_index.md @@ -29,117 +29,106 @@ keywords: description: "Learn how to quickly and easily extract text from PowerPoint presentations using Aspose.Slides for Python via .NET. Follow our simple, step-by-step guide to save time and efficiently access slide content in your applications." --- -{{% alert color="primary" %}} +## **Overview** -It's not uncommon that developers need to extract the text from a presentation. To do so, you need to extract text from all the shapes on all the slides in a presentation. This article explains how to extract text from Microsoft PowerPoint PPTX presentations using Aspose.Slides. Text can be extracted in following ways: +It’s common for developers to need to extract text from a presentation. To do this, you must pull text from every shape on every slide. This article explains how to extract text from Microsoft PowerPoint (PPTX) presentations using Aspose.Slides. Text can be extracted in the following ways: -- [Extracting text from one slide](/slides/python-net/extracting-text-from-the-presentation/) -- [Extracting text using GetAllTextBoxes method](/slides/python-net/extracting-text-from-the-presentation/) -- [Categorized and fast extraction of text](/slides/python-net/extracting-text-from-the-presentation/) +- Extracting text from a slide +- Extracting text from a presentation +- Categorized and fast text extraction + +## **Extract Text from a Slide** -{{% /alert %}} -## **Extract Text from Slide** -Aspose.Slides for Python via .NET provides the Aspose.Slides.Util namespace which includes the SlideUtil class. This class exposes a number of overloaded static methods for extracting the entire text from a presentation or slide. To extract the text from a slide in a PPTX presentation, -use the [GetAllTextBoxes](https://reference.aspose.com/slides/python-net/aspose.slides.util/slideutil/) overloaded static method exposed by the SlideUtil class. This method accepts the Slide object as a parameter. -Upon execution, the Slide method scans the entire text from the slide passed as parameter and returns an array of TextFrame objects. This means that any text formatting associated with the text is available. The following piece of code extracts all the text on the first slide of the presentation: +Aspose.Slides for Python via .NET provides the [aspose.slides.util](https://reference.aspose.com/slides/python-net/aspose.slides.util/) namespace, which includes the [SlideUtil](https://reference.aspose.com/slides/python-net/aspose.slides.util/slideutil/) class. [SlideUtil](https://reference.aspose.com/slides/python-net/aspose.slides.util/slideutil/) exposes several overloaded static methods for extracting text from an entire presentation or a single slide. To extract text from a slide in a PPTX, use the `get_all_text_boxes` method. It takes a [Slide](https://reference.aspose.com/slides/python-net/aspose.slides/slide/) object, scans the slide for text, and returns an array of [TextFrame](https://reference.aspose.com/slides/python-net/aspose.slides/textframe/) objects—so the text and its formatting are preserved. The code below extracts all text from the first slide of the presentation: ```py import aspose.slides as slides -#Instatiate Presentation class that represents a PPTX file -with slides.Presentation("pres.pptx") as pptxPresentation: - # Get an Array of ITextFrame objects from all slides in the PPTX - textFramesPPTX = slides.util.SlideUtil.get_all_text_boxes(pptxPresentation.slides[0]) - - # Loop through the Array of TextFrames - for i in range(len(textFramesPPTX)): - # Loop through paragraphs in current ITextFrame - for para in textFramesPPTX[i].paragraphs: - # Loop through portions in the current IParagraph - for port in para.portions: - # Display text in the current portion - print(port.text) - - # Display font height of the text - print(port.portion_format.font_height) - - # Display font name of the text - if port.portion_format.latin_font != None: - print(port.portion_format.latin_font.font_name) +# Instantiate the Presentation class that represents a PPTX file. +with slides.Presentation("sample.pptx") as presentation: + slide = presentation.slides[0] + # Get an array of TextFrame objects from all slides in the PPTX file. + text_frames = slides.util.SlideUtil.get_all_text_boxes(slide) + # Loop through the array of the text frames. + for text_frame in text_frames: + # Loop through paragraphs in the current text frame. + for paragraph in text_frame.paragraphs: + # Loop through text portions in the current paragraph. + for portion in paragraph.portions: + # Display the text in the current portion. + print(portion.text) + # Display the font height of the text. + print(portion.portion_format.font_height) + # Display the font name of the text. + if portion.portion_format.latin_font is not None: + print(portion.portion_format.latin_font.font_name) ``` +## **Extract Text from a Presentation** +To extract text from an entire presentation, use the `get_all_text_frames` static method of the [SlideUtil](https://reference.aspose.com/slides/python-net/aspose.slides.util/slideutil/) class. It takes two parameters: +1. A [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) object representing the PPTX to extract from. +1. A `Boolean` indicating whether to include the master slides. -## **Extract Text from Presentation** -To scan the text from the whole presentation, use the - [GetAllTextFrames](https://reference.aspose.com/slides/python-net/aspose.slides.util/slideutil/) static method exposed by the SlideUtil class. It takes two parameters: - -1. First, a Presentation object that represents the PPTX presentation the text is being extracted from. -1. Second, a Boolean value determining whether the master slide is to be included when the text is scanned from the presentation. - The method returns an array of TextFrame objects, complete with text formatting information. The code below scans the text and formatting information from a presentation, including the master slides. +The method returns an array of [TextFrame](https://reference.aspose.com/slides/python-net/aspose.slides/textframe/) objects with their formatting. The example below scans the text and formatting from a presentation, including the master slides. ```py import aspose.slides as slides -#Instatiate Presentation class that represents a PPTX file -with slides.Presentation("pres.pptx") as pptxPresentation: - # Get an Array of ITextFrame objects from all slides in the PPTX - textFramesPPTX = slides.util.SlideUtil.get_all_text_frames(pptxPresentation, True) - - # Loop through the Array of TextFrames - for i in range(len(textFramesPPTX)): - # Loop through paragraphs in current ITextFrame - for para in textFramesPPTX[i].paragraphs: - # Loop through portions in the current IParagraph - for port in para.portions: - # Display text in the current portion - print(port.text) - - # Display font height of the text - print(port.portion_format.font_height) - - # Display font name of the text - if port.portion_format.latin_font != None: - print(port.portion_format.latin_font.font_name) +# Instantiate the Presentation class that represents a PPTX file. +with slides.Presentation("pres.pptx") as presentation: + # Get an array of TextFrame objects from all slides in the PPTX file. + text_frames = slides.util.SlideUtil.get_all_text_frames(presentation, True) + # Loop through the array of text frames. + for text_frame in text_frames: + # Loop through paragraphs in the current text frame. + for paragraph in text_frame.paragraphs: + # Loop through text portions in the current paragraph. + for portion in paragraph.portions: + # Display text in the current portion. + print(portion.text) + # Display the font height of the text. + print(portion.portion_format.font_height) + # Display the font name of the text. + if portion.portion_format.latin_font is not None: + print(portion.portion_format.latin_font.font_name) ``` - - - ## **Categorized and Fast Text Extraction** -The new static method GetPresentationText has been added to Presentation class. There are two overloads for this method: + +The [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class provides a static method, `get_presentation_text`, with these overloads: ```py -slides.Presentation.get_presentation_text(stream) -slides.Presentation.get_presentation_text(stream, mode) +Presentation.get_presentation_text(stream, mode) +Presentation.get_presentation_text(file, mode) +Presentation.get_presentation_text(stream, mode, options) ``` -The ExtractionMode enum argument indicates the mode to organize the output of text result and can be set to the following values: -Unarranged - The raw text with no respect to position on the slide -Arranged - The text is positioned in the same order as on the slide +The [TextExtractionArrangingMode](https://reference.aspose.com/slides/python-net/aspose.slides/textextractionarrangingmode/) argument controls how the extracted text is organized: -Unarranged mode can be used when speed is critical, it's faster than Arranged mode. +- `UNARRANGED` — raw text with no regard to on-slide position. +- `ARRANGED` — text appears in the same order as on the slide. -PresentationText represents the raw text extracted from the presentation. It contains a `slides_text` property from Aspose.Slides.Util namespace which returns an array of SlideText objects. Every object represent the text on the corresponding slide. SlideText object have the following properties: +Use `UNARRANGED` when speed is critical; it is faster than `ARRANGED`. -SlideText.text - The text on the slide's shapes -SlideText.master_text - The text on the master page's shapes for this slide -SlideText.layout_text - The text on the layout page's shapes for this slide -SlideText.notes_text - The text on the notes page's shapes for this slide +[PresentationText](https://reference.aspose.com/slides/python-net/aspose.slides/presentationtext/) represents the raw text extracted from a presentation. It exposes the `slides_text` property, which returns an array of `SlideText` objects—each corresponding to a slide. A `SlideText` object has the following properties: +- `SlideText.text` — text from the slide’s shapes +- `SlideText.master_text` — text from the master page’s shapes for that slide +- `SlideText.layout_text` — text from the layout page’s shapes for that slide +- `SlideText.notes_text` — text from the notes page’s shapes for that slide -The new API can be used like this: +Here’s how to use the API: ```py import aspose.slides as slides -text1 = slides.PresentationFactory().get_presentation_text("pres.pptx", slides.TextExtractionArrangingMode.UNARRANGED) -print(text1.slides_text[0].text) -print(text1.slides_text[0].layout_text) -print(text1.slides_text[0].master_text) -print(text1.slides_text[0].notes_text) +arranging_mode = slides.TextExtractionArrangingMode.UNARRANGED +presentation_text = slides.PresentationFactory().get_presentation_text("sample.pptx", arranging_mode) +slide_text = presentation_text.slides_text[0] +print(slide_text.text) +print(slide_text.layout_text) +print(slide_text.master_text) +print(slide_text.notes_text) ``` - - - diff --git a/en/python-net/developer-guide/presentation-content/manage-text/manage-autofit-settings/_index.md b/en/python-net/developer-guide/presentation-content/manage-text/manage-autofit-settings/_index.md index 3cc64d58a..776c22ca4 100644 --- a/en/python-net/developer-guide/presentation-content/manage-text/manage-autofit-settings/_index.md +++ b/en/python-net/developer-guide/presentation-content/manage-text/manage-autofit-settings/_index.md @@ -35,11 +35,11 @@ In PowerPoint, these are the 4 important parameters or options that control the ![autofit-options-powerpoint](autofit-options-powerpoint.png) -Aspose.Slides for Python via .NET provides similar options—some properties under the [text_frame_format](https://reference.aspose.com/slides/python-net/aspose.slides/textframeformat/) class—that allow you to control the autofit behavior for textboxes in presentations. +Aspose.Slides for Python via .NET provides similar options—some properties under the [TextFrameFormat](https://reference.aspose.com/slides/python-net/aspose.slides/textframeformat/) class—that allow you to control the autofit behavior for textboxes in presentations. -## **Resize Shape to Fit Text** +## **Resize Shapes to Fit Text** -If you want the text in a box to always fit into that box after changes are made to the text, you have to use the **Resize shape to fix text** option. To specify this setting, set the [autofit_type](https://reference.aspose.com/slides/python-net/aspose.slides/textframeformat/) property (from the [text_frame_format](https://reference.aspose.com/slides/python-net/aspose.slides/textframeformat/) class) to `SHAPE`. +If you want the text in a box to always fit into that box after changes are made to the text, you have to use the **Resize shape to fix text** option. To specify this setting, set the [autofit_type](https://reference.aspose.com/slides/python-net/aspose.slides/textframeformat/) property from the [TextFrameFormat](https://reference.aspose.com/slides/python-net/aspose.slides/textframeformat/) class to `SHAPE`. ![alwaysfit-setting-powerpoint](alwaysfit-setting-powerpoint.png) @@ -49,26 +49,26 @@ This Python code shows you how to specify that a text must always fit into its b import aspose.slides as slides import aspose.pydrawing as draw -with slides.Presentation() as pres: - slide = pres.slides[0] - autoShape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 30, 30, 350, 100) +with slides.Presentation() as presentation: + slide = presentation.slides[0] + auto_shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 30, 30, 350, 100) portion = slides.Portion("lorem ipsum...") portion.portion_format.fill_format.solid_fill_color.color = draw.Color.black portion.portion_format.fill_format.fill_type = slides.FillType.SOLID - autoShape.text_frame.paragraphs[0].portions.add(portion) + auto_shape.text_frame.paragraphs[0].portions.add(portion) - textFrameFormat = autoShape.text_frame.text_frame_format - textFrameFormat.autofit_type = slides.TextAutofitType.SHAPE + text_frame_format = auto_shape.text_frame.text_frame_format + text_frame_format.autofit_type = slides.TextAutofitType.SHAPE - pres.save("Output-presentation.pptx", slides.export.SaveFormat.PPTX) + presentation.save("output.pptx", slides.export.SaveFormat.PPTX) ``` If the text becomes longer or bigger, the textbox will be automatically resized (increase in height) to ensure all the text fits into it. If the text becomes shorter, the reverse occurs. ## **Do Not Autofit** -If you want a textbox or shape to retain its dimensions no matter the changes made to the text it contains, you have to use the **Do not Autofit** option. To specify this setting, set the [autofit_type](https://reference.aspose.com/slides/python-net/aspose.slides/textframeformat/) property (from the [text_frame_format](https://reference.aspose.com/slides/python-net/aspose.slides/textframeformat/) class) to `NONE`. +If you want a textbox or shape to retain its dimensions no matter the changes made to the text it contains, you have to use the **Do not Autofit** option. To specify this setting, set the [autofit_type](https://reference.aspose.com/slides/python-net/aspose.slides/textframeformat/) property from the [TextFrameFormat](https://reference.aspose.com/slides/python-net/aspose.slides/textframeformat/) class to `NONE`. ![donotautofit-setting-powerpoint](donotautofit-setting-powerpoint.png) @@ -78,26 +78,26 @@ This Python code shows you how to specify that a textbox must always retain its import aspose.slides as slides import aspose.pydrawing as draw -with slides.Presentation() as pres: - slide = pres.slides[0] - autoShape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 30, 30, 350, 100) +with slides.Presentation() as presentation: + slide = presentation.slides[0] + auto_shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 30, 30, 350, 100) portion = slides.Portion("lorem ipsum...") portion.portion_format.fill_format.solid_fill_color.color = draw.Color.black portion.portion_format.fill_format.fill_type = slides.FillType.SOLID - autoShape.text_frame.paragraphs[0].portions.add(portion) + auto_shape.text_frame.paragraphs[0].portions.add(portion) - textFrameFormat = autoShape.text_frame.text_frame_format - textFrameFormat.autofit_type = slides.TextAutofitType.NONE + text_frame_format = auto_shape.text_frame.text_frame_format + text_frame_format.autofit_type = slides.TextAutofitType.NONE - pres.save("Output-presentation.pptx", slides.export.SaveFormat.PPTX) + presentation.save("output.pptx", slides.export.SaveFormat.PPTX) ``` When the text becomes too long for its box, it spills out. ## **Shrink Text on Overflow** -If a text becomes too long for its box, through the **Shrink text on overflow** option, you can specify that the text's size and spacing must be reduced to make it fit into its box. To specify this setting, set the [autofit_type](https://reference.aspose.com/slides/python-net/aspose.slides/textframeformat/) property (from the [text_frame_format](https://reference.aspose.com/slides/python-net/aspose.slides/textframeformat/) class) to `NORMAL`. +If a text becomes too long for its box, through the **Shrink text on overflow** option, you can specify that the text's size and spacing must be reduced to make it fit into its box. To specify this setting, set the [autofit_type](https://reference.aspose.com/slides/python-net/aspose.slides/textframeformat/) property from the [TextFrameFormat](https://reference.aspose.com/slides/python-net/aspose.slides/textframeformat/) class to `NORMAL`. ![shrinktextonoverflow-setting-powerpoint](shrinktextonoverflow-setting-powerpoint.png) @@ -107,19 +107,19 @@ This Python code shows you how to specify that a text must be shrunk on overflow import aspose.slides as slides import aspose.pydrawing as draw -with slides.Presentation() as pres: - slide = pres.slides[0] - autoShape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 30, 30, 350, 100) +with slides.Presentation() as presentation: + slide = presentation.slides[0] + auto_shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 30, 30, 350, 100) portion = slides.Portion("lorem ipsum...") portion.portion_format.fill_format.solid_fill_color.color = draw.Color.black portion.portion_format.fill_format.fill_type = slides.FillType.SOLID - autoShape.text_frame.paragraphs[0].portions.add(portion) + auto_shape.text_frame.paragraphs[0].portions.add(portion) - textFrameFormat = autoShape.text_frame.text_frame_format - textFrameFormat.autofit_type = slides.TextAutofitType.NORMAL + text_frame_format = auto_shape.text_frame.text_frame_format + text_frame_format.autofit_type = slides.TextAutofitType.NORMAL - pres.save("Output-presentation.pptx", slides.export.SaveFormat.PPTX) + presentation.save("output.pptx", slides.export.SaveFormat.PPTX) ``` {{% alert title="Info" color="info" %}} @@ -130,7 +130,7 @@ When the **Shrink text on overflow** option is used, the setting gets applied on ## **Wrap Text** -If you want the text in a shape to get wrapped inside that shape when the text goes beyond the shape's border (width only), you have to use the **Wrap text in shape** parameter. To specify this setting, you have to set the [wrap_text](https://reference.aspose.com/slides/python-net/aspose.slides/textframeformat/) property (from the [TextFrameFormat](https://reference.aspose.com/slides/python-net/aspose.slides/textframeformat/) class) to `1`. +If you want the text in a shape to get wrapped inside that shape when the text goes beyond the shape's border (width only), you have to use the **Wrap text in shape** parameter. To specify this setting, you have to set the [wrap_text](https://reference.aspose.com/slides/python-net/aspose.slides/textframeformat/) property from the [TextFrameFormat](https://reference.aspose.com/slides/python-net/aspose.slides/textframeformat/) class to `NullableBool.TRUE`. This Python code shows you how to use the Wrap Text setting in a PowerPoint presentation: @@ -138,29 +138,24 @@ This Python code shows you how to use the Wrap Text setting in a PowerPoint pres import aspose.slides as slides import aspose.pydrawing as draw -with slides.Presentation() as pres: - slide = pres.slides[0] - autoShape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 30, 30, 350, 100) +with slides.Presentation() as presentation: + slide = presentation.slides[0] + auto_shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 30, 30, 350, 100) portion = slides.Portion("lorem ipsum...") portion.portion_format.fill_format.solid_fill_color.color = draw.Color.black portion.portion_format.fill_format.fill_type = slides.FillType.SOLID - autoShape.text_frame.paragraphs[0].portions.add(portion) + auto_shape.text_frame.paragraphs[0].portions.add(portion) - textFrameFormat = autoShape.text_frame.text_frame_format - textFrameFormat.autofit_type = slides.TextAutofitType.NONE - textFrameFormat.wrap_text = 1 + text_frame_format = auto_shape.text_frame.text_frame_format + text_frame_format.autofit_type = slides.TextAutofitType.NONE + text_frame_format.wrap_text = slides.NullableBool.TRUE - pres.save("Output-presentation.pptx", slides.export.SaveFormat.PPTX) + presentation.save("output.pptx", slides.export.SaveFormat.PPTX) ``` {{% alert title="Note" color="warning" %}} -If you set the `wrap_text` property to `0` for a shape, when the text inside the shape becomes longer than the shape's width, the text gets extended beyond the shape's borders along a single line. +If you set the `wrap_text` property to `NullableBool.FALSE` for a shape, when the text inside the shape becomes longer than the shape's width, the text gets extended beyond the shape's borders along a single line. {{% /alert %}} - - - - - diff --git a/en/python-net/developer-guide/presentation-content/manage-text/manage-autofit-settings/alwaysfit-setting-powerpoint.png b/en/python-net/developer-guide/presentation-content/manage-text/manage-autofit-settings/alwaysfit-setting-powerpoint.png index 3bb347702..e01b360b3 100644 Binary files a/en/python-net/developer-guide/presentation-content/manage-text/manage-autofit-settings/alwaysfit-setting-powerpoint.png and b/en/python-net/developer-guide/presentation-content/manage-text/manage-autofit-settings/alwaysfit-setting-powerpoint.png differ diff --git a/en/python-net/developer-guide/presentation-content/manage-text/manage-autofit-settings/donotautofit-setting-powerpoint.png b/en/python-net/developer-guide/presentation-content/manage-text/manage-autofit-settings/donotautofit-setting-powerpoint.png index e6a7fe7af..ef131ed36 100644 Binary files a/en/python-net/developer-guide/presentation-content/manage-text/manage-autofit-settings/donotautofit-setting-powerpoint.png and b/en/python-net/developer-guide/presentation-content/manage-text/manage-autofit-settings/donotautofit-setting-powerpoint.png differ diff --git a/en/python-net/developer-guide/presentation-content/manage-text/manage-autofit-settings/shrinktextonoverflow-setting-powerpoint.png b/en/python-net/developer-guide/presentation-content/manage-text/manage-autofit-settings/shrinktextonoverflow-setting-powerpoint.png index 4a2a9e200..4bd737e6f 100644 Binary files a/en/python-net/developer-guide/presentation-content/manage-text/manage-autofit-settings/shrinktextonoverflow-setting-powerpoint.png and b/en/python-net/developer-guide/presentation-content/manage-text/manage-autofit-settings/shrinktextonoverflow-setting-powerpoint.png differ diff --git a/en/python-net/developer-guide/presentation-content/manage-text/manage-autofit-settings/textbox-in-powerpoint.png b/en/python-net/developer-guide/presentation-content/manage-text/manage-autofit-settings/textbox-in-powerpoint.png index f362b610f..0ade669b9 100644 Binary files a/en/python-net/developer-guide/presentation-content/manage-text/manage-autofit-settings/textbox-in-powerpoint.png and b/en/python-net/developer-guide/presentation-content/manage-text/manage-autofit-settings/textbox-in-powerpoint.png differ diff --git a/en/python-net/developer-guide/presentation-content/manage-text/superscript-and-subscript/_index.md b/en/python-net/developer-guide/presentation-content/manage-text/superscript-and-subscript/_index.md index bd890f920..e66204227 100644 --- a/en/python-net/developer-guide/presentation-content/manage-text/superscript-and-subscript/_index.md +++ b/en/python-net/developer-guide/presentation-content/manage-text/superscript-and-subscript/_index.md @@ -17,72 +17,65 @@ keywords: description: "Master superscript and subscript in Aspose.Slides for Python via .NET and elevate your presentations with professional text formatting for maximum impact." --- -## **Manage Super Script and Sub Script Text** -You can add superscript and subscript text inside any paragraph portion. For adding Superscript or Subscript text in Aspose.Slides text frame one must use **the Escapement** properties of PortionFormat class. - -This property returns or sets the superscript or subscript text (value from -100% (subscript) to 100% (superscript). For example : - -- Create an instance of [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class. -- Obtain the reference of a slide by using its Index. -- Add an IAutoShape of Rectangle type to the slide. -- Access the ITextFrame associated with the IAutoShape. -- Clear existing Paragraphs -- Create a new paragraph object for holding superscript text and add it to the IParagraphs collection of the ITextFrame. -- Create a new portion object -- Set Escapement property for the portion between 0 to 100 for adding superscript. (0 mean no superscript) -- Set some text for Portion and then add that in portion collection of paragraph. -- Create a new paragraph object for holding subscript text and add it to the IParagraphs collection of the ITextFrame. -- Create a new portion object -- Set Escapement property for portion between 0 to -100 for adding superscript. (0 mean no subscript) -- Set some text for Portion and then add that in portion collection of paragraph. -- Save the presentation as a PPTX file. - -The implementation of the above steps is given below. +You can add superscript and subscript text to any paragraph portion. In Aspose.Slides, use the `escapement` property of the [PortionFormat](https://reference.aspose.com/slides/python-net/aspose.slides/portionformat/) class to control this. + +`escapement` is a percentage from **-100% to 100%**: + +- **> 0** → superscript (e.g., 25% = slight raise; 100% = full superscript) +- **0** → baseline (no super/subscript) +- **< 0** → subscript (e.g., -25% = slight lower; -100% = full subscript) + +Steps: + +1. Create a [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) and get a slide. +1. Add a rectangle [AutoShape](https://reference.aspose.com/slides/python-net/aspose.slides/autoshape/) and access its [TextFrame](https://reference.aspose.com/slides/python-net/aspose.slides/textframe/). +1. Clear existing paragraphs. +1. For superscript: create a paragraph and a portion, set `portion.portion_format.escapement` to a value between **0 and 100**, set text, and add the portion. +1. For subscript: create another paragraph and portion, set `escapement` to a value between **-100 and 0**, set text, and add the portion. +1. Save the presentation as PPTX. ```py import aspose.slides as slides with slides.Presentation("pres.pptx") as presentation: - # Get slide + # Get a slide. slide = presentation.slides[0] - # Create text box + # Create a text box. shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 100, 100, 200, 100) - textFrame = shape.text_frame - textFrame.paragraphs.clear() + shape.text_frame.paragraphs.clear() - # Create paragraph for superscript text - superPar = slides.Paragraph() + # Create a paragraph for superscript text. + superscript_paragraph = slides.Paragraph() - # Create portion with usual text + # Create a text portion with regular text. portion1 = slides.Portion() portion1.text = "SlideTitle" - superPar.portions.add(portion1) + superscript_paragraph.portions.add(portion1) - # Create portion with superscript text - superPortion = slides.Portion() - superPortion.portion_format.escapement = 30 - superPortion.text = "TM" - superPar.portions.add(superPortion) + # Create a text portion with superscript text. + superscript_portion = slides.Portion() + superscript_portion.portion_format.escapement = 30 + superscript_portion.text = "TM" + superscript_paragraph.portions.add(superscript_portion) - # Create paragraph for subscript text - paragraph2 = slides.Paragraph() + # Create a paragraph for the subscript text. + subscript_paragraph = slides.Paragraph() - # Create portion with usual text + # Create a text portion with regular text. portion2 = slides.Portion() portion2.text = "a" - paragraph2.portions.add(portion2) + subscript_paragraph.portions.add(portion2) - # Create portion with subscript text - subPortion = slides.Portion() - subPortion.portion_format.escapement = -25 - subPortion.text = "i" - paragraph2.portions.add(subPortion) + # Create a text portion with subscript text. + subscript_portion = slides.Portion() + subscript_portion.portion_format.escapement = -25 + subscript_portion.text = "i" + subscript_paragraph.portions.add(subscript_portion) - # Add paragraphs to text box - textFrame.paragraphs.add(superPar) - textFrame.paragraphs.add(paragraph2) + # Add the paragraphs to the text box. + shape.text_frame.paragraphs.add(superscript_paragraph) + shape.text_frame.paragraphs.add(subscript_paragraph) presentation.save("TestOut.pptx", slides.export.SaveFormat.PPTX) ``` - diff --git a/en/python-net/developer-guide/presentation-content/manage-text/text-formatting/_index.md b/en/python-net/developer-guide/presentation-content/manage-text/text-formatting/_index.md index ea39df461..c8df50abb 100644 --- a/en/python-net/developer-guide/presentation-content/manage-text/text-formatting/_index.md +++ b/en/python-net/developer-guide/presentation-content/manage-text/text-formatting/_index.md @@ -31,17 +31,16 @@ description: "Learn how to format and style text in PowerPoint and OpenDocument --- ## **Highlight Text** -New HighlightText method has been added to ITextFrame interface and TextFrame class. -It allows to highlight text part with background color using text sample, similar to Text Highlight Color tool in PowerPoint 2019. +The `highlight_text` method in the [TextFrame](https://reference.aspose.com/slides/python-net/aspose.slides/textframe/) class allows you to highlight a part of the text with a background color using a text sample, similar to the Text Highlight Color tool in PowerPoint 2019. -The code snippet below shows how to use this feature: +The following code snippet shows how to use this feature: ```py import aspose.slides as slides import aspose.pydrawing as draw -with slides.Presentation(path + "SomePresentation.pptx") as presentation: +with slides.Presentation("SomePresentation.pptx") as presentation: presentation.slides[0].shapes[0].text_frame.highlight_text("title", draw.Color.light_blue) opts = slides.TextHighlightingOptions() @@ -51,18 +50,9 @@ with slides.Presentation(path + "SomePresentation.pptx") as presentation: presentation.save("SomePresentation-out2.pptx", slides.export.SaveFormat.PPTX) ``` -{{% alert color="primary" %}} - -Aspose provides a simple, [free online PowerPoint editing service](https://products.aspose.app/slides/editor). - -{{% /alert %}} - - -## **Highlight Text using Regular Expression** -New HighlightRegex method has been added to ITextFrame interface and TextFrame class. - -It allows to highlight text part with background color using regex, similar to Text Highlight Color tool in PowerPoint 2019. +## **Highlight Text Using Regular Expressions** +The `highlight_regex` method of the [TextFrame](https://reference.aspose.com/slides/python-net/aspose.slides/textframe/) class lets you highlight a portion of text with a background color using a regular expression, similar to the Text Highlight Color tool in PowerPoint 2019. The code snippet below shows how to use this feature: @@ -70,19 +60,16 @@ The code snippet below shows how to use this feature: import aspose.slides as slides import aspose.pydrawing as draw -with slides.Presentation(path + "SomePresentation.pptx") as presentation: +with slides.Presentation("SomePresentation.pptx") as presentation: options = slides.TextHighlightingOptions() presentation.slides[0].shapes[0].text_frame.highlight_regex("\\b[^\s]{5,}\\b", draw.Color.blue, options) presentation.save("SomePresentation-out3.pptx", slides.export.SaveFormat.PPTX) ``` - ## **Set Text Background Color** -Aspose.Slides allows you to specify your preferred color for the background of a text. - -This Python code shows you how to set the background color for an entire text: +Aspose.Slides allows you to specify your preferred background color for text. The Python code below shows how to set the background color for the entire text: ```python import aspose.slides as slides @@ -118,7 +105,7 @@ with slides.Presentation("text.pptx") as pres: pres.save("text-red.pptx", slides.export.SaveFormat.PPTX) ``` -This Python code shows you how to set the background color for only a portion of a text: +This Python code shows how to set the background color for only a portion of the text: ```python import aspose.slides as slides @@ -157,24 +144,24 @@ with slides.Presentation("text.pptx") as pres: pres.save("text-red.pptx", slides.export.SaveFormat.PPTX) ``` - ## **Align Text Paragraphs** -Text formatting is one of the key elements while creating any kind of documents or presentations. We know that Aspose.Slides for Python via .NET supports adding text to slides but in this topic, we will see that how can we control the alignment of the text paragraphs in a slide. Please follow the steps below to align text paragraphs using Aspose.Slides for Python via .NET : -1. Create an instance of [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class. -2. Obtain the reference of a slide by using its Index. -3. Access the Placeholder shapes present in the slide and typecast them as a AutoShape. -4. Get the Paragraph (that needs to be aligned) from the TextFrame exposed by AutoShape. -5. Align the Paragraph. A paragraph can be aligned to Right, Left, Center & Justify. -6. Write the modified presentation as a PPTX file. +Text formatting is a key element when creating documents or presentations. Aspose.Slides for Python via .NET supports adding text to slides; in this section, we’ll see how to control paragraph alignment in a slide. Follow these steps to align text paragraphs using Aspose.Slides for Python via .NET: + +1. Create an instance of the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class. +1. Get a reference to a slide by its index. +1. Access the placeholder shapes on the slide and cast them to [AutoShape](https://reference.aspose.com/slides/python-net/aspose.slides/autoshape/). +1. From the [TextFrame](https://reference.aspose.com/slides/python-net/aspose.slides/textframe/) exposed by the [AutoShape](https://reference.aspose.com/slides/python-net/aspose.slides/autoshape/), get the paragraph that needs to be aligned. +1. Align the paragraph. A paragraph can be aligned `LEFT`, `RIGHT`, `CENTER`, `JUSTIFY`, `JUSTIFY_LOW`, or `DISTRIBUTED`. +1. Save the modified presentation as a PPTX file. -The implementation of the above steps is given below. +The implementation of these steps is shown below. ```py import aspose.slides as slides # Instantiate a Presentation object that represents a PPTX file -with slides.Presentation(path + "ParagraphsAlignment.pptx") as presentation: +with slides.Presentation("ParagraphsAlignment.pptx") as presentation: # Accessing first slide slide = presentation.slides[0] @@ -198,22 +185,22 @@ with slides.Presentation(path + "ParagraphsAlignment.pptx") as presentation: presentation.save("Centeralign_out.pptx", slides.export.SaveFormat.PPTX) ``` +## **Set Text Transparency** -## **Set Transparency for Text** -This article demonstrates how to set transparency property to any text shape using Aspose.Slides for Python via .NET. In order to set the transparency to text. Please follow the steps below: +This section demonstrates how to set the transparency property for any text shape using Aspose.Slides for Python via .NET. To set text transparency, follow these steps: -1. Create an instance of [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class. -2. Get the reference of a slide. -3. Set shadow color -4. Write the presentation as a PPTX file. +1. Create an instance of the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class. +1. Get a reference to a slide. +1. Set the shadow color. +1. Save the presentation as a PPTX file. -The implementation of the above steps is given below. +The implementation of these steps is given below. ```py import aspose.slides as slides import aspose.pydrawing as draw -with slides.Presentation(path + "transparency.pptx") as pres: +with slides.Presentation("transparency.pptx") as pres: shape = pres.slides[0].shapes[0] effects = shape.text_frame.paragraphs[0].portions[0].portion_format.effect_format @@ -227,12 +214,11 @@ with slides.Presentation(path + "transparency.pptx") as pres: pres.save("transparency-2.pptx", slides.export.SaveFormat.PPTX) ``` +## **Set Text Character Spacing** -## **Set Character Spacing for Text** - -Aspose.Slides allows you to set the space between letters in a textbox. This way, you get to adjust the visual density of a line or block of text by expanding or condensing the spacing between characters. +Aspose.Slides lets you adjust the spacing between letters in a text box. This allows you to control the visual density of a line or block of text by expanding or condensing the spacing between characters. -This Python code shows you how to expand the spacing for one line of text and condense the spacing for another line: +The Python example below shows how to expand the spacing for one line of text and condense it for another: ```python import aspose.slides as slides @@ -248,30 +234,32 @@ with slides.Presentation("in.pptx") as pres: pres.save("out.pptx", slides.export.SaveFormat.PPTX) ``` +## **Manage Paragraph Font Properties** -## **Manage Paragraph's Font Properties** -Presentations usually contain both text and images. The text can be formatted in a various ways, either to highlight specific sections and words, or to conform with corporate styles. Text formatting helps users vary the look and feel of the presentation content. This article shows how to use Aspose.Slides for Python via .NET to configure the font properties of paragraphs of text on slides. To manage font properties of a paragraph using Aspose.Slides for Python via .NET : +Presentations usually contain both text and images. The text can be formatted in various ways—either to highlight specific sections and words or to conform to corporate styles. Text formatting helps users change the look and feel of the presentation content. + +This section demonstrates how to use Aspose.Slides for Python via .NET to configure the font properties of paragraphs in slide text. To manage a paragraph’s font properties using Aspose.Slides for Python via .NET: 1. Create an instance of the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class. -1. Obtain a slide's reference by using its index. -1. Access the Placeholder shapes in the slide and typecast them to AutoShape. -1. Get the Paragraph from the TextFrame exposed by AutoShape. +1. Get a reference to a slide by using its index. +1. Access the placeholder shapes on the slide and cast them to [AutoShape](https://reference.aspose.com/slides/python-net/aspose.slides/autoshape/). +1. Get the paragraph from the [TextFrame](https://reference.aspose.com/slides/python-net/aspose.slides/textframe/) exposed by [AutoShape](https://reference.aspose.com/slides/python-net/aspose.slides/autoshape/). 1. Justify the paragraph. -1. Access a Paragraph's text Portion. -1. Define the font using FontData and set the Font of the text Portion accordingly. +1. Access the paragraph’s text portion. +1. Define the font using [FontData](https://reference.aspose.com/slides/python-net/aspose.slides/fontdata/) and set the font of the text portion accordingly. 1. Set the font to bold. 1. Set the font to italic. -1. Set the font color using the FillFormat exposed by the Portion object. -1. Write the modified presentation to a [PPTX](https://docs.fileformat.com/presentation/pptx/) file. +1. Set the font color using the [FillFormat](https://reference.aspose.com/slides/python-net/aspose.slides/fillformat/) exposed by the [Portion](https://reference.aspose.com/slides/python-net/aspose.slides/portion/) object. +1. Save the modified presentation as a PPTX file. -The implementation of the above steps is given below. It takes an unadorned presentation and formats the fonts on one of the slides. +The implementation of the above steps is shown below. It takes a plain presentation and applies font formatting to one of the slides. ```py import aspose.slides as slides import aspose.pydrawing as draw # Instantiate a Presentation object that represents a PPTX file -with slides.Presentation(path + "FontProperties.pptx") as pres: +with slides.Presentation("FontProperties.pptx") as pres: # Accessing a slide using its slide position slide = pres.slides[0] @@ -313,22 +301,24 @@ with slides.Presentation(path + "FontProperties.pptx") as pres: pres.save("WelcomeFont_out.pptx", slides.export.SaveFormat.PPTX) ``` +## **Manage the Font Family of Text** + +[Portion](https://reference.aspose.com/slides/python-net/aspose.slides/portion/) objects are used to hold text with a similar formatting style within a paragraph. This section demonstrates how to use Aspose.Slides for Python to create a text box, add text to it, and then define a specific font along with various other font family properties. -## **Manage Font Family of Text** -A Portion is used to hold text with similar formatting style in a paragraph. This article shows how to use Aspose.Slides for Python to create a textbox with some text and then define a particular font, and various other properties of the font family category. To create a textbox and set font properties of the text in it:: +To create a text box and set the font properties of the text inside it: 1. Create an instance of the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class. -2. Obtain the reference of a slide by using its index. -3. Add an AutoShape of the type Rectangle to the slide. -4. Remove the fill style associated with the AutoShape. -5. Access the AutoShape's TextFrame. -6. Add some text to the TextFrame. -7. Access the Portion object associated with the TextFrame. -8. Define the font to be used for the Portion. -9. Set other font properties like bold, italic, underline, color and height using the relevant properties as exposed by the Portion object. -10. Write the modified presentation as a PPTX file. - -The implementation of the above steps is given below. +1. Get a reference to a slide by its index. +1. Add an [AutoShape](https://reference.aspose.com/slides/python-net/aspose.slides/autoshape/) of type `RECTANGLE` to the slide. +1. Remove the fill style associated with the [AutoShape](https://reference.aspose.com/slides/python-net/aspose.slides/autoshape/). +1. Access the AutoShape’s [TextFrame](https://reference.aspose.com/slides/python-net/aspose.slides/textframe/). +1. Add text to the [TextFrame](https://reference.aspose.com/slides/python-net/aspose.slides/textframe/). +1. Access the [Portion](https://reference.aspose.com/slides/python-net/aspose.slides/portion/) object associated with the [TextFrame](https://reference.aspose.com/slides/python-net/aspose.slides/textframe/). +1. Define the font to be used for the [Portion](https://reference.aspose.com/slides/python-net/aspose.slides/portion/). +1. Set other font properties such as bold, italic, underline, color, and height using the relevant properties exposed by the [Portion](https://reference.aspose.com/slides/python-net/aspose.slides/portion/) object. +1. Save the modified presentation as a PPTX file. + +The implementation of the above steps is shown below. ```py import aspose.slides as slides @@ -376,11 +366,11 @@ with slides.Presentation() as presentation: ``` -## **Set Font Size for Text** +## **Set the Font Size for Text** -Aspose.Slides allows you to choose your preferred font size for existing text in a paragraph and other texts that may be added to the paragraph later. +Aspose.Slides allows you to set your preferred font size for existing text in a paragraph, as well as for any text that may be added to the paragraph later. -This Python code shows you how to set the font size for texts contained in a paragraph: +This Python example demonstrates how to set the font size for text contained in a paragraph: ```python import aspose.slides as slides @@ -405,16 +395,18 @@ with slides.Presentation("pres.pptx") as presentation: ``` - ## **Set Text Rotation** -Aspose.Slides for Python via .NET allows developers to rotate the text. Text could be set to appear as Horizontal, Vertical, Vertical270, WordArtVertical, EastAsianVertical, MongolianVertical or WordArtVerticalRightToLeft. To rotate the text of any TextFrame, please follow the steps below: -1. Create an instance of [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class. -2. Access the first slide. -3. Add any Shape to the slide. -4. Access the TextFrame. -5. Rotate the text. -6. Save file to disk. +Aspose.Slides for Python via .NET allows developers to rotate text. Text can be set to appear as `HORIZONTAL`, `VERTICAL`, `VERTICAL270`, `WORD_ART_VERTICAL`, `EAST_ASIAN_VERTICAL`, `MONGOLIAN_VERTICAL`, or `WORD_ART_VERTICAL_RIGHT_TO_LEFT`. + +To rotate the text in any [TextFrame](https://reference.aspose.com/slides/python-net/aspose.slides/textframe/), follow these steps: + +1. Create an instance of the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class. +1. Access the first slide. +1. Add a shape to the slide. +1. Access the [TextFrame](https://reference.aspose.com/slides/python-net/aspose.slides/textframe/). +1. Apply the desired text rotation. +1. Save the file to disk. ```py import aspose.slides as slides @@ -449,16 +441,18 @@ with slides.Presentation() as presentation: presentation.save("RotateText_out.pptx", slides.export.SaveFormat.PPTX) ``` +## **Set a Custom Rotation Angle for a TextFrame** -## **Set Custom Rotation Angle for TextFrame** -Aspose.Slides for Python via .NET now supports, Setting custom rotation angle for textframe. In this topic, we will see with example how to set the RotationAngle property in Aspose.Slides. The new property RotationAngle has been added to IChartTextBlockFormat and ITextFrameFormat interfaces, allows to set the custom rotation angle for textframe. In order to set the RotationAngle property, Please follow the steps below: +Aspose.Slides for Python via .NET supports setting a custom rotation angle for a [TextFrame](https://reference.aspose.com/slides/python-net/aspose.slides/textframe/). In this section, we will demonstrate how to use the `rotation_angle` property in Aspose.Slides. -1. Create an instance of [Presentation ](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/)class. -2. Add a chart on slide. -3. Set RotationAngle property. -4. Write the presentation as a PPTX file. +To set the `rotation_angle` property, follow these steps: -In the example given below, we set the RotationAngle property. +1. Create an instance of the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class. +1. Add a chart to the slide. +1. Set the `rotation_angle` property. +1. Save the presentation as a PPTX file. + +In the example below, we set the `rotation_angle` property. ```py import aspose.slides as slides @@ -479,33 +473,33 @@ with slides.Presentation() as presentation: presentation.save("textframe-rotation_out.pptx", slides.export.SaveFormat.PPTX) ``` +## **Set the Line Spacing of Paragraphs** -## **Line Spacing of Paragraph** -Aspose.Slides provides properties under `paragraph_format`—`space_after`, `space_before` and `space_within`—that allow you to manage the line spacing for a paragraph. The three properties are used this way: +Aspose.Slides provides the `space_after`, `space_before`, and `space_within` properties under the [ParagraphFormat](https://reference.aspose.com/slides/python-net/aspose.slides/paragraphformat/) class to control a paragraph’s line spacing. These properties work as follows: -* To specify the line spacing for a paragraph in percentage, use a positive value. -* To specify the line spacing for a paragraph in points, use a negative value. +* To specify line spacing as a percentage, use a positive value. +* To specify line spacing in points, use a negative value. -For example, you can apply a 16pt line spacing for a paragraph by setting the `space_before` property to -16. +For example, to apply a 16 pt line spacing before a paragraph, set the `space_before` property to `-16`. -This is how you specify the line spacing for a specific paragraph: +Here’s how to set the line spacing for a specific paragraph: -1. Load a presentation containing an AutoShape with some text in it. -2. Get a slide's reference through its index. -3. Access the TextFrame. -4. Access the Paragraph. -5. Set the Paragraph properties. -6. Save the presentation. +1. Load a presentation that contains an [AutoShape](https://reference.aspose.com/slides/python-net/aspose.slides/autoshape/) with text. +1. Get a reference to the slide by its index. +1. Access the [TextFrame](https://reference.aspose.com/slides/python-net/aspose.slides/textframe/). +1. Access the [Paragraph](https://reference.aspose.com/slides/python-net/aspose.slides/paragraph/). +1. Set the desired paragraph properties. +1. Save the presentation. -This Python code shows you how to specify the line spacing for a paragraph: +The following Python example demonstrates how to set the line spacing for a paragraph: ```py import aspose.slides as slides # Create an instance of Presentation class -with slides.Presentation(path + "Fonts.pptx") as presentation: +with slides.Presentation("Fonts.pptx") as presentation: - # Obtain a slide's reference by its index + # Get a slide's reference by its index sld = presentation.slides[0] # Access the TextFrame @@ -522,16 +516,23 @@ with slides.Presentation(path + "Fonts.pptx") as presentation: presentation.save("LineSpacing_out.pptx", slides.export.SaveFormat.PPTX) ``` - ## **Set the AutofitType Property for TextFrame** -In this topic, we will explore the different formatting properties of text frame. This article covers how to Set the AutofitType property of text frame, anchor of text and rotating the text in presentation. Aspose.Slides for Python via .NET allows developers to set AutofitType property of any text frame. AutofitType could be set to Normal or Shape. If set to Normal then shape will remain the same whereas the text will be adjusted without causing the shape to change itself whereas If AutofitType is set to shape, then shape will be modified such that only required text is contained in it. To set the AutofitType property of a text frame, please follow the steps below: -1. Create an instance of [Presentation ](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/)class. -2. Access the first slide. -3. Add any shape to the slide. -4. Access the TextFrame. -5. Set the AutofitType of the TextFrame. -6. Save file to disk. +In this section, we will explore various formatting properties of a [TextFrame](https://reference.aspose.com/slides/python-net/aspose.slides/textframe/), including how to set its `autofit_type`, adjust the text anchor, and rotate text in a presentation. + +Aspose.Slides for Python via .NET allows developers to set the `autofit_type` property of any [TextFrame](https://reference.aspose.com/slides/python-net/aspose.slides/textframe/). The `autofit_type` can be set to either `NORMAL` or `SHAPE`: + +* If set to `NORMAL`, the shape remains unchanged while the text is adjusted to fit within it. +* If set to `SHAPE`, the shape is resized so that it contains only the required text. + +To set the `autofit_type` property of a [TextFrame](https://reference.aspose.com/slides/python-net/aspose.slides/textframe/), follow these steps: + +1. Create an instance of the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class. +1. Access the first slide. +1. Add a shape to the slide. +1. Access the [TextFrame](https://reference.aspose.com/slides/python-net/aspose.slides/textframe/). +1. Set the `autofit_type` for the [TextFrame](https://reference.aspose.com/slides/python-net/aspose.slides/textframe/). +1. Save the file to disk. ```py import aspose.slides as slides @@ -567,16 +568,18 @@ with slides.Presentation() as presentation: presentation.save("formatText_out.pptx", slides.export.SaveFormat.PPTX) ``` +## **Set the Anchor of a TextFrame** + +Aspose.Slides for Python via .NET allows developers to set the anchor position of any [TextFrame](https://reference.aspose.com/slides/python-net/aspose.slides/textframe/). The [TextAnchorType](https://reference.aspose.com/slides/python-net/aspose.slides/textanchortype/) property specifies where the text is placed within the shape. It can be set to `TOP`, `CENTER`, `BOTTOM`, `JUSTIFIED`, or `DISTRIBUTED`. -## **Set Anchor of TextFrame** -Aspose.Slides for Python via .NET allows developers to Anchor of any TextFrame. TextAnchorType specifies that where is that text placed in the shape. TextAnchorType could be set to Top, Center, Bottom, Justified or Distributed. To set Anchor of any TextFrame, please follow the steps below: +To set the anchor of a [TextFrame](https://reference.aspose.com/slides/python-net/aspose.slides/textframe/), follow these steps: -1. Create an instance of [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class. -2. Access the first slide. -3. Add any shape to the slide. -4. Access the TextFrame. -5. Set TextAnchorType of the TextFrame. -6. Save file to disk. +1. Create an instance of the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class. +1. Access the first slide. +1. Add a shape to the slide. +1. Access the [TextFrame](https://reference.aspose.com/slides/python-net/aspose.slides/textframe/). +1. Set the [TextAnchorType](https://reference.aspose.com/slides/python-net/aspose.slides/textanchortype/) for the [TextFrame](https://reference.aspose.com/slides/python-net/aspose.slides/textframe/). +1. Save the file to disk. ```py import aspose.slides as slides @@ -611,19 +614,11 @@ with slides.Presentation() as presentation: presentation.save("AnchorText_out.pptx", slides.export.SaveFormat.PPTX) ``` +## **Set the Default Text Style** -## **Set Text Tabulation** -- EffectiveTabs.ExplicitTabCount (2 in our case) property is equal to Tabs.Count. -- EffectiveTabs collection includes all tabs (from Tabs collection and default tabs) -- EffectiveTabs.ExplicitTabCount (2 in our case) property is equal to Tabs.Count. -- EffectiveTabs.DefaultTabSize (294) property shows distance between default tabs (3 and 4 in our example). -- EffectiveTabs.GetTabByIndex(index) with index = 0 will return first explicit tab (Position = 731), index = 1 - second tab (Position = 1241). If you try to get next tab with index = 2 it will return first default tab (Position = 1470) and etc. -- EffectiveTabs.GetTabAfterPosition(pos) used for getting next tabulation after some text. For example you have text: "Helloworld!". To render such text you should know where to start draw "world!". At first, you should calculate length of "Hello" in pixels and call GetTabAfterPosition with this value. You will get next tab position to draw "world!". - - -## **Set Default Text Style** +If you need to apply the same default text formatting to all text elements in a presentation, you can use the `default_text_style` property of the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class and set the desired formatting. -If you need to apply the same default text formatting to all text elements of a presentation at once, then you can use the `default_text_style` property from the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class and set the preferred formatting. The code example below shows how to set the default bold font (14 pt) for the text on all slides in a new presentation. +The example below demonstrates how to set the default font to bold, with a size of 14 pt, for all text across every slide in a new presentation. ```py with slides.Presentation() as presentation: @@ -666,3 +661,9 @@ Output: Original text: Hello, Aspose! All-Caps effect: HELLO, ASPOSE! ``` + +{{% alert color="primary" %}} + +Aspose provides a simple, [free online PowerPoint editing service](https://products.aspose.app/slides/editor). + +{{% /alert %}} diff --git a/en/python-net/developer-guide/presentation-content/powerpoint-shapes/shape-manipulations/_index.md b/en/python-net/developer-guide/presentation-content/powerpoint-shapes/shape-manipulations/_index.md index ead88f105..c651ef507 100644 --- a/en/python-net/developer-guide/presentation-content/powerpoint-shapes/shape-manipulations/_index.md +++ b/en/python-net/developer-guide/presentation-content/powerpoint-shapes/shape-manipulations/_index.md @@ -27,275 +27,252 @@ keywords: description: "Learn to create, edit and optimize shapes in Aspose.Slides for Python via .NET and deliver high-performance PowerPoint and OpenDocument presentations." --- -## **Find Shape in Slide** -This topic will describe a simple technique to make it easier for developers to find a specific shape on a slide without using its internal Id. It is important to know that PowerPoint Presentation files do not have any way to identify shapes on a slide except an internal unique Id. It seems to be difficult for developers to find a shape using its internal unique Id. All shapes added to the slides have some Alt Text. We suggest developers to use alternative text for finding a specific shape. You can use MS PowerPoint to define the alternative text for objects which you are planning to change in the future. +## **Overview** -After setting the alternative text of any desired shape, you can then open that presentation using Aspose.Slides for Python via .NET and iterate through all shapes added to a slide. During each iteration, you can check the alternative text of the shape and the shape with the matching alternative text would be the shape required by you. To demonstrate this technique in a better way, we have created a method, [FindShape](https://reference.aspose.com/slides/python-net/aspose.slides.util/slideutil/) that does the trick to find a specific shape in a slide and then simply returns that shape. +This guide introduces shape manipulation in Aspose.Slides for Python via .NET. Learn practical patterns for finding shapes (including by Alternative Text), duplicating, deleting or hiding, reordering, aligning and flipping, reading IDs and layout-driven formatting, and exporting individual shapes to SVG using the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) and [Shape](https://reference.aspose.com/slides/python-net/aspose.slides/shape/) APIs. + +## **Find Shapes on Slides** + +PowerPoint identifies shapes only by internal IDs. Assign a unique Alt Text to the target shape in PowerPoint, then open the presentation with Aspose.Slides for Python, iterate over slide shapes, and select the one whose Alt Text matches. The `find_shape` method implements this approach and returns the matching shape. ```py import aspose.slides as slides -# Method implementation to find a shape in a slide using its alternative text -def find_shape(slide, alttext): - for i in range(len(slide.shapes)): - if slide.shapes[i].alternative_text == alttext: - return slide.shapes[i] +# Finds a shape on a slide by its alternative text. +def find_shape(slide, alt_text): + for slide_shape in slide.shapes: + if slide_shape.alternative_text == alt_text: + return slide_shape return None - -# Instantiate a Presentation class that represents the presentation file -with slides.Presentation(path + "FindingShapeInSlide.pptx") as p: - slide = p.slides[0] - # Alternative text of the shape to be found + + +# Instantiate the Presentation class that represents a presentation file. +with slides.Presentation("sample.pptx") as presentation: + slide = presentation.slides[0] + # Find the shape with Alt Text "Shape1". shape = find_shape(slide, "Shape1") - if shape != None: - print("Shape Name: " + shape.name) + if shape is not None: + print("Shape name:", shape.name) ``` +## **Clone Shapes** +To clone shapes from a source slide to a new slide in Aspose.Slides, follow these steps: -## **Clone Shape** -To clone a shape to a slide using Aspose.Slides for Python via .NET: +1. Create a [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) from the source file. +1. Get the source slide by index and its shapes collection. +1. Retrieve a blank layout from the master slide. +1. Add an empty slide using that layout and get its shapes. +1. Clone shapes into the target slide. +1. Save the presentation as PPTX. -1. Create an instance of the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class. -1. Obtain the reference of a slide by using its index. -1. Access the source slide shape collection. -1. Add new slide to the presentation. -1. Clone shapes from the source slide shape collection to the new slide. -1. Save the modified presentation as a PPTX file. - -The example below adds a group shape to a slide. +The following code example clones shapes from one slide to another. ```py import aspose.slides as slides -# Instantiate Presentation class -with slides.Presentation(path + "Source Frame.pptx") as srcPres: - sourceShapes = srcPres.slides[0].shapes - blankLayout = srcPres.masters[0].layout_slides.get_by_type(slides.SlideLayoutType.BLANK) - destSlide = srcPres.slides.add_empty_slide(blankLayout) - destShapes = destSlide.shapes - destShapes.add_clone(sourceShapes[1], 50, 150 + sourceShapes[0].height) - destShapes.add_clone(sourceShapes[2]) - destShapes.insert_clone(0, sourceShapes[0], 50, 150) - - # Write the PPTX file to disk - srcPres.save("CloneShape_out.pptx", slides.export.SaveFormat.PPTX) -``` +# Instantiate the Presentation class. +with slides.Presentation("sample.pptx") as presentation: + source_shapes = presentation.slides[0].shapes + blank_layout = presentation.masters[0].layout_slides.get_by_type(slides.SlideLayoutType.BLANK) + target_slide = presentation.slides.add_empty_slide(blank_layout) + target_shapes = target_slide.shapes + + target_shapes.add_clone(source_shapes[1], 50, 150 + source_shapes[0].height) + target_shapes.add_clone(source_shapes[2]) + target_shapes.insert_clone(0, source_shapes[0], 50, 150) + # Save the presentation to disk. + presentation.save("output.pptx", slides.export.SaveFormat.PPTX) +``` -## **Remove Shape** -Aspose.Slides for Python via .NET allows developers to remove any shape. To remove the shape from any slide, please follow the steps below: +## **Remove Shapes** -1. Create an instance of `Presentation` class. -1. Access the first slide. -1. Find the shape with specific AlternativeText. -1. Remove the shape. -1. Save file to disk. +Aspose.Slides lets you remove any shape from a slide. For example, to delete a shape from the first slide by its Alternative Text, follow these steps: + +1. Create a [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) instance and load the file. +1. Access the first slide from the slides collection. +1. Find the shape by the Alternative Text value. +1. Remove the shape from the slide’s shapes collection. +1. Save the presentation to disk in PPTX format. ```py import aspose.slides as slides -# Create Presentation object -with slides.Presentation() as pres: - # Get the first slide - sld = pres.slides[0] - - # Add autoshape of rectangle type - shp1 = sld.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 50, 40, 150, 50) - shp2 = sld.shapes.add_auto_shape(slides.ShapeType.MOON, 160, 40, 150, 50) - alttext = "User Defined" - for i in range(len(sld.shapes)): - ashp = sld.shapes[0] - if ashp.alternative_text == alttext: - sld.shapes.remove(ashp) - - # Save presentation to disk - pres.save("RemoveShape_out.pptx", slides.export.SaveFormat.PPTX) -``` +# Finds a shape on a slide by its alternative text. +def find_shape(slide, alt_text): + for slide_shape in slide.shapes: + if slide_shape.alternative_text == alt_text: + return slide_shape + return None + +# Instantiate the Presentation class that represents a presentation file. +with slides.Presentation("sample.pptx") as presentation: + slide = presentation.slides[0] + # Find the shape with Alt Text "User Defined". + shape = find_shape(slide, "User Defined") + # Remove the shape. + slide.shapes.remove(shape) + # Save the presentation to disk. + presentation.save("output.pptx", slides.export.SaveFormat.PPTX) +``` +## **Hide Shapes** -## **Hide Shape** -Aspose.Slides for Python via .NET allows developers to hide any shape. To hide the shape from any slide, please follow the steps below: +Aspose.Slides lets you hide any shape on a slide. For example, to hide a shape on the first slide by its Alternative Text, follow these steps: -1. Create an instance of `Presentation` class. -1. Access the first slide. -1. Find the shape with specific AlternativeText. +1. Create a [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) instance and load the file. +1. Access the first slide from the slides collection. +1. Find the shape by the Alternative Text value. 1. Hide the shape. -1. Save file to disk. +1. Save the presentation to disk in PPTX format. ```py -import aspose.slides as slides +# Finds a shape on a slide by its alternative text. +def find_shape(slide, alt_text): + for slide_shape in slide.shapes: + if slide_shape.alternative_text == alt_text: + return slide_shape + return None -# Instantiate Presentation class that represents the PPTX -with slides.Presentation() as pres: - # Get the first slide - sld = pres.slides[0] - - # Add autoshape of rectangle type - shp1 = sld.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 50, 40, 150, 50) - shp2 = sld.shapes.add_auto_shape(slides.ShapeType.MOON, 160, 40, 150, 50) - alttext = "User Defined" - for i in range(len(sld.shapes)): - ashp = sld.shapes[i] - if ashp.alternative_text == alttext: - ashp.hidden = True - - # Save presentation to disk - pres.save("Hiding_Shapes_out.pptx", slides.export.SaveFormat.PPTX) -``` +# Instantiate the Presentation class that represents a presentation file. +with slides.Presentation("sample.pptx") as presentation: + slide = presentation.slides[0] + # Find the shape with Alt Text "User Defined". + shape = find_shape(slide, "User Defined") + # Hide the shape. + shape.hidden = True + # Save the presentation to disk. + presentation.save("output.pptx", slides.export.SaveFormat.PPTX) +``` +## **Change the Order of Shapes** -## **Change Shapes Order** -Aspose.Slides for Python via .NET allows developers to reorder the shapes. Reordering the shape specifies which shape is on the front or which shape is at the back. To reorder the shape from any slide, please follow the steps below: +Aspose.Slides allows developers to reorder shapes (change their z-order). Reordering determines which shape appears in front or behind. For, example, to reorder two shapes on the first slide, follow the steps below: -1. Create an instance of `Presentation` class. +1. Create an instance of the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class. 1. Access the first slide. -1. Add a shape. -1. Add some text in shape's text frame. -1. Add another shape with the same co-ordinates. -1. Reorder the shapes. -1. Save file to disk. +1. Add the first shape (for example, a rectangle). +1. Add the second shape (for example, a triangle). +1. Reorder the shapes by moving the second shape to the first position in the collection. +1. Save the presentation to disk. ```py import aspose.slides as slides -with slides.Presentation(path + "HelloWorld.pptx") as presentation1: - slide = presentation1.slides[0] - shp3 = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 200, 365, 400, 150) - shp3.fill_format.fill_type = slides.FillType.NO_FILL - shp3.add_text_frame(" ") - - txtFrame = shp3.text_frame - para = txtFrame.paragraphs[0] - portion = para.portions[0] - portion.text="Watermark Text Watermark Text Watermark Text" - shp3 = slide.shapes.add_auto_shape(slides.ShapeType.TRIANGLE, 200, 365, 400, 150) - slide.shapes.reorder(2, shp3) - presentation1.save( "Reshape_out.pptx", slides.export.SaveFormat.PPTX) +with slides.Presentation("sample.pptx") as presentation: + slide = presentation.slides[0] + # Add two shapes to the slide. + shape1 = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 20, 20, 200, 150) + shape2 = slide.shapes.add_auto_shape(slides.ShapeType.TRIANGLE, 20, 200, 200, 150) + # Move the second shape to the first position. + slide.shapes.reorder(0, shape2) + presentation.save("output.pptx", slides.export.SaveFormat.PPTX) ``` +## **Get the Interop Shape ID** -## **Get Interop Shape ID** -Aspose.Slides for Python via .NET allows developers to get a unique shape identifier in slide scope in contrast to the UniqueId property, which allows obtaining a unique identifier in presentation scope. Property OfficeInteropShapeId was added to IShape interfaces and Shape class respectively. The value returned by OfficeInteropShapeId property corresponds to the value of the Id of the Microsoft.Office.Interop.PowerPoint.Shape object. Below is a sample code is given. +Aspose.Slides lets you obtain a shape’s unique identifier at the slide scope, unlike the `unique_id` property, which is unique across the entire presentation. The `office_interop_shape_id` property is available on the [Shape](https://reference.aspose.com/slides/python-net/aspose.slides/shape/) class. Its value corresponds to the `Id` of the `Microsoft.Office.Interop.PowerPoint.Shape` object. A sample code snippet is shown below. ```py import aspose.slides as slides -with slides.Presentation(path + "Presentation.pptx") as presentation: - # Getting unique shape identifier in slide scope +with slides.Presentation("sample.pptx") as presentation: + # Get the shape’s unique identifier within the slide. officeInteropShapeId = presentation.slides[0].shapes[0].office_interop_shape_id ``` +## **Set the Alternative Text for Shapes** +Aspose.Slides allows developers to set alternative text for any shape. You can use alternative text to identify and locate shapes in a presentation. The alternative text property can be read and written through both Aspose.Slides and Microsoft PowerPoint. By tagging shapes with this property, you can later remove, hide, or reorder them on a slide. -## **Set Alternative Text for Shape** -Aspose.Slides for Python via .NET allows developers to set AlternateText of any shape. -Shapes in a presentation could be distinguished by the AlternativeText or Shape Name property. -AlternativeText property could be read or set by using Aspose.Slides as well as Microsoft PowerPoint. -By using this property, you can tag a shape and can perform different operations as Removing a shape, -Hiding a shape or Reordering shapes on a slide. -To set the AlternateText of a shape, please follow the steps below: +To set the alternative text of a shape, follow these steps: -1. Create an instance of `Presentation` class. +1. Create an instance of the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class. 1. Access the first slide. -1. Add any shape to the slide. -1. Do some work with the newly added shape. -1. Traverse through shapes to find a shape. -1. Set the AlternativeText. -1. Save file to disk. +1. Add a shape to the slide. +1. Set the alternative text. +1. Save the presentation to disk. ```py import aspose.slides as slides -import aspose.pydrawing as draw - -# Instantiate Presentation class that represents the PPTX -with slides.Presentation() as pres: - # Get the first slide - sld = pres.slides[0] - - # Add autoshape of rectangle type - shp1 = sld.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 50, 40, 150, 50) - shp2 = sld.shapes.add_auto_shape(slides.ShapeType.MOON, 160, 40, 150, 50) - shp2.fill_format.fill_type = slides.FillType.SOLID - shp2.fill_format.solid_fill_color.color = draw.Color.gray - - for i in range(len(sld.shapes)): - shape = sld.shapes[i] - if shape != None: - shape.alternative_text = "User Defined" - - # Save presentation to disk - pres.save("Set_AlternativeText_out.pptx", slides.export.SaveFormat.PPTX) -``` - - +# Instantiate the Presentation class that represents a PPTX file. +with slides.Presentation() as presentation: + slide = presentation.slides[0] + # Add a shape. + shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 50, 40, 150, 50) + # Set the alternative text for the shape. + shape.alternative_text = "User Defined" + # Save the presentation to disk. + presentation.save("output.pptx", slides.export.SaveFormat.PPTX) +``` -## **Access Layout Formats for Shape** - Aspose.Slides for Python via .NET provides a simple API to access layout formats for a shape. This article demonstrates how you can access layout formats. +## **Access Layout Formats for Shapes** -Below sample code is given. +Aspose.Slides provides a simple API for accessing layout formats for shapes. This section demonstrates how to access layout formats. ```py import aspose.slides as slides -with slides.Presentation("Set_AlternativeText_out.pptx") as pres: - for layoutSlide in pres.layout_slides: - fillFormats = list(map(lambda shape: shape.fill_format, layoutSlide.shapes)) - lineFormats = list(map(lambda shape: shape.line_format, layoutSlide.shapes)) +with slides.Presentation(folder_path + "sample.pptx") as presentation: + for layout_slide in presentation.layout_slides: + fill_formats = list(map(lambda shape: shape.fill_format, layout_slide.shapes)) + line_formats = list(map(lambda shape: shape.line_format, layout_slide.shapes)) ``` -## **Render Shape as SVG** -Now Aspose.Slides for Python via .NET support for rendering a shape as svg. WriteAsSvg method (and its overload) has been added to Shape class and IShape interface. This method allows to save content of the shape as an SVG file. Code snippet below shows how to export slide's shape to an SVG file. +## **Render Shapes as SVG** + +Aspose.Slides supports rendering shapes as SVG. The `write_as_svg` method (and its overloads) on the [Shape](https://reference.aspose.com/slides/python-net/aspose.slides/shape/) class lets you save a shape’s contents as an SVG image. The code snippet below shows how to export a shape to an SVG file. ```py import aspose.slides as slides -with slides.Presentation("pres.pptx") as pres: - with open("SingleShape.svg", "wb") as stream: - pres.slides[0].shapes[0].write_as_svg(stream) +with slides.Presentation("sample.pptx") as presentation: + with open("output.svg", "wb") as image_stream: + # Get the first shape on the first slide. + shape = presentation.slides[0].shapes[0] + shape.write_as_svg(image_stream) ``` ## **Align Shape** -Through the [SlidesUtil.AlignShape()](https://reference.aspose.com/slides/python-net/aspose.slides.util/slideutil/) overloaded method, you can +Using the `align_shape` method in the [SlidesUtil](https://reference.aspose.com/slides/python-net/aspose.slides.util/slideutil/) class, you can: -* align shapes relative to a slide's margins. See Example 1. -* align shapes relative to each other. See Example 2. +* Align shapes relative to a slide’s margins (see Example 1). +* Align shapes relative to each other (see Example 2). The [ShapesAlignmentType](https://reference.aspose.com/slides/python-net/aspose.slides/shapesalignmenttype/) enumeration defines the available alignment options. **Example 1** -This Python code shows you how to align shapes with indices 1,2 and 4 along the border at the top of a slide: -Source code below aligns shapes with indices 1,2 and 4 along the top border of the slide. +This Python code shows how to align the shapes with indices 1, 2, and 4 to the top edge of the slide: ```py import aspose.slides as slides -with slides.Presentation("OutputPresentation.pptx") as pres: - slide = pres.slides[0] - shape1 = slide.shapes[1] - shape2 = slide.shapes[2] - shape3 = slide.shapes[4] - slides.util.SlideUtil.align_shapes(slides.ShapesAlignmentType.ALIGN_TOP, True, pres.slides[0], [ - slide.shapes.index_of(shape1), - slide.shapes.index_of(shape2), - slide.shapes.index_of(shape3)]) +align_type = slides.ShapesAlignmentType.ALIGN_TOP +slide_indices = [1, 2, 4] + +with slides.Presentation("sample.pptx") as presentation: + slide = presentation.slides[0] + slides.util.SlideUtil.align_shapes(align_type, True, slide, slide_indices) ``` **Example 2** -This Python code shows you how to align an entire collection of shapes relative to the bottom shape in the collection: +This Python example shows how to align all shapes in a collection relative to the bottom-most shape in that collection: ```py import aspose.slides as slides -with slides.Presentation("example.pptx") as pres: - slides.util.SlideUtil.align_shapes(slides.ShapesAlignmentType.ALIGN_BOTTOM, False, pres.slides[0].shapes) +align_type = slides.ShapesAlignmentType.ALIGN_BOTTOM + +with slides.Presentation("sample.pptx") as presentation: + slides.util.SlideUtil.align_shapes(align_type, False, presentation.slides[0]) ``` ## **Flip Properties** diff --git a/en/python-net/developer-guide/presentation-content/powerpoint-smartart/manage-smartart-shape/_index.md b/en/python-net/developer-guide/presentation-content/powerpoint-smartart/manage-smartart-shape/_index.md index 5aec76899..a732c8e40 100644 --- a/en/python-net/developer-guide/presentation-content/powerpoint-smartart/manage-smartart-shape/_index.md +++ b/en/python-net/developer-guide/presentation-content/powerpoint-smartart/manage-smartart-shape/_index.md @@ -22,134 +22,124 @@ keywords: description: "Automate PowerPoint SmartArt creation, editing, and styling in Python via .NET using Aspose.Slides, featuring concise code examples and performance-focused guidance." --- -## **Create SmartArt Shape** -Aspose.Slides for Python via .NET now facilitates to add custom SmartArt shapes in their slides from scratch. Aspose.Slides for Python via .NET has provided the simplest API to create SmartArt shapes in an easiest way. To create a SmartArt shape in a slide, please follow the steps below: +## **Create SmartArt Shapes** -- Create an instance of [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class. -- Obtain the reference of a slide by using its Index. -- Add a SmartArt shape by setting it LayoutType. -- Write the modified presentation as a PPTX file. +Aspose.Slides for Python via .NET allows you to add custom SmartArt shapes to slides from scratch. The API makes this easy. To add a SmartArt shape to a slide: + +1. Create an instance of the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class. +1. Get the target slide by its index. +1. Add a SmartArt shape, specifying its layout type. +1. Save the modified presentation as a PPTX file. ```py import aspose.slides as slides -import aspose.slides.smartart as art - -# Instantiate the presentation -with slides.Presentation() as pres: - # Access the presentation slide - slide = pres.slides[0] - - # Add Smart Art Shape - smart = slide.shapes.add_smart_art(0, 0, 400, 400, art.SmartArtLayoutType.BASIC_BLOCK_LIST) - - # Saving presentation - pres.save("SimpleSmartArt_out.pptx", slides.export.SaveFormat.PPTX) +import aspose.slides.smartart as smartart + +# Instantiate the Presentation class. +with slides.Presentation() as presentation: + # Access the presentation slide. + slide = presentation.slides[0] + # Add a SmartArt shape. + smart_art = slide.shapes.add_smart_art(0, 0, 400, 400, smartart.SmartArtLayoutType.BASIC_BLOCK_LIST) + # Save the presentation to disk. + presentation.save("output.pptx", slides.export.SaveFormat.PPTX) ``` +## **Access SmartArt Shapes on Slides** - -## **Access SmartArt Shape in Slide** -The following code will be used to access the SmartArt shapes added in presentation slide. In sample code we will traverse through every shape inside the slide and check if it is a SmartArt shape. If shape is of SmartArt type then we will typecast that to SmartArt instance. +The following code demonstrates how to access SmartArt shapes on a slide. The sample iterates through each shape on the slide and checks whether it is a [SmartArt](https://reference.aspose.com/slides/python-net/aspose.slides.smartart/smartart/) object. ```py import aspose.slides as slides -import aspose.slides.smartart as art - -# Load the desired the presentation -with slides.Presentation(path + "SmartArt.pptx") as pres: +import aspose.slides.smartart as smartart - # Traverse through every shape inside first slide - for shape in pres.slides[0].shapes: - # Check if shape is of SmartArt type - if type(shape) is art.SmartArt: - # Typecast shape to SmartArtEx - print("Shape Name:" + shape.name) +# Load a presentation file. +with slides.Presentation("SmartArt.pptx") as presentation: + # Iterate through every shape on the first slide. + for shape in presentation.slides[0].shapes: + # Check whether the shape is a SmartArt shape. + if isinstance(shape, smartart.SmartArt): + # Print the shape name. + print("Shape name:", shape.name) ``` +## **Access SmartArt Shapes with a Specified Layout Type** +The following example shows how to access a SmartArt shape with a specified layout type. Note that you cannot change a SmartArt’s layout type—it’s read-only and is set when the shape is created. -## **Access SmartArt Shape with Particular Layout Type** -The following sample code will help to access the SmartArt shape with particular LayoutType. Please note that you cannot change the LayoutType of the SmartArt as it is read only and is set only when the SmartArt shape is added. - -- Create an instance of `Presentation` class and load the presentation with SmartArt Shape. -- Obtain the reference of first slide by using its Index. -- Traverse through every shape inside first slide. -- Check if shape is of SmartArt type and Typecast selected shape to SmartArt if it is SmartArt. -- Check the SmartArt shape with particular LayoutType and perform what is required to be done afterwards. +1. Create a [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) instance and load the presentation that contains the SmartArt shape. +1. Get a reference to the first slide by index. +1. Iterate over every shape on the first slide. +1. Check whether the shape is a [SmartArt](https://reference.aspose.com/slides/python-net/aspose.slides.smartart/smartart/) object. +1. If the SmartArt shape’s layout type matches the one you need, perform the required actions. ```py import aspose.slides as slides -import aspose.slides.smartart as art +import aspose.slides.smartart as smartart -with slides.Presentation(path + "SmartArt.pptx") as presentation: - # Traverse through every shape inside first slide +with slides.Presentation("SmartArt.pptx") as presentation: + # Iterate through every shape on the first slide. for shape in presentation.slides[0].shapes: - # Check if shape is of SmartArt type - if type(shape) is art.SmartArt: - # Checking SmartArt Layout - if shape.layout == art.SmartArtLayoutType.BASIC_BLOCK_LIST: - print("Do some thing here....") + # Check whether the shape is a SmartArt shape. + if isinstance(shape, smartart.SmartArt): + # Check the SmartArt layout type. + if shape.layout == smartart.SmartArtLayoutType.BASIC_BLOCK_LIST: + print("Do something here...") ``` +## **Change the SmartArt Shape Style** +The following example shows how to locate SmartArt shapes and change their style: -## **Change SmartArt Shape Style** -The following sample code will help to access the SmartArt shape with particular LayoutType. - -- Create an instance of `Presentation` class and load the presentation with SmartArt Shape. -- Obtain the reference of first slide by using its Index. -- Traverse through every shape inside first slide. -- Check if shape is of SmartArt type and Typecast selected shape to SmartArt if it is SmartArt. -- Find the SmartArt shape with particular Style. -- Set the new Style for the SmartArt shape. -- Save the Presentation. +1. Create a [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) and load the file that contains the SmartArt shape(s). +1. Get a reference to the first slide by index. +1. Iterate over each shape on the first slide. +1. Find the SmartArt shape with the specified style. +1. Assign the new style to the SmartArt shape. +1. Save the presentation. ```py import aspose.slides as slides -import aspose.slides.smartart as art +import aspose.slides.smartart as smartart -with slides.Presentation(path + "SmartArt.pptx") as presentation: - # Traverse through every shape inside first slide +with slides.Presentation("SmartArt.pptx") as presentation: + # Iterate through every shape on the first slide. for shape in presentation.slides[0].shapes: - # Check if shape is of SmartArt type - if type(shape) is art.SmartArt: - # Checking SmartArt style - if shape.quick_style == art.SmartArtQuickStyleType.SIMPLE_FILL: - # Changing SmartArt Style - smart.quick_style = art.SmartArtQuickStyleType.CARTOON - - # Saving Presentation - presentation.save("ChangeSmartArtStyle_out.pptx", slides.export.SaveFormat.PPTX) + # Check whether the shape is a SmartArt shape. + if isinstance(shape, smartart.SmartArt): + # Check the SmartArt style. + if shape.quick_style == smartart.SmartArtQuickStyleType.SIMPLE_FILL: + # Change the SmartArt style. + smart.quick_style = smartart.SmartArtQuickStyleType.CARTOON + # Save the presentation. + presentation.save("output.pptx", slides.export.SaveFormat.PPTX) ``` +## **Change the Color Style of SmartArt Shapes** +This example shows how to change the color style of a SmartArt shape. The sample code locates a SmartArt shape with a specified color style and updates it. -## **Change SmartArt Shape Color Style** -In this example, we will learn to change the color style for any SmartArt shape. In the following sample code will access the SmartArt shape with particular color style and will change its style. - -- Create an instance of `Presentation` class and load the presentation with SmartArt Shape. -- Obtain the reference of first slide by using its Index. -- Traverse through every shape inside first slide. -- Check if shape is of SmartArt type and Typecast selected shape to SmartArt if it is SmartArt. -- Find the SmartArt shape with particular Color Style. -- Set the new Color Style for the SmartArt shape. -- Save the Presentation. +1. Create an instance of the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class and load the presentation that contains the SmartArt shape(s). +1. Get a reference to the first slide by index. +1. Iterate over each shape on the first slide. +1. Check whether the shape is a [SmartArt](https://reference.aspose.com/slides/python-net/aspose.slides.smartart/smartart/) object. +1. Locate the SmartArt shape with the specified color style. +1. Set the new color style for that SmartArt shape. +1. Save the presentation. ```py import aspose.slides as slides -import aspose.slides.smartart as art +import aspose.slides.smartart as smartart -with slides.Presentation(path + "SmartArt.pptx") as presentation: - # Traverse through every shape inside first slide +with slides.Presentation("SmartArt.pptx") as presentation: + # Iterate through every shape on the first slide. for shape in presentation.slides[0].shapes: - # Check if shape is of SmartArt type - if type(shape) is art.SmartArt: - # Checking SmartArt color type - if shape.color_style == art.SmartArtColorType.COLORED_FILL_ACCENT1: - # Changing SmartArt color type - shape.color_style = art.SmartArtColorType.COLORFUL_ACCENT_COLORS - - # Saving Presentation - presentation.save("ChangeSmartArtColorStyle_out.pptx", slides.export.SaveFormat.PPTX) + # Check whether the shape is a SmartArt shape. + if isinstance(shape, smartart.SmartArt): + # Check the color type. + if shape.color_style == smartart.SmartArtColorType.COLORED_FILL_ACCENT1: + # Change the color type. + shape.color_style = smartart.SmartArtColorType.COLORFUL_ACCENT_COLORS + # Save the presentation. + presentation.save("output.pptx", slides.export.SaveFormat.PPTX) ``` - diff --git a/en/python-net/developer-guide/presentation-slide/clone-slides/_index.md b/en/python-net/developer-guide/presentation-slide/clone-slides/_index.md index f4e13cd28..8d0b1d344 100644 --- a/en/python-net/developer-guide/presentation-slide/clone-slides/_index.md +++ b/en/python-net/developer-guide/presentation-slide/clone-slides/_index.md @@ -15,187 +15,171 @@ keywords: description: "Quickly clone or duplicate PowerPoint slides with Aspose.Slides for Python via .NET. Follow our clear code examples and tips to automate PPT creation in seconds, boost productivity, and eliminate manual work." --- -## **Clone Slides in Presentation** -Cloning is the process of making an exact copy or replica of something. Aspose.Slides for Python via .NET also makes it possible to make a copy or clone of any slide and then insert that cloned slide to the current or any other opened presentation. The process of slide cloning creates a new slide that can be modified by developers without changing the original slide. There are several possible ways to clone a slide: +## **Overview** -- Clone at End within a Presentation. -- Clone at Another Position within Presentation. -- Clone at End in another Presentation. -- Clone at Another Position in another Presentation. -- Clone at a specific position in another Presentation. +Cloning is the process of making an exact copy or replica of something. Aspose.Slides for Python via .NET allows you to clone any slide and insert that clone into the current presentation or another open presentation. The cloning process creates a new slide that you can modify without affecting the original. -In Aspose.Slides for Python via .NET, (a collection of [Slide](https://reference.aspose.com/slides/python-net/aspose.slides/islide/) objects) exposed by the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) object provides the [add_clone](https://reference.aspose.com/slides/python-net/aspose.slides/islidecollection/) and [insert_clone](https://reference.aspose.com/slides/python-net/aspose.slides/ishapecollection/) methods to perform the above types of slide cloning -## **Clone at End Within a Presentation** -If you want to clone a slide and then use it within the same presentation file at the end of the existing slides, use the [add_clone](https://reference.aspose.com/slides/python-net/aspose.slides/islidecollection/) method according to the steps listed below: +There are several ways to clone a slide: + +- Clone a slide at the end within the same presentation. +- Clone a slide to a specific position within the same presentation. +- Clone a slide at the end of another presentation. +- Clone a slide to a specific position in another presentation. +- Clone a slide with its master slide into another presentation. + +In Aspose.Slides for Python via .NET, the [slide collection](https://reference.aspose.com/slides/python-net/aspose.slides/slidecollection/) exposed by the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) object provides the `add_clone` and `insert_clone` methods to perform these types of slide cloning. + +## **Clone at the End Within the Same Presentation** + +If you want to clone a slide within the same presentation and append it to the end of the existing slides, use the `add_clone` method. Follow these steps: 1. Create an instance of the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class. -1. Instantiate the [SlideCollection](https://reference.aspose.com/slides/python-net/aspose.slides/islidecollection/) class by referencing the Slides collection exposed by the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) object. -2. Call the [add_clone](https://reference.aspose.com/slides/python-net/aspose.slides/islidecollection/) method exposed by the [SlideCollection](https://reference.aspose.com/slides/python-net/aspose.slides/islidecollection/) object and pass the slide to be cloned as a parameter to the [add_clone](https://reference.aspose.com/slides/python-net/aspose.slides/islidecollection/) method. -3. Write the modified presentation file. +1. Get the slide collection from the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) object. +1. Call the `add_clone` method on the [SlideCollection](https://reference.aspose.com/slides/python-net/aspose.slides/slidecollection/), passing the slide to be cloned. +1. Save the modified presentation. -In the example given below, we have cloned a slide (lying at the first position – zero index – of the presentation) to the end of the presentation. +In the example below, the first slide (index 0) is cloned and appended to the end of the presentation. ```py import aspose.slides as slides -# Instantiate Presentation class that represents a presentation file -with slides.Presentation(path + "CloneWithinSamePresentationToEnd.pptx") as pres: - # Clone the desired slide to the end of the collection of slides in the same presentation - slds = pres.slides - - slds.add_clone(pres.slides[0]) - - # Write the modified presentation to disk - pres.save("Aspose_CloneWithinSamePresentationToEnd_out.pptx", slides.export.SaveFormat.PPTX) +# Instantiate the Presentation class to represent the presentation file. +with slides.Presentation("CloneWithinSamePresentationToEnd.pptx") as presentation: + # Clone the desired slide to the end of the slide collection in the same presentation. + presentation.slides.add_clone(presentation.slides[0]) + # Save the modified presentation to disk. + presentation.save("Aspose_CloneWithinSamePresentationToEnd_out.pptx", slides.export.SaveFormat.PPTX) ``` +## **Clone to a Specific Position Within the Same Presentation** -## **Clone at Another Position Within Presentation** -If you want to clone a slide and then use it within the same presentation file but at a different position, use the [insert_clone](https://reference.aspose.com/slides/python-net/aspose.slides/ishapecollection/) method: +If you want to clone a slide within the same presentation and place it at a different position, use the `insert_clone` method: 1. Create an instance of the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class. -1. Instantiate the class by referencing the **Slides** collection exposed by the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) object. -1. Call the [insert_clone](https://reference.aspose.com/slides/python-net/aspose.slides/ishapecollection/) method exposed by the [SlideCollection](https://reference.aspose.com/slides/python-net/aspose.slides/islidecollection/) object and pass the slide to be cloned along with the index for the new position as a parameter to the [insert_clone](https://reference.aspose.com/slides/python-net/aspose.slides/ishapecollection/) method. -1. Write the modified presentation as a PPTX file. +1. Get the slide collection from the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) object. +1. Call the `insert_clone` method on the [SlideCollection](https://reference.aspose.com/slides/python-net/aspose.slides/slidecollection/), passing the slide to be cloned and the target index for its new position. +1. Save the modified presentation. -In the example given below, we have cloned a slide (lying at the zero index – position 1 – of the presentation) to index 1 – Position 2 – of the presentation. +In the example below, the slide at index 0 (position 1) is cloned to index 1 (position 2) within the same presentation. ```py import aspose.slides as slides -# Instantiate Presentation class that represents a presentation file -with slides.Presentation(path + "CloneWithInSamePresentation.pptx") as pres: - # Clone the desired slide to the end of the collection of slides in the same presentation - slds = pres.slides - - # Clone the desired slide to the specified index in the same presentation - slds.insert_clone(2, pres.slides[1]) - - # Write the modified presentation to disk - pres.save("Aspose_CloneWithInSamePresentation_out.pptx", slides.export.SaveFormat.PPTX) +# Instantiate the Presentation class to represent the presentation file. +with slides.Presentation("CloneWithInSamePresentation.pptx") as presentation: + # Clone the desired slide to the specified position (index) within the same presentation. + presentation.slides.insert_clone(2, presentation.slides[1]) + # Save the modified presentation to disk. + presentation.save("Aspose_CloneWithInSamePresentation_out.pptx", slides.export.SaveFormat.PPTX) ``` +## **Clone at the End of Another Presentation** -## **Clone at End in Another Presentation** -If you need to clone a slide from one presentation and use it in another presentation file, at the end of the existing slides: +If you need to clone a slide from one presentation and append it to the end of another presentation: -1. Create an instance of the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class containing the presentation the slide will be cloned from. -1. Create an instance of the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class containing the destination presentation that the slide will be added to. -1. Instantiate the [SlideCollection](https://reference.aspose.com/slides/python-net/aspose.slides/islidecollection/) class by referencing the **Slides** collection exposed by the Presentation object of the destination presentation. -1. Call the [add_clone](https://reference.aspose.com/slides/python-net/aspose.slides/islidecollection/) method exposed by the [SlideCollection](https://reference.aspose.com/slides/python-net/aspose.slides/islidecollection/) object and pass the slide from the source presentation as a parameter to the [add_clone](https://reference.aspose.com/slides/python-net/aspose.slides/islidecollection/) method. -1. Write the modified destination presentation file. +1. Create an instance of the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class for the source presentation (the one that contains the slide to clone). +1. Create an instance of the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class for the destination presentation (where the slide will be added). +1. Get the slide collection from the destination presentation. +1. Call `add_clone` on the destination [SlideCollection](https://reference.aspose.com/slides/python-net/aspose.slides/slidecollection/), passing the slide from the source presentation. +1. Save the modified destination presentation. -In the example given below, we have cloned a slide (from the first index of the source presentation) to the end of the destination presentation. +In the example below, the slide at index 0 in the source presentation is cloned to the end of the destination presentation. ```py import aspose.slides as slides -# Instantiate Presentation class to load the source presentation file -with slides.Presentation(path + "CloneAtEndOfAnother.pptx") as srcPres: - # Instantiate Presentation class for destination PPTX (where slide is to be cloned) - with slides.Presentation() as destPres: - # Clone the desired slide from the source presentation to the end of the collection of slides in destination presentation - slds = destPres.slides - slds.add_clone(srcPres.slides[0]) - - # Write the destination presentation to disk - destPres.save("Aspose2_out.pptx", slides.export.SaveFormat.PPTX) +# Instantiate the Presentation class to represent the source presentation file. +with slides.Presentation("CloneAtEndOfAnother.pptx") as source_presentation: + # Instantiate the Presentation class for the destination PPTX (where the slide will be cloned). + with slides.Presentation() as target_presentation: + # Clone the desired slide from the source presentation to the end of the slide collection in the destination presentation. + target_presentation.slides.add_clone(source_presentation.slides[0]) + # Save the destination presentation to disk. + target_presentation.save("Aspose2_out.pptx", slides.export.SaveFormat.PPTX) ``` +## **Clone to a Specific Position in Another Presentation** -## **Clone at Another Position in Another Presentation** -If you need to clone a slide from one presentation and use it in another presentation file, at a specific position: +If you need to clone a slide from one presentation and insert it into another presentation at a specific position: -1. Create an instance of the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class containing the source presentation the slide will be cloned from. -1. Create an instance of the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class containing the presentation the slide will be added to. -1. Instantiate the [ISlideCollection](https://reference.aspose.com/slides/python-net/aspose.slides/islidecollection/) class by referencing the Slides collection exposed by the Presentation object of the destination presentation. -1. Call the [insert_clone](https://reference.aspose.com/slides/python-net/aspose.slides/ishapecollection/) method exposed by the [ISlideCollection](https://reference.aspose.com/slides/python-net/aspose.slides/islidecollection/) object and pass the slide from the source presentation along with the desired position as a parameter to the [insert_clone](https://reference.aspose.com/slides/python-net/aspose.slides/ishapecollection/) method. -1. Write the modified destination presentation file. +1. Create an instance of the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class for the source presentation (the one containing the slide to clone). +1. Create an instance of the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class for the destination presentation (where the slide will be added). +1. Get the slide collection from the destination presentation. +1. Call the `insert_clone` method on the destination [SlideCollection](https://reference.aspose.com/slides/python-net/aspose.slides/slidecollection/), passing the slide from the source presentation and the desired target index. +1. Save the modified destination presentation. -In the example given below, we have cloned a slide (from the zero index of the source presentation) to index 1 (position 2) of the destination presentation. +In the example below, the slide at index 0 in the source presentation is cloned to index 1 (position 2) in the destination presentation. ```py import aspose.slides as slides -# Instantiate Presentation class to load the source presentation file -with slides.Presentation(path + "CloneAtEndOfAnother.pptx") as srcPres: - # Instantiate Presentation class for destination PPTX (where slide is to be cloned) - with slides.Presentation("Aspose2_out.pptx") as destPres: - slds = destPres.slides - slds.insert_clone(2, srcPres.slides[0]) - - # Write the destination presentation to disk - destPres.save("Aspose3_out.pptx", slides.export.SaveFormat.PPTX) +# Instantiate the Presentation class to represent the source presentation file. +with slides.Presentation("CloneAtEndOfAnother.pptx") as source_presentation: + # Instantiate the Presentation class for the destination PPTX (where the slide is to be cloned). + with slides.Presentation("Aspose2_out.pptx") as target_presentation: + # Insert a clone of the first slide from the source at index 2 in the destination presentation. + target_presentation.slides.insert_clone(2, source_presentation.slides[0]) + # Save the destination presentation to disk. + target_presentation.save("Aspose3_out.pptx", slides.export.SaveFormat.PPTX) ``` +## **Clone a Slide with Its Master Slide into Another Presentation** + +If you need to clone a slide **with its master** from one presentation and use it in another, first clone the required master slide from the source presentation into the destination presentation. Then use that destination master when cloning the slide. The method `add_clone(Slide, MasterSlide)` expects a **master slide from the destination presentation**, not from the source. -## **Clone at Specific Position in Another Presentation** -If you need to clone a slide with a master slide from one presentation from and use it in another presentation, you need to clone the desired master slide from source presentation to destination presentation first. Then you need to use that master slide for cloning slide with master slide. The **add_clone(ISlide, IMasterSlide)** expects a master slide from destination presentation rather than from source presentation. In order to clone the slide with a master, please follow the steps below: +To clone a slide with its master, follow these steps: -1. Create an instance of the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class containing the source presentation the slide will be cloned from. -1. Create an instance of the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class containing the destination presentation the slide will be cloned to. -1. Access the slide to be cloned along with the master slide. -1. Instantiate the [IMasterSlideCollection](https://reference.aspose.com/slides/python-net/aspose.slides/imasterslidecollection/) class by referencing the Masters collection exposed by the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) object of the destination presentation. -1. Call the [add_clone](https://reference.aspose.com/slides/python-net/aspose.slides/islidecollection/) method exposed by the [IMasterSlideCollection](https://reference.aspose.com/slides/python-net/aspose.slides/imasterslidecollection/) object and pass the master from the source PPTX to be cloned as a parameter to the [add_clone](https://reference.aspose.com/slides/python-net/aspose.slides/islidecollection/) method. -1. Instantiate the [ISlideCollection](https://reference.aspose.com/slides/python-net/aspose.slides/islidecollection/) class by setting the reference to the Slides collection exposed by the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) object of the destination presentation. -2. Call the [add_clone](https://reference.aspose.com/slides/python-net/aspose.slides/islidecollection/) method exposed by the [ISlideCollection](https://reference.aspose.com/slides/python-net/aspose.slides/islidecollection/) object and pass the slide from the source presentation to be cloned and master slide as a parameter to the [add_clone](https://reference.aspose.com/slides/python-net/aspose.slides/islidecollection/) method. -3. Write the modified destination presentation file. +1. Create an instance of the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class for the source presentation (the one containing the slide to clone). +1. Create an instance of the [Presentation](https://reference.aspose.com/slides/python-net/aspose.slides/presentation/) class for the destination presentation. +1. Access the source slide to be cloned and its master slide. +1. Get the [MasterSlideCollection](https://reference.aspose.com/slides/python-net/aspose.slides/masterslidecollection/) from the destination presentation’s master collection. +1. Call `add_clone` on the destination [MasterSlideCollection](https://reference.aspose.com/slides/python-net/aspose.slides/masterslidecollection/), passing the source master to clone it into the destination. +1. Get the [SlideCollection](https://reference.aspose.com/slides/python-net/aspose.slides/slidecollection/) from the destination presentation’s slide collection. +1. Call `add_clone` on the destination [SlideCollection](https://reference.aspose.com/slides/python-net/aspose.slides/slidecollection/), passing the source slide and the cloned destination master. +1. Save the modified destination presentation. -In the example given below, we have cloned a slide with a master (lying at the zero index of the source presentation) to the end of the destination presentation using a master from source slide. +In the example below, the slide at index 0 in the source presentation is cloned to the end of the destination presentation using the master cloned from the source. ```py import aspose.slides as slides -# Instantiate Presentation class to load the source presentation file -with slides.Presentation(path + "CloneToAnotherPresentationWithMaster.pptx") as srcPres: - # Instantiate Presentation class for destination presentation (where slide is to be cloned) - with slides.Presentation() as destPres: - # Instantiate ISlide from the collection of slides in source presentation along with - # Master slide - sourceSlide = srcPres.slides[0] - sourceMaster = sourceSlide.layout_slide.master_slide - - # Clone the desired master slide from the source presentation to the collection of masters in the - # Destination presentation - masters = destPres.masters - destMaster = sourceSlide.layout_slide.master_slide - - # Clone the desired master slide from the source presentation to the collection of masters in the - # Destination presentation - iSlide = masters.add_clone(sourceMaster) - - # Clone the desired slide from the source presentation with the desired master to the end of the - # Collection of slides in the destination presentation - slds = destPres.slides - slds.add_clone(sourceSlide, iSlide, True) - - # Clone the desired master slide from the source presentation to the collection of masters in the # Destination presentation - # save the destination presentation to disk - destPres.save("CloneToAnotherPresentationWithMaster_out.pptx", slides.export.SaveFormat.PPTX) +# Instantiate the Presentation class to represent the source presentation file. +with slides.Presentation("CloneToAnotherPresentationWithMaster.pptx") as source_presentation: + # Instantiate the Presentation class for the destination presentation where the slide will be cloned. + with slides.Presentation() as target_presentation: + # Get the first slide from the source presentation. + source_slide = source_presentation.slides[0] + # Get the master slide used by the first slide. + source_master = source_slide.layout_slide.master_slide + # Clone the master slide into the destination presentation's master collection. + cloned_master = target_presentation.masters.add_clone(source_master) + # Clone the slide from the source presentation to the end of the destination presentation using the cloned master. + target_presentation.slides.add_clone(source_slide, cloned_master, True) + # Save the destination presentation to disk. + target_presentation.save("CloneToAnotherPresentationWithMaster_out.pptx", slides.export.SaveFormat.PPTX) ``` +## **Clone at the End in a Specified Section** +With Aspose.Slides for Python via .NET, you can clone a slide from one section of a presentation and insert it into another section within the same presentation. To do this, use the `add_clone(Slide, Section)` method of the [SlideCollection](https://reference.aspose.com/slides/python-net/aspose.slides/slidecollection/) interface. -## Clone at End in Specified Section - -With Aspose.Slides for Python via .NET, you can clone a slide from one section of a presentation and insert that slide into another section in the same presentation. In this case, you have to use the [add_clone](https://reference.aspose.com/slides/python-net/aspose.slides/islidecollection/) method from the [ISlideCollection](https://reference.aspose.com/slides/python-net/aspose.slides/islidecollection/) Interface. - -This Python code shows you how to clone a slide and insert the cloned slide into a specified section: +The following Python example shows how to clone a slide and insert the clone into a specified section: ```py import aspose.slides as slides -with slides.Presentation() as pres: - slide = pres.slides.add_empty_slide(pres.slides[0].layout_slide) - slide.shapes.add_auto_shape(slides.ShapeType.ELLIPSE, 150, 150, 100, 100) # to clone - - slide2 = pres.slides.add_empty_slide(pres.slides[0].layout_slide) - section = pres.sections.add_section("Section2", slide2) - - pres.slides.add_clone(slide, section) - - pres.save("pres.pptx", slides.export.SaveFormat.PPTX) +# Create a new blank presentation. +with slides.Presentation() as presentation: + # Add an empty slide based on the layout of the first slide. + slide = presentation.slides.add_empty_slide(presentation.slides[0].layout_slide) + # Add an ellipse shape to the new slide; this slide will be cloned later. + slide.shapes.add_auto_shape(slides.ShapeType.ELLIPSE, 150, 150, 100, 100) + # Add another empty slide based on the layout of the first slide. + slide2 = presentation.slides.add_empty_slide(presentation.slides[0].layout_slide) + # Create a section named "Section2" that starts at slide2. + section = presentation.sections.add_section("Section2", slide2) + # Clone the previously created slide into the "Section2" section. + presentation.slides.add_clone(slide, section) + # Save the presentation as a PPTX file. + presentation.save("presentation.pptx", slides.export.SaveFormat.PPTX) ``` - - - diff --git a/en/python-net/getting-started/licensing/_index.md b/en/python-net/getting-started/licensing/_index.md index 94af1c095..a35265109 100644 --- a/en/python-net/getting-started/licensing/_index.md +++ b/en/python-net/getting-started/licensing/_index.md @@ -18,43 +18,38 @@ description: "Learn how to apply, manage, and troubleshoot licenses in Aspose.Sl ## **Evaluate Aspose.Slides** -{{% alert color="primary" %}} +You can download an evaluation version of **Aspose.Slides for Python via .NET** from its [download page](https://pypi.org/project/Aspose.Slides/). The evaluation version provides the same features as the licensed product. The evaluation package is identical to the purchased package and becomes licensed after you add a few lines of code to apply the license. -You can download an evaluation version of **Aspose.Slides for Python via .NET** from its [download page](https://pypi.org/project/Aspose.Slides/). The evaluation version provides the same functionalities as the licensed version of the product. The evaluation package is the same as the purchased package. The evaluation version simply becomes licensed after you add a few lines of code to it (to apply the license). +When you’re satisfied with your evaluation of **Aspose.Slides**, you can [purchase a license](https://purchase.aspose.com/buy). We recommend reviewing the available subscription options. If you have questions, contact the Aspose sales team. -Once you are happy with your evaluation of **Aspose.Slides**, you can [purchase a license](https://purchase.aspose.com/buy). We recommend you go through the different subscription types. If you have questions, contact the Aspose sales team. +Every Aspose license includes a one-year subscription with free upgrades to new versions and fixes released during that period. Both licensed and evaluation users receive free, unlimited technical support. -Every Aspose license comes with one-year subscription for free upgrades to new versions or fixes released within the subscription period. Users with licensed products or even evaluation versions get free and unlimited technical support. +**Limitations of the Evaluation Version** -{{% /alert %}} +* While the Aspose.Slides evaluation version (when no license is applied) provides full functionality, it adds an evaluation watermark at the top of the document whenever you open or save it. +* When extracting text from a presentation, you are limited to one slide. -**Evaluation version limitations** - -* While Aspose.Slides evaluation version (without a license specified) provides full product functionality, it inserts an evaluation watermark at the top of the document on open and save operations. -* You are limited to one slide when extracting texts from presentation slides. - -{{% alert color="primary" %}} +{{% alert color="primary" %}} -To test Aspose.Slides without limitations, you can ask for a **30-Day Temporary License**. See the [How to get a Temporary License](https://purchase.aspose.com/temporary-license) page for more information. +To test Aspose.Slides without limitations, you can request a **30-day Temporary License**. See the [How to Get a Temporary License](https://purchase.aspose.com/temporary-license) page for details. {{% /alert %}} ## **Licensing in Aspose.Slides** -* An evaluation version becomes licensed after you purchase a license and add a couple of lines of code to it (to apply the license). -* The license is a plain-text XML file that contains details such as the product name, number of developers it is licensed to, subscription expiry date, and so on. -* The license file is digitally signed, so you must not modify the file. Even an inadvertent addition of an extra line break to the contents of the file will invalidate it. -* Aspose.Slides for Python via .NET typically tries to find the license in these locations: - * An explicit path - * The folder containing the Python script that calls Aspose.Slides for Python via .NET -* To avoid the limitations associated with the evaluation version, you need to set a license before using Aspose.Slides. You only have to set a license once per application or process. - -{{% alert color="primary" %}} +* An evaluation version becomes licensed after you purchase a license and add a couple of lines of code to apply it. +* The license is a plain-text XML file that contains details such as the product name, the number of developers it covers, the subscription expiry date, and so on. +* The license file is digitally signed, so you must not modify it. Even adding a single line break will invalidate it. +* Aspose.Slides for Python via .NET typically looks for the license in these locations: + * An explicit path you provide + * The folder that contains the Python script that calls Aspose.Slides for Python via .NET +* To avoid the evaluation limitations, set the license before using Aspose.Slides. You only need to set it once per application or process. -You may want to see [Metered Licensing](/slides/python-net/metered-licensing/). +{{% alert color="primary" %}} -{{% /alert %}} +You may also want to review [Metered Licensing](/slides/python-net/metered-licensing/). +{{% /alert %}} ## **Applying a License** @@ -62,11 +57,11 @@ A license can be loaded from a **file**, **stream**, or **embedded resource**. {{% alert color="primary" %}} -Aspose.Slides provides the [License](https://reference.aspose.com/slides/python-net/aspose.slides/license/) class for licensing operations. +Aspose.Slides provides the [License](https://reference.aspose.com/slides/python-net/aspose.slides/license/) class to handle licensing. -{{% /alert %}} +{{% /alert %}} -{{% alert color="warning" %}} +{{% alert color="warning" %}} New licenses can activate Aspose.Slides only with version 21.4 or later. Earlier versions use a different licensing system and will not recognize these licenses. @@ -74,47 +69,47 @@ New licenses can activate Aspose.Slides only with version 21.4 or later. Earlier ### **File** -The easiest method of setting a license requires you to place the license file in the same folder containing the component's DLL (included in Aspose.Slides) and specify the file name without its path. +The easiest way to set a license is to place the license file in the same folder as the component’s DLL and specify only the file name (without a path). -This Python code shows you how to set a license file: +The following Python code shows how to set the license file: -``` python +```py import aspose.slides as slides -# Instantiates the License class +# Instantiates the License class. license = slides.License() -# Sets the license file path +# Sets the license file path. license.set_license("Aspose.Slides.lic") ``` -{{% alert color="warning" %}} +{{% alert color="warning" %}} -If you place the license file in a different directory, when you call the [License.set_license()](https://reference.aspose.com/slides/python-net/aspose.slides/license/) method, the license file name at the end of the specified explicit must be the same as your license file. +If you place the license file in a different directory, when you call [License.set_license()](https://reference.aspose.com/slides/python-net/aspose.slides/license/set_license/#str), the file name at the end of the explicit path must match your license file’s name. -For example, you can change the license file name to *Aspose.Slides.lic.xml*. Then, in your code, you have to pass the path to the file (ending with *Aspose.Slides.lic.xml*) to the [License.set_license()](https://reference.aspose.com/slides/python-net/aspose.slides/license/) method. +For example, you can rename the license file to *Aspose.Slides.lic.xml*. Then, in your code, pass the full path to that file (ending with Aspose.Slides.lic.xml) to the [License.set_license()](https://reference.aspose.com/slides/python-net/aspose.slides/license/set_license/#str) method. {{% /alert %}} ### **Stream** -You can load a license from a stream. This Python code shows you how to apply a license from a stream: +You can load a license from a stream. The following Python example shows how to apply a license from a stream: -``` python +```py import aspose.slides as slides -# Instantiates the License class +# Instantiates the License class. license = slides.License() -#Sets the license through a stream +# Set the license from a stream. license.set_license(stream) ``` ## **Validating a License** -To check whether a license has been set properly, you can validate it. This Python code shows you how to validate a license: +To verify that the license has been applied correctly, you can validate it. The following Python code demonstrates how to validate a license: -```python +```py import aspose.slides as slides license = slides.License() @@ -127,8 +122,8 @@ if license.is_licensed(): ## **Thread Safety** -{{% alert title="Note" color="warning" %}} +{{% alert title="Note" color="warning" %}} -The [License.set_license()](https://reference.aspose.com/slides/python-net/aspose.slides/license/) method is not thread safe. If this method has to be called simultaneously from many threads, you may want to use synchronization primitives (like a lock) to avoid issues. +The [License.set_license](https://reference.aspose.com/slides/python-net/aspose.slides/license/) methods are not thread-safe. If it needs to be called concurrently from multiple threads, use synchronization primitives (e.g., `threading.Lock`) to avoid issues. {{% /alert %}}