Knowledgebase (2330)
Children categories
Python: Apply Shadow, Transparent, and 3D Effects to Text in PowerPoint
2024-09-04 00:49:50 Written by KoohjiEnhancing the visual appeal of your PowerPoint presentations is crucial for capturing your audience's attention. One effective way to achieve this is by applying advanced text effects such as shadows, transparency, and 3D effects. These techniques can add depth, dimension, and a modern look to your text, making your slides more engaging and professional. In this article, we'll demonstrate how to apply shadow, transparent and 3D effects to text in PowerPoint in Python using Spire.Presentation for Python.
- Apply Shadow Effect to Text in PowerPoint in Python
- Apply Transparent Effect to Text in PowerPoint in Python
- Apply 3D Effect to Text in PowerPoint in Python
Install Spire.Presentation for Python
This scenario requires Spire.Presentation for Python. It can be easily installed in your Windows through the following pip command.
pip install Spire.Presentation
If you are unsure how to install, please refer to this tutorial: How to Install Spire.Presentation for Python on Windows
Apply Shadow Effect to Text in PowerPoint in Python
Spire.Presentation for Python offers the InnerShadowEffect and OuterShadowEffect classes for creating inner and outer shadow effects. These shadow effects can then be applied to the text within shapes by using the IAutoShape.TextFrame.TextRange.EffectDag.InnerShadowEffect and IAutoShape.TextFrame.TextRange.EffectDag.OuterShadowEffect properties. The detailed steps are as follows.
- Create an object of the Presentation class.
- Get a specific slide in the presentation using the Presentation.Slides[index] property.
- Add a shape to the slide using the ISilde.Shapes.AppendShape() method.
- Add text to the shape using the IAutoShape.AppendTextFrame() method.
- Create an inner or outer shadow effect using the InnerShadowEffect or OuterShadowEffect class.
- Set the blur radius, direction, distance and color, for the inner or outer shadow effect using the properties offered by the InnerShadowEffect or OuterShadowEffect class.
- Apply the inner or outer shadow effect to the text within the shape using the IAutoShape.TextFrame.TextRange.EffectDag.InnerShadowEffect or IAutoShape.TextFrame.TextRange.EffectDag.OuterShadowEffect property.
- Save the resulting presentation using the Presentation.SaveToFile() method.
- Python
from spire.presentation.common import *
from spire.presentation import *
# Create an object of the Presentation class
ppt = Presentation()
# Get the first slide
slide = ppt.Slides[0]
# Add the first rectangular shape to the slide
shape = slide.Shapes.AppendShape(ShapeType.Rectangle, RectangleF.FromLTRB(120, 60, 500, 200))
shape.Fill.FillType = FillFormatType.none
# Add text to the shape
shape.AppendTextFrame("Text With Outer Shadow Effect")
shape.TextFrame.Paragraphs[0].TextRanges[0].LatinFont = TextFont("Arial")
shape.TextFrame.Paragraphs[0].TextRanges[0].FontHeight = 21
shape.TextFrame.Paragraphs[0].TextRanges[0].Fill.FillType = FillFormatType.Solid
shape.TextFrame.Paragraphs[0].TextRanges[0].Fill.SolidColor.Color = Color.get_Black()
# Create an outer shadow effect
outerShadow = OuterShadowEffect()
# Set the blur radius, direction, distance and color for the outer shadow effect
outerShadow.BlurRadius = 0
outerShadow.Direction = 50
outerShadow.Distance = 10
outerShadow.ColorFormat.Color = Color.get_LightBlue()
# Apply the outer shadow effect to the text in the first rectangular shape
shape.TextFrame.TextRange.EffectDag.OuterShadowEffect = outerShadow
# Add the second rectangular shape to the slide
shape = slide.Shapes.AppendShape(ShapeType.Rectangle, RectangleF.FromLTRB(120, 300, 500, 440))
shape.Fill.FillType = FillFormatType.none
# Add text to the shape
shape.AppendTextFrame("Text With Inner Shadow Effect")
shape.TextFrame.Paragraphs[0].TextRanges[0].LatinFont = TextFont("Arial")
shape.TextFrame.Paragraphs[0].TextRanges[0].FontHeight = 21
shape.TextFrame.Paragraphs[0].TextRanges[0].Fill.FillType = FillFormatType.Solid
shape.TextFrame.Paragraphs[0].TextRanges[0].Fill.SolidColor.Color = Color.get_Black()
# Create an inner shadow effect
innerShadow = InnerShadowEffect()
# Set the blur radius, direction, distance and color for the inner shadow effect
innerShadow.BlurRadius = 0
innerShadow.Direction = 50
innerShadow.Distance = 10
innerShadow.ColorFormat.Color = Color.get_LightBlue()
# Apply the inner shadow effect to the text in the second rectangular shape
shape.TextFrame.TextRange.EffectDag.InnerShadowEffect = innerShadow
# Save the resulting presentation
ppt.SaveToFile("SetShadowEffect.pptx", FileFormat.Pptx2013)
ppt.Dispose()

Apply Transparent Effect to Text in PowerPoint in Python
Spire.Presentation for Python does not offer a direct method to apply transparency effect to text, but you can control the transparency by adjusting the alpha value of the text color. The detailed steps are as follows.
- Create an object of the Presentation class.
- Get a specific slide in the presentation using the Presentation.Slides[index] property.
- Add a shape to the slide using the ISilde.Shapes.AppendShape() method.
- Retrieve the paragraph collection from the text frame within the shape using the IAutoShape.TextFrame.Paragraphs property, then remove any default paragraphs from the collection using the ParagraphList.Clear() method.
- Add new paragraphs to the collection using the ParagraphList.Append() method, and insert text into each paragraph using the TextParagraph.TextRanges.Append() method.
- Set the fill type of the text to solid using the TextRange.Fill.FillType property.
- Adjust the transparency of the text by setting the color with varying alpha values using the Color.FromArgb(alpha:int, red:int, green:int, blue:int) method, where the alpha value controls the transparency level—the lower the alpha, the more transparent the text.
- Save the resulting presentation using the Presentation.SaveToFile() method.
- Python
from spire.presentation.common import *
from spire.presentation import *
# Create an object of the Presentation class
ppt = Presentation()
# Get the first slide
slide = ppt.Slides[0]
# Add a rectangular shape to the slide
textboxShape = slide.Shapes.AppendShape(ShapeType.Rectangle, RectangleF.FromLTRB(100, 100, 400, 220))
# Make the border of the shape transparent
textboxShape.ShapeStyle.LineColor.Color = Color.get_Transparent()
# Set the shape's fill to none
textboxShape.Fill.FillType = FillFormatType.none
# Retrieve the paragraph collection from the text frame within the shape
paras = textboxShape.TextFrame.Paragraphs
# Remove any default paragraphs
paras.Clear()
# Add three new paragraphs to the text frame, each with a different transparency level for the text
alpha = 55 # Initial alpha value for text transparency
for i in range(3):
# Create and add a new paragraph
paras.Append(TextParagraph())
# Add text to the paragraph
paras[i].TextRanges.Append(TextRange("Text with Different Transparency"))
# Set the text fill type to solid
paras[i].TextRanges[0].Fill.FillType = FillFormatType.Solid
# Set the text color with varying transparency, controlled by the alpha value
paras[i].TextRanges[0].Fill.SolidColor.Color = Color.FromArgb(
alpha,
Color.get_Blue().R,
Color.get_Blue().G,
Color.get_Blue().B
)
# Increase alpha value to reduce transparency for the next paragraph
alpha += 100
# Save the resulting presentation
ppt.SaveToFile("SetTransparency.pptx", FileFormat.Pptx2013)
ppt.Dispose()

Apply 3D Effect to Text in PowerPoint in Python
The FormatThreeD class in Spire.Presentation for Python is used for creating a 3D effect. You can access the FormatThreeD object using the IAutoShape.TextFrame.TextThreeD property, then use the properties of the FormatThreeD class to configure the settings for the 3D effect. The detailed steps are as follows.
- Create an object of the Presentation class.
- Get a specific slide in the presentation using the Presentation.Slides[index] property.
- Add a shape to the slide using the ISilde.Shapes.AppendShape() method.
- Add text to the shape using the IAutoshape.AppendTextFrame() method.
- Access the FormatThreeD object using the IAutoShape.TextFrame.TextThreeD property.
- Set the material type, top bevel type, contour color and width, and lighting type for the 3D effect through the properties of the FormatThreeD class.
- Save the resulting presentation using the Presentation.SaveToFile() method.
- Python
from spire.presentation.common import *
from spire.presentation import *
# Create an object of the Presentation class
ppt = Presentation()
# Get the first slide
slide = ppt.Slides[0]
# Add a rectangular shape to the slide
shape = slide.Shapes.AppendShape(ShapeType.Rectangle, RectangleF.FromLTRB(30, 40, 680, 240))
# Make the border of the shape transparent
shape.ShapeStyle.LineColor.Color = Color.get_Transparent()
# Set the shape's fill to none
shape.Fill.FillType = FillFormatType.none
# Add text to the shape
shape.AppendTextFrame("Text with 3D Effect")
# Set text color
textRange = shape.TextFrame.TextRange
textRange.Fill.FillType = FillFormatType.Solid
textRange.Fill.SolidColor.Color = Color.get_LightBlue()
# Set font
textRange.FontHeight = 40
textRange.LatinFont = TextFont("Arial")
# Access the FormatThreeD object
threeD = shape.TextFrame.TextThreeD
# Set the material type for the 3D effect
threeD.ShapeThreeD.PresetMaterial = PresetMaterialType.Metal
# Set the top bevel type for the 3D effect
threeD.ShapeThreeD.TopBevel.PresetType = BevelPresetType.Circle
# Set the contour color and width for the 3D effect
threeD.ShapeThreeD.ContourColor.Color = Color.get_Green()
threeD.ShapeThreeD.ContourWidth = 3
# Set the lighting type for the 3D effect
threeD.LightRig.PresetType = PresetLightRigType.Sunrise
# Save the resulting presentation
ppt.SaveToFile("Set3DEffect.pptx", FileFormat.Pptx2013)
ppt.Dispose()

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
Programmatic editing of Word documents involves using code to alter or modify the contents of these documents. This approach enables automation and customization, making it particularly advantageous for handling large document collections. Through the use of Spire.Doc library, developers can perform a wide range of operations, including text manipulation, formatting changes, and the addition of images or tables.
The following sections will demonstrate how to edit or modify a Word document in Python using Spire.Doc for Python.
- Modify Text in a Word Document
- Change Formatting of Text in a Word Document
- Add New Elements to a Word Document
- Remove Paragraphs from a Word Document
Install Spire.Doc for Python
This scenario requires Spire.Doc for Python and plum-dispatch v1.7.4. They can be easily installed in your Windows through the following pip command.
pip install Spire.Doc
If you are unsure how to install, please refer to this tutorial: How to Install Spire.Doc for Python on Windows
Modify Text in a Word Document in Python
In order to alter the content of a paragraph, the initial step is to obtain the desired paragraph from a specific section through the use of the Section.Paragraphs[index] property. Following this, you can replace the existing text with the new content by assigning it to the Paragraph.Text property of the chosen paragraph.
Here are the steps to edit text in a Word document with Python:
- Create a Document object.
- Load a Word file from the given file path.
- Get a specific section using Document.Sections[index] property.
- Get a specific paragraph using Section.Paragraphs[index] property.
- Reset the text of the paragraph using Paragraph.Text property.
- Save the updated document to a different Word file.
- Python
from spire.doc import *
from spire.doc.common import *
# Create a Document object
document = Document()
# Load an existing Word file
document.LoadFromFile("C:\\Users\\Administrator\\Desktop\\input.docx");
# Get a specific section
section = document.Sections[0]
# Get a specific paragraph
paragraph = section.Paragraphs[0]
# Modify the text of the paragraph
paragraph.Text = "The text has been modified"
# Save the document to a different Word file
document.SaveToFile("output/ModifyText.docx", FileFormat.Docx)
# Dispose resource
document.Dispose()

Change Formatting of Text in a Word Document in Python
To alter the text appearance of a particular paragraph, you first need to obtain the specified paragraph. Next, go through its child objects to find the individual text ranges. The formatting of each text range can then be updated using the TextRange.CharacterFormat property.
The steps to change text formatting in a Word document are as follows:
- Create a Document object.
- Load a Word file from the given file path.
- Get a specific section using Document.Sections[index] property.
- Get a specific paragraph using Section.Paragraphs[index] property.
- Iterate through the child objects in the paragraph.
- Determine if a child object is a text range.
- Get a specific text range.
- Reset the text formatting using TextRange.CharacterFormat property.
- Save the updated document to a different Word file.
- Python
from spire.doc import *
from spire.doc.common import *
# Create an object of Document
doc = Document()
# Load a Word document
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\input.docx")
# Get a specific section
section = document.Sections.get_Item(0)
# Get a specific paragraph
paragraph = section.Paragraphs.get_Item(0)
# Iterate through the child objects in the paragraph
for i in range(paragraph.ChildObjects.Count):
# Determine if a child object is text range
if isinstance(paragraph.ChildObjects[i], TextRange):
# Get a specific text range
textRange = paragraph.ChildObjects[i]
# Reset font name
textRange.CharacterFormat.FontName = "Corbel Light"
# Reset font size
textRange.CharacterFormat.FontSize = 11.0
# Reset text color
textRange.CharacterFormat.TextColor = Color.get_Blue()
# Apply italic to the text range
textRange.CharacterFormat.Italic = True
# Save the document to a different Word file
doc.SaveToFile("output/ChangeFormatting.docx", FileFormat.Docx2019)
# Dispose resource
doc.Dispose()

Add New Elements to a Word Document in Python
In a Word document, most elements—such as text, images, lists, and charts—are fundamentally organized around the concept of a paragraph. To insert a new paragraph into a specific section, use the Section.AddParagraph() method.
After creating the new paragraph, you can add various elements to it by leveraging the methods and properties of the Paragraph object.
The steps to add new elements (text and images) to a Word document are as follows:
- Create a Document object.
- Load a Word file from the given file path.
- Get a specific section through Document.Sections[index] property.
- Add a paragraph to the section using Section.AddParagraph() method.
- Add text to the paragraph using Paragraph.AppendText() method.
- Add an image to the paragraph using Paragraph.AppendPicture() method.
- Save the updated document to a different Word file.
- Python
from spire.doc import *
from spire.doc.common import *
# Create an object of Document
doc = Document()
# Load a Word document
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\Input.docx")
# Get the last section
lastSection = doc.LastSection
# Add a paragraph to the section
paragraph = lastSection.AddParagraph()
# Add an image to the paragraph
picture = paragraph.AppendPicture("C:\\Users\\Administrator\\Desktop\\logo.png");
# Set text wrap style
picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom
# Add text to the paragraph
paragraph.AppendText("This text and the image above are added by Spire.Doc for Python.")
# Create a paragraph style
style = ParagraphStyle(doc)
style.Name = "FontStyle"
style.CharacterFormat.FontName = "Times New Roman"
style.CharacterFormat.FontSize = 12
doc.Styles.Add(style)
# Apply the style to the paragraph
paragraph.ApplyStyle(style.Name)
# Save the document to a different Word file
doc.SaveToFile("output/AddNewElements.docx", FileFormat.Docx2019)
# Dispose resource
doc.Dispose()

Remove Paragraphs from a Word Document in Python
To eliminate a specific paragraph from a document, simply invoke the ParagraphCollection.RemoveAt() method and supply the index of the paragraph you intend to delete.
The steps to remove paragraphs from a Word document are as follows:
- Create a Document object.
- Load a Word file from the given file path.
- Get a specific section through Document.Sections[index] property.
- Remove a specific paragraph from the section using Section.Paragraphs.RemoveAt() method.
- Save the updated document to a different Word file.
- Python
from spire.doc import *
from spire.doc.common import *
# Create an object of Document
doc = Document()
# Load a Word document
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\input.docx")
# Get a specific section
section = doc.Sections[0]
# Remove a specific paragraph
section.Paragraphs.RemoveAt(0)
# Save the document to a different Word file
doc.SaveToFile("output/RemoveParagraph.docx", FileFormat.Docx);
# Dispose resource
doc.Dispose()
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
Interactive forms in PDFs are valuable tools that allow users to fill in information, complete surveys, or sign documents electronically. However, these forms can also add layers of complexity to a PDF, impacting both file size and the overall user experience. When forms are no longer needed, or when a document needs to be simplified for distribution or archiving, removing these interactive elements can be beneficial. In this article, we will demonstrate how to remove forms from a PDF document in Python using Spire.PDF for Python.
Install Spire.PDF for Python
This scenario requires Spire.PDF for Python and plum-dispatch v1.7.4. They can be easily installed in your Windows through the following pip command.
pip install Spire.PDF
If you are unsure how to install, please refer to this tutorial: How to Install Spire.PDF for Python on Windows
Remove a Specific Form from a PDF Document in Python
Spire.PDF for Python allows you to remove specific form fields from a PDF file by using either the indexes or the names of the form fields. The detailed steps are as follows.
- Create an instance of the PdfDocument class.
- Load a PDF document containing form fields using the PdfDocument.LoadFromFile() method.
- Get the form of the document using the PdfDocument.Form property.
- Get the form field collection using the PdfFormWidget.FieldsWidget property.
- Remove a specific form field by its index using the PdfFormFieldWidgetCollection.RemoveAt(index) method. Or retrieve a form field by its name using the PdfFormFieldWidgetCollection[name] property, and then remove it using the PdfFormFieldWidgetCollection.Remove(field) method.
- Save the resulting document using the PdfDocument.SaveToFile() method.
- Python
from spire.pdf.common import *
from spire.pdf import *
# Create an instance of the PdfDocument class
doc = PdfDocument()
# Load a PDF file
doc.LoadFromFile("Forms.pdf")
# Get the form of the document
pdfForm = doc.Form
formWidget = PdfFormWidget(pdfForm)
# Get the form field collection
field_collection = formWidget.FieldsWidget
# Remove a specific form field by its index
field_collection.RemoveAt(0)
# Or remove a specific form field by its name
# text_box = field_collection["Name"]
# field_collection.Remove(text_box)
# Save the resulting document
doc.SaveToFile("remove_specific_form.pdf")
doc.Close()

Remove All Forms from a PDF Document in Python
To remove all form fields from a PDF document, you need to iterate through the form field collection, and then remove each form field from the collection using the PdfFormFieldWidgetCollection.RemoveAt(index) method. The detailed steps are as follows.
- Create an instance of the PdfDocument class.
- Load a PDF document containing form fields using the PdfDocument.LoadFromFile() method.
- Get the form of the document using the PdfDocument.Form property.
- Get the form field collection using the PdfFormWidget.FieldsWidget property.
- Iterate through all form fields in the collection.
- Remove each form field from the collection using the PdfFormFieldWidgetCollection.RemoveAt(index) method.
- Save the resulting document using the PdfDocument.SaveToFile() method.
- Python
from spire.pdf.common import *
from spire.pdf import *
# Create an instance of the PdfDocument class
doc = PdfDocument()
# Load a PDF file
doc.LoadFromFile("Forms.pdf")
# Get the form of the document
pdfForm = doc.Form
formWidget = PdfFormWidget(pdfForm)
# Get the form field collection
field_collection = formWidget.FieldsWidget
# Check if there are any form fields in the collection
if field_collection.Count > 0:
# Iterate through all form fields in the collection
for i in range(field_collection.Count - 1, -1, -1):
# Remove the current form field from the collection
field_collection.RemoveAt(i)
# Save the resulting document
doc.SaveToFile("remove_all_forms.pdf")
doc.Close()

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.