Knowledgebase (2311)
Children categories
Watermarks in Word documents serve as overlayed text or pictures that are typically used to indicate documents’ status, confidentiality, draft nature, etc. While they are useful in certain contexts, watermarks often become a hindrance when it comes to presenting documents. They can be distracting, obscuring the readability, and reduce the overall quality of the document. This article will show how to remove watermarks from Word documents in Python programs using Spire.Doc for Python.
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 commands.
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
Remove the Watermark from a Word Document
Spire.Doc for Python provides the Document.Watermark property which allows users to deal with the watermark of a Word document. Users can assign a null value to this property to remove the watermark of Word document. The detailed steps are as follows:
- Create an object of Document class.
- Load a Word document using Document.LoadFromFile() method.
- Remove the watermark by assigning a null value to Document.Watermark property.
- Save the document using Document.SaveToFile() method.
- Python
from spire.doc import *
from spire.doc.common import *
# Create an object of Document class
doc = Document()
# Load a Word document
doc.LoadFromFile("Sample.docx")
# Remove the watermark
doc.Watermark = None
# Save the document
doc.SaveToFile("output/RemoveWatermark.docx", FileFormat.Auto)

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.
Convert PowerPoint PPT or PPTX to PDF in Python: A Comprehensive Guide
2023-09-12 01:08:24 Written by Koohji
Looking to convert PowerPoint PPT or PPTX files to PDF using Python? This comprehensive guide walks you through the process of converting PowerPoint to PDF with ease. You'll learn how to perform quick conversions using default settings, as well as explore advanced features such as exporting specific slides, adjusting slide size for optimal output, including hidden slides, and generating PDF/A-compliant files for archival use.
- Why Convert PowerPoint to PDF
- Python PowerPoint to PDF Converter Library Installation
- Convert PowerPoint to PDF with Default Settings
- Export PowerPoint to PDF with Advanced Settings
- Conclusion
- FAQs
Why Convert PowerPoint to PDF?
Converting PowerPoint files to PDF offers several advantages:
- Universal Compatibility: PDF files can be opened on virtually any device or operating system without needing PowerPoint installed.
- Preserved Formatting: Unlike PowerPoint files, PDFs lock in layout, fonts, and images to avoid rendering inconsistencies.
- Enhanced Security: PDF files can be encrypted, making them ideal for sharing confidential information.
- Reduced File Size: PDFs often have a smaller file size than PowerPoint presentations, making them easier to share via email or upload online.
Python PowerPoint to PDF Converter Library Installation
To convert PowerPoint presentations to PDF in Python, you can use Spire.Presentation for Python. This powerful library allows you to create, read, modify, and convert PowerPoint PPTX and PPT files without needing Microsoft PowerPoint installed.
Why Choose Spire.Presentation for Python?
- High Fidelity: Ensures accurate conversion while preserving formatting and layout.
- User-Friendly: Simple API makes it easy to implement in your projects.
- Versatile: Supports a wide range of PowerPoint features and formats.
Install Spire.Presentation for Python
Before starting with the conversion process, install Spire.Presentation via pip using the following command:
pip install Spire.Presentation
Need help with installation? Refer to this detailed documentation: How to Install Spire.Presentation for Python on Windows
Convert PowerPoint to PDF with Default Settings
Spire.Presentation makes it easy to convert PowerPoint files to PDF with just a few lines of code.
The example below shows how to load a .pptx or .ppt file and export it to PDF using default settings - ideal for quick conversions where no customization is needed.
from spire.presentation import *
# Create a Presentation object
presentation = Presentation()
# Load a PPTX file
presentation.LoadFromFile("Input.pptx")
# Or load a PPT file
# presentation.LoadFromFile("Input.ppt")
# Save the file as a PDF
presentation.SaveToFile("Basic_conversion.pdf", FileFormat.PDF)
presentation.Dispose()

Export PowerPoint to PDF with Advanced Settings
Spire.Presentation provides a range of advanced settings that give you control over how the PDF output is generated, making it ideal for both professional use and archival purposes. For example, you can:
- Export a Particular Slide to PDF
- Adjust Slide Size for Optimal PDF Output
- Include Hidden Slides in the Converted PDF
- Generate PDF/A-compliant Files from PowerPoint
Export a Particular Slide to PDF
If you only need to share a specific part of your presentation, Spire.Presentation allows you to extract and convert individual slides to a PDF. This is especially useful for generating slide-specific reports or handouts.
from spire.presentation import *
# Create a Presentation object
presentation = Presentation()
# Load the PowerPoint file
presentation.LoadFromFile("Input.pptx")
# Get the desired slide (e.g., the second slide)
slide = presentation.Slides.get_Item(1)
# Save the slide as a PDF
slide.SaveToFile("Single_slide.pdf", FileFormat.PDF)
presentation.Dispose()

Adjust Slide Size for Optimal PDF Output
To ensure that your PDF meets printing or layout requirements, you can adjust the slide dimensions before conversion. Spire.Presentation lets you set standard slide sizes as well as custom slide dimensions so the output aligns with your document formatting needs.
from spire.presentation import *
# Create a Presentation object
presentation = Presentation()
# Load the PowerPoint file
presentation.LoadFromFile("Input.pptx")
# Set the slide size to a standard slide size like A4
presentation.SlideSize.Type = SlideSizeType.A4
# # Or you can set custom slide size (e.g., 720x540 points)
# presentation.SlideSize.Size = SizeF(720.0, 540.0)
# Fit content to the new slide size
presentation.SlideSizeAutoFit = True
# Save the presentation as a PDF
presentation.SaveToFile("Resized_output.pdf", FileFormat.PDF)
presentation.Dispose()

Include Hidden Slides in the Converted PDF
By default, hidden slides are excluded from conversion. However, if your workflow requires complete documentation, Spire.Presentation enables you to include hidden slides in the output PDF.
from spire.presentation import *
# Create a Presentation object
presentation = Presentation()
# Load the PowerPoint file
presentation.LoadFromFile("Input.pptx")
# Get the SaveToPdfOption object
option = presentation.SaveToPdfOption
# Enable ContainHiddenSlides option
option.ContainHiddenSlides = True
# Save the presentation as a PDF
presentation.SaveToFile("Include_hidden_slides.pdf", FileFormat.PDF)
presentation.Dispose()
Generate PDF/A-compliant Files from PowerPoint
PDF/A is a specialized format intended for long-term digital preservation. If your organization needs to archive presentations in a standards-compliant format, Spire.Presentation allows you to export PDF/A files that conform to archival best practices.
from spire.presentation import *
# Create a Presentation object
presentation = Presentation()
# Load the PowerPoint file
presentation.LoadFromFile("Input.pptx")
# Get the SaveToPdfOption object
option = presentation.SaveToPdfOption
# Set PDF compliance to PDF/A-1a
option.PdfConformanceLevel = PdfConformanceLevel.Pdf_A1A
# Save the presentation as a PDF
presentation.SaveToFile("Pdf_a_output.pdf", FileFormat.PDF)
presentation.Dispose()
Conclusion
Spire.Presentation for Python offers a robust set of features for converting PowerPoint files to PDF with minimal effort and maximum flexibility. Whether you require simple conversions or advanced customization options, this library gives developers full control over the process. From exporting individual slides to generating archival-quality outputs, it’s a comprehensive tool for PowerPoint-to-PDF conversion workflows in Python.
FAQs
Q1: Can I convert PPTX and PPT files without installing Microsoft PowerPoint?
A1: Yes, Spire.Presentation is a standalone library and does not require Microsoft Office or PowerPoint to be installed.
Q2: Does the library support batch conversion of multiple PowerPoint files?
A2: Yes, you can write scripts to loop through multiple files and convert each to PDF programmatically.
Q3: Is PDF/A-1a the only compliance level supported for PPT to PDF/A conversion?
A3: No, Spire.Presentation supports multiple compliance levels for PPT to PDF/A conversion, including PDF/A-1a, PDF/A-2a, PDF/A-3a, PDF/A-1b, PDF/A-2b, and PDF/A-3b.
Get a Free License
To fully experience the capabilities of Spire.Presentation for Python without any evaluation limitations, you can request a free 30-day trial license.
Images in Word documents can break up large blocks of text and make the content more visually interesting. In addition, they can also effectively illustrate complex ideas or concepts that are difficult to explain solely through text. In this article, you will learn how to programmatically add images to a Word document using Spire.Doc for Python.
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 commands.
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
Insert an Image in a Word Document in Python
Spire.Doc for Python offers the Paragraph.AppendPicture() method to insert an image into a Word document. The following are the detailed steps.
- Create a Document object.
- Add a section using Document.AddSection() method.
- Add two paragraphs to the section using Section.AddParagraph() method.
- Add text to the paragraphs and set formatting.
- Load an image and add it to a specified paragraph using Paragraph.AppendPicture() method.
- Set width and height for the image using DocPicture.Width and DocPicture.Height properties.
- Set a text wrapping style for the image using DocPicture.TextWrappingStyle property.
- Save the result document using Document.SaveToFile() method.
- Python
from spire.doc import *
from spire.doc.common import *
# Create a Document object
document = Document()
# Add a seciton
section = document.AddSection()
# Add a paragraph
paragraph1 = section.AddParagraph()
# Add text to the paragraph and set formatting
tr = paragraph1.AppendText("Spire.Doc for Python is a professional Word Python API specifically designed for developers to create, read, write, convert, and compare Word documents with fast and high-quality performance.")
tr.CharacterFormat.FontName = "Calibri"
tr.CharacterFormat.FontSize = 11
paragraph1.Format.LineSpacing = 18
paragraph1.Format.BeforeSpacing = 10
paragraph1.Format.AfterSpacing = 10
# Add another paragraph
paragraph2 = section.AddParagraph()
tr = paragraph2.AppendText("Spire.Doc for Python enables to perform many Word document processing tasks. It supports Word 97-2003 /2007/2010/2013/2016/2019 and it has the ability to convert them to commonly used file formats like XML, RTF, TXT, XPS, EPUB, EMF, HTML and vice versa. Furthermore, it supports to convert Word Doc/Docx to PDF using Python, Word to SVG, and Word to PostScript in high quality.")
# Add text to the paragraph and set formatting
tr.CharacterFormat.FontName = "Calibri"
tr.CharacterFormat.FontSize = 11
paragraph2.Format.LineSpacing = 18
# Add an image to the specified paragraph
picture = paragraph1.AppendPicture("Spire.Doc.jpg")
# Set image width and height
picture.Width = 100
picture.Height = 100
# Set text wrapping style for the image
picture.TextWrappingStyle = TextWrappingStyle.Square
#Save the result document
document.SaveToFile("InsertImage.docx", FileFormat.Docx)
document.Close()

Insert an Image at a Specified Location in a Word document in Python
If you wish to place the image at a specified location in the Word document, you can set its position through the DocPicture.HorizontalPosition and DocPicture.VerticalPosition properties. The following are the detailed steps.
- Create a Document object.
- Add a section using Document.AddSection() method.
- Add a paragraph to the section using Section.AddParagraph() method.
- Add text to the paragraph and set formatting.
- Add an image to the paragraph using Paragraph.AppendPicture() method.
- Set width and height for the image using DocPicture.Width and DocPicture.Height properties.
- Set the horizontal position and vertical position for the image using DocPicture.HorizontalPosition and DocPicture.VerticalPosition properties.
- Set a text wrapping style for the image using DocPicture.TextWrappingStyle property.
- Save the result document using Document.SaveToFile() method.
- Python
from spire.doc import *
from spire.doc.common import *
# Create a Document object
doc = Document()
# Add a section
section = doc.AddSection()
# Add a paragraph to the section
paragraph = section.AddParagraph()
# Add text to the paragraph and set formatting
paragraph.AppendText("The sample demonstrates how to insert an image at a specified location in a Word document.")
paragraph.ApplyStyle(BuiltinStyle.Heading2)
# Add an image to the paragraph
picture = paragraph.AppendPicture("pic.jpg")
# Set image position
picture.HorizontalPosition = 150.0
picture.VerticalPosition = 60.0
# Set image size
picture.Width = 120.0
picture.Height = 180.0
# Set a text wrapping style for the image (note that the position settings are not applicable when the text wrapping style is Inline)
picture.TextWrappingStyle = TextWrappingStyle.Through
# Save the result document
doc.SaveToFile("WordImage.docx", FileFormat.Docx)
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.