Skip to main content
Glama
daekeun-ml

PowerPoint Translator

by daekeun-ml

post_process_powerpoint

Optimize PowerPoint presentations by adjusting text boxes; enable text wrapping and auto-fit for content exceeding specified length thresholds. Streamline formatting for improved readability.

Instructions

Apply post-processing to a PowerPoint presentation to optimize text boxes.

This function enables text wrapping and shrink text on overflow for text boxes that contain text longer than the specified threshold.

Args: input_file: Path to the input PowerPoint file (.pptx) output_file: Path to save the processed file (optional, auto-generated if not provided) text_threshold: Text length threshold for enabling auto-fit (overrides .env setting) enable_autofit: Enable text auto-fitting (default: True)

Returns: Success message with post-processing details

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
enable_autofitNo
input_fileYes
output_fileNo
text_thresholdNo

Implementation Reference

  • The main handler function for the 'post_process_powerpoint' tool, decorated with @mcp.tool() for registration. It validates the input PowerPoint file, applies configuration overrides, instantiates PowerPointPostProcessor, and calls process_presentation to perform the text auto-fitting.
    @mcp.tool()
    def post_process_powerpoint(
        input_file: str,
        output_file: Optional[str] = None,
        text_threshold: Optional[int] = None,
        enable_autofit: bool = True
    ) -> str:
        """
        Apply post-processing to a PowerPoint presentation to optimize text boxes.
        
        This function enables text wrapping and shrink text on overflow for text boxes
        that contain text longer than the specified threshold.
        
        Args:
            input_file: Path to the input PowerPoint file (.pptx)
            output_file: Path to save the processed file (optional, auto-generated if not provided)
            text_threshold: Text length threshold for enabling auto-fit (overrides .env setting)
            enable_autofit: Enable text auto-fitting (default: True)
        
        Returns:
            Success message with post-processing details
        """
        try:
            # Validate input file using helper function
            input_path, error_msg = validate_input_path(input_file)
            if error_msg:
                return error_msg
            
            # Create configuration
            config = Config()
            if text_threshold is not None:
                config.set('TEXT_LENGTH_THRESHOLD', str(text_threshold))
            if not enable_autofit:
                config.set('ENABLE_TEXT_AUTOFIT', 'false')
            
            # Generate output filename if not provided
            if not output_file:
                output_file = str(input_path)  # Overwrite the original file
            
            # Apply post-processing
            logger.info(f"Starting post-processing: {input_path}")
            verbose = config.get_bool('DEBUG', False)
            post_processor = PowerPointPostProcessor(config, verbose=verbose)
            final_output = post_processor.process_presentation(str(input_path), output_file)
            
            threshold = config.get_int('TEXT_LENGTH_THRESHOLD', 10)
            autofit_enabled = config.get_bool('ENABLE_TEXT_AUTOFIT', True)
            
            return f"""โœ… PowerPoint post-processing completed successfully!
    
    ๐Ÿ“ Input file: {input_path}
    ๐Ÿ“ Output file: {final_output}
    ๐Ÿ”ง Text auto-fitting: {'โœ… Enabled' if autofit_enabled else 'โŒ Disabled'}
    ๐Ÿ“ Text length threshold: {threshold} characters
    ๐Ÿ“ Processing applied to text boxes longer than {threshold} characters
    
    ๐Ÿ’ก Post-processing features applied:
    โ€ข Text wrapping in shape enabled
    โ€ข Shrink text on overflow enabled
    โ€ข Text box margins optimized
    โ€ข Formatting preservation maintained"""
            
        except Exception as e:
            logger.error(f"Post-processing failed: {str(e)}")
            return f"โŒ Post-processing failed: {str(e)}"
  • Core helper method in PowerPointPostProcessor class that implements the post-processing logic: loads the PPTX, iterates over slides and shapes, applies text wrapping and shrink-on-overflow for text boxes exceeding the length threshold.
    def process_presentation(self, input_file: str, output_file: Optional[str] = None) -> str:
        """
        Process a PowerPoint presentation to enable text auto-fitting.
        
        Args:
            input_file: Path to the input PowerPoint file
            output_file: Path to save the processed file (optional)
            
        Returns:
            Path to the processed file
        """
        if not os.path.exists(input_file):
            raise FileNotFoundError(f"Input file not found: {input_file}")
            
        # Use input file as output file if not provided (overwrite original)
        if not output_file:
            output_file = input_file
        
        print(f"Processing PowerPoint file: {input_file}")
        print(f"Text length threshold: {self.text_threshold} characters")
        print(f"Auto-fit enabled: {self.enable_autofit}")
        
        # Load presentation
        presentation = Presentation(input_file)
        
        total_processed = 0
        total_slides = len(presentation.slides)
        
        # Process each slide
        for slide_idx, slide in enumerate(presentation.slides, 1):
            if self.verbose:
                print(f"Processing slide {slide_idx}/{total_slides}...")
            processed_count = self._process_slide(slide)
            total_processed += processed_count
            
            if processed_count > 0 and self.verbose:
                print(f"  โ†’ Processed {processed_count} text boxes")
        
        # Save the processed presentation
        presentation.save(output_file)
        
        if self.verbose:
            print(f"\nPost-processing completed!")
            print(f"Total text boxes processed: {total_processed}")
            print(f"Output saved to: {output_file}")
        
        return output_file
  • Helper method _process_slide that iterates over slide shapes, checks if they need processing via _should_process_shape, and applies autofit via _apply_text_autofit.
    def _process_slide(self, slide) -> int:
        """
        Process a single slide to enable text auto-fitting for qualifying text boxes.
        
        Args:
            slide: PowerPoint slide object
            
        Returns:
            Number of text boxes processed
        """
        processed_count = 0
        
        for shape in slide.shapes:
            if self._should_process_shape(shape):
                self._apply_text_autofit(shape)
                processed_count += 1
                
        return processed_count
Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/daekeun-ml/ppt-translator'

If you have feedback or need assistance with the MCP directory API, please join our Discord server