def add_audio_frame(dataDir): dataDir = Settings.dataDir + 'WorkingWithShapes/Frame/' # Create an instance of Presentation class pres = Presentation() # Get the first slide sId = pres.getSlides().get_Item(0) # Load the wav sound file to stram fstr = FileInputStream(File(dataDir + "Bass-Drum.wav")) # Add Audio Frame af = sId.getShapes().addAudioFrameEmbedded(50, 150, 100, 100, fstr) # Set Play Mode and Volume of the Audio audioPlayModePreset = AudioPlayModePreset audioVolumeMode = AudioVolumeMode af.setPlayMode(audioPlayModePreset.Auto) af.setVolume(audioVolumeMode.Loud) # Write the presentation as a PPTX file save_format = SaveFormat pres.save(dataDir + "AudioFrameEmbed.pptx", save_format.Pptx) print "Added audio frame to slide, please check the output file."
def add_picture_frame(dataDir): dataDir = Settings.dataDir + 'WorkingWithShapes/Frame/' # Create an instance of Presentation class pres = Presentation() # Get the first slide sId = pres.getSlides().get_Item(0) # Instantiate the Image class imgx = pres.getImages().addImage( FileInputStream(File(dataDir + "aspose-logo.jpg"))) # Add Picture Frame with height and width equivalent of Picture shapeType = ShapeType sId.getShapes().addPictureFrame(shapeType.Rectangle, 50, 150, imgx.getWidth(), imgx.getHeight(), imgx) # Write the presentation as a PPTX file save_format = SaveFormat pres.save(dataDir + "RectPicFrame.pptx", save_format.Pptx) print "Added picture frame to slide, please check the output file."
def fill_shapes_with_pattern(dataDir): dataDir = Settings.dataDir + 'WorkingWithShapes/FillingShapes/' # Create an instance of Presentation class pres = Presentation() # Get the first slide sld = pres.getSlides().get_Item(0) # Add autoshape of rectangle type shapeType = ShapeType shp = sld.getShapes().addAutoShape(shapeType.Rectangle, 50, 150, 75, 150) # Set the fill type to Pattern fillType = FillType shp.getFillFormat().setFillType(fillType.Pattern) # Set the pattern style patternStyle = PatternStyle shp.getFillFormat().getPatternFormat().setPatternStyle(patternStyle.Trellis) # Set the pattern back and fore colors color = Color shp.getFillFormat().getPatternFormat().getBackColor().setColor(color.LIGHT_GRAY) shp.getFillFormat().getPatternFormat().getForeColor().setColor(color.YELLOW) # Write the presentation as a PPTX file save_format = SaveFormat pres.save(dataDir + "RectShpPatt.pptx", save_format.Pptx) print "Filled shapes with Pattern, please check the output file."
def create_thumbnail_in_notes_slides_view(dataDir): # Instantiate Presentation class that represents the presentation file pres = Presentation(dataDir + 'demo.pptx') # Access the first slide slide = pres.getSlides().get_Item(0) # User defined dimension desired_x = 1200 desired_y = 800 # Getting scaled value of X and Y scale_x = (1.0 / java_values( pres.getSlideSize().getSize().getWidth())) * desired_x scale_y = (1.0 / java_values( pres.getSlideSize().getSize().getHeight())) * desired_y # Create a full scale image image = slide.getNotesSlide().getThumbnail(scale_x, scale_y) # Save the image to disk in JPEG format imageIO = ImageIO() imageIO.write(image, "jpeg", File(dataDir + "ContentBG_tnail.jpg")) print "Created thumbnail in notes slides view, please check the output file.".PHP_EOL
def add_video_frame(dataDir): dataDir = Settings.dataDir + 'WorkingWithShapes/Frame/' # Create an instance of Presentation class pres = Presentation() # Get the first slide sId = pres.getSlides().get_Item(0) # Add Video Frame vf = sId.getShapes().addVideoFrame(50, 150, 300, 150, dataDir + "Wildlife.mp4") # Set Play Mode and Volume of the Video videoPlayModePreset = VideoPlayModePreset audioVolumeMode = AudioVolumeMode vf.setPlayMode(videoPlayModePreset.Auto) vf.setVolume(audioVolumeMode.Loud) # Write the presentation as a PPTX file save_format = SaveFormat pres.save(dataDir + "VideoFrame.pptx", save_format.Pptx) print "Added video frame to slide, please check the output file."
def set_background_color_of_normal_slide(dataDir): dataDir = Settings.dataDir + 'WorkingWithSlidesInPresentation/Background/' # Instantiate Presentation class that represents the presentation file pres = Presentation() # Set the background color of the Normal slide to Blue backgroundType = BackgroundType fillType = FillType color = Color pres.getSlides().get_Item(0).getBackground().setType( backgroundType.OwnBackground) pres.getSlides().get_Item( 0).getBackground().getFillFormat().setFillType(fillType.Solid) pres.getSlides().get_Item( 0).getBackground().getFillFormat().getSolidFillColor().setColor( color.BLUE) # Saving the presentation save_format = SaveFormat pres.save(dataDir + "ContentBG.pptx", save_format.Pptx) print "Set background color of normal slide, please check the output file."
def create_textbox_with_hyperlink(dataDir): dataDir = Settings.dataDir + 'WorkingWithText/CreateTextBox/' pres = Presentation() # Get the first slide sld = pres.getSlides().get_Item(0) # Add autoshape of rectangle type shapeType=ShapeType pptxShape = sld.getShapes().addAutoShape(shapeType.Rectangle, 150, 150, 150, 50) # Cast the shape to AutoShape pptxAutoShape = pptxShape # Access ITextFrame associated with the AutoShape pptxAutoShape.addTextFrame("") text_frame = pptxAutoShape.getTextFrame() # Add some text to the frame text_frame.getParagraphs().get_Item(0).getPortions().get_Item(0).setText("Aspose.Slides") #Set Hyperlink for the portion text hypman = text_frame.getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().getHyperlinkManager() hypman.setExternalHyperlinkClick("http://www.aspose.com") # Write the presentation as a PPTX file save_format =SaveFormat pres.save(dataDir + "hLinkPPTX.pptx", save_format.Pptx) print "Created TextBox with Hyperlink, please check the output file."
def get_properties(dataDir): dataDir = Settings.dataDir + 'WorkingWithPresentation/Properties/' # Instantiate the Presentation class that represents the presentation pres = Presentation(dataDir + "HelloWorld.pptx") # Create a reference to IDocumentProperties object associated with Presentation dp = pres.getDocumentProperties() # Display the builtin properties print "Category : " + dp.getCategory() print "Current Status : " + dp.getContentStatus() print "Creation Date : " dp.getCreatedTime() print "Author : " + dp.getAuthor() print "Description : " + dp.getComments() print "KeyWords : " + dp.getKeywords() print "Last Modified By : " + dp.getLastSavedBy() print "Supervisor : " + dp.getManager() print "Modified Date : " dp.getLastSavedTime() print "Presentation Format : " dp.getPresentationFormat() print "Last Print Date : " dp.getLastPrinted() print "Is Shared between producers : " dp.getSharedDoc() print "Subject : " dp.getSubject() print "Title : " dp.getTitle()
def __init__(self): dataDir = Settings.dataDir + 'WorkingWithTables/AddImage/' pres = Presentation() # Get the first slide sld = pres.getSlides().get_Item(0) # Define co lumns with widths and rows with heights dbl_cols = [150,150,150,150] dbl_rows = [100,100,100,100,90] # Add table shape to slide tbl = sld.getShapes().addTable(50, 50, dbl_cols, dbl_rows) # Creating a Buffered Image object to hold the image file imageIO = ImageIO() image = imageIO.read(File(dataDir + "aspose-logo.jpg")) imgx1 = pres.getImages().addImage(image) fillType=FillType() pictureFillMode=PictureFillMode() tbl.get_Item(0,0).getFillFormat().setFillType(fillType.Picture) tbl.get_Item(0,0).getFillFormat().getPictureFillFormat().setPictureFillMode(pictureFillMode.Stretch) tbl.get_Item(0,0).getFillFormat().getPictureFillFormat().getPicture().setImage(imgx1) # Write the presentation as a PPTX file save_format = SaveFormat() pres.save(dataDir + "AddImage.pptx", save_format.Pptx) print "Added image, please check the output file."
def fill_shapes_with_solid_color(dataDir): dataDir = Settings.dataDir + 'WorkingWithShapes/FillingShapes/' # Create an instance of Presentation class pres = Presentation() # Get the first slide sld = pres.getSlides().get_Item(0) # Add autoshape of rectangle type shapeType = ShapeType shp = sld.getShapes().addAutoShape(shapeType.Rectangle, 50, 150, 75, 150) # Set the fill type to Solid fillType = FillType shp.getFillFormat().setFillType(fillType.Solid) # Set the color of the rectangle color = Color shp.getFillFormat().getSolidFillColor().setColor(color.YELLOW) # Write the presentation as a PPTX file save_format = SaveFormat pres.save(dataDir + "RectShpSolid.pptx", save_format.Pptx) print "Filled shapes with Solid Color, please check the output file."
def create_smartart_shape(dataDir): dataDir = Settings.dataDir + 'WorkingWithSmartArt/FillFormat/' # Create an instance of Presentation class pres = Presentation() # Get the first slide slide = pres.getSlides().get_Item(0) # Adding SmartArt shape and nodes smartArtLayoutType = SmartArtLayoutType chevron = slide.getShapes().addSmartArt( 10, 10, 800, 60, smartArtLayoutType.ClosedChevronProcess) node = chevron.getAllNodes().addNode() node.getTextFrame().setText("Some text") # Setting node fill color color = Color fillType = FillType item = node.getShapes().get_Item(0) item.getFillFormat().setFillType(fillType.Solid) item.getFillFormat().getSolidFillColor().setColor(color.RED) # Write the presentation as a PPTX file saveFormat = SaveFormat pres.save(dataDir + "FillFormat.pptx", saveFormat.Pptx) print "Set fill format for smartart node, please check the output file."
def add_fixed_error_bar_value(dataDir): dataDir = Settings.dataDir + 'WorkingWithCharts/ErrorBars' pres = Presentation() # Creating a bubble chart chartType = ChartType chart = pres.getSlides().get_Item(0).getShapes().addChart( chartType.Bubble, 50, 50, 400, 300, True) # Adding Error bars and setting its format error_bar_x = chart.getChartData().getSeries().get_Item( 0).getErrorBarsXFormat() error_bar_y = chart.getChartData().getSeries().get_Item( 0).getErrorBarsYFormat() errorBarValueType = ErrorBarValueType errorBarType = ErrorBarType error_bar_x.setValueType(errorBarValueType.Fixed) error_bar_x.setValue(0.1) error_bar_y.setValueType(errorBarValueType.Percentage) error_bar_y.setValue(5) error_bar_x.setType(errorBarType.Plus) error_bar_y.getFormat().getLine().setWidth(2.0) #error_bar_x.hasEndCap(True) # Save presentation with chart save_format = SaveFormat pres.save(dataDir + "ErrorBar.pptx", save_format.Pptx) print "Added fixed error bar value for chart, please check the output file."
def fill_shapes_with_picture(dataDir): dataDir = Settings.dataDir + 'WorkingWithShapes/FillingShapes/' # Create an instance of Presentation class pres = Presentation() # Get the first slide sld = pres.getSlides().get_Item(0) # Add autoshape of rectangle type shapeType = ShapeType shp = sld.getShapes().addAutoShape(shapeType.Rectangle, 50, 150, 75, 150) # Set the fill type to Picture fillType = FillType shp.getFillFormat().setFillType(fillType.Picture) # Set the picture fill mode pictureFillMode = PictureFillMode shp.getFillFormat().getPictureFillFormat().setPictureFillMode( pictureFillMode.Tile) # Set the picture imgx = pres.getImages().addImage( FileInputStream(File(dataDir + "night.jpg"))) shp.getFillFormat().getPictureFillFormat().getPicture().setImage(imgx) # Write the presentation as a PPTX file save_format = SaveFormat pres.save(dataDir + "RectShpPic.pptx", save_format.Pptx) print "Filled shapes with Picture, please check the output file."
def set_image_as_background_color(dataDir): dataDir = Settings.dataDir + 'WorkingWithSlidesInPresentation/Background/' # Instantiate Presentation class that represents the presentation file pres = Presentation() # Set the background with Image backgroundType = BackgroundType fillType = FillType pictureFillMode = PictureFillMode pres.getSlides().get_Item(0).getBackground().setType( backgroundType.OwnBackground) pres.getSlides().get_Item( 0).getBackground().getFillFormat().setFillType(fillType.Picture) pres.getSlides().get_Item(0).getBackground().getFillFormat( ).getPictureFillFormat().setPictureFillMode(pictureFillMode.Stretch) # Set the picture imgx = pres.getImages().addImage( FileInputStream(File(dataDir + 'night.jpg'))) # Image imgx = pres.getImages().addImage(image) # Add image to presentation's images collection pres.getSlides().get_Item(0).getBackground().getFillFormat( ).getPictureFillFormat().getPicture().setImage(imgx) # Saving the presentation save_format = SaveFormat pres.save(dataDir + "ContentBG_Image.pptx", save_format.Pptx) print "Set image as background, please check the output file."
def create_textbox(dataDir): dataDir = Settings.dataDir + 'WorkingWithText/CreateTextBox/' # Create an instance of Presentation class pres = Presentation() # Get the first slide sld = pres.getSlides().get_Item(0) # Add autoshape of rectangle type shapeType=ShapeType shp = sld.getShapes().addAutoShape(shapeType.Rectangle, 150, 75, 150, 50) # Add TextFrame to the Rectangle shp.addTextFrame(" ") # Accessing the text frame txt_frame = shp.getTextFrame() # Create the Paragraph object for text frame para = txt_frame.getParagraphs().get_Item(0) # Create Portion object for paragraph portion = para.getPortions().get_Item(0) # Set Text portion.setText("Aspose TextBox") # Write the presentation as a PPTX file save_format = SaveFormat pres.save(dataDir + "TextBox.pptx", save_format.Pptx) print "Created TextBox, please check the output file."
def convert_with_custom_size(dataDir): dataDir = Settings.dataDir + 'WorkingWithPresentation/ConvertingToTiff/' # Instantiate a Presentation object that represents a PPTX file pres = Presentation(dataDir + "Aspose.pptx") # Instantiate the TiffOptions class opts = TiffOptions # Setting compression type tiff_compression_types = TiffCompressionTypes opts.setCompressionType(tiff_compression_types.Default) #Setting image DPI opts.setDpiX(200) opts.setDpiY(100) # Set Image Size opts.setImageSize(Dimension(1728, 1078)) # Save the presentation to TIFF with specified image size save_format = SaveFormat pres.save(dataDir + "Aspose-Custom-Size.tiff", save_format.Tiff, opts) print "Document has been converted, please check the output file."
def __init__(self): dataDir = Settings.dataDir + 'WorkingWithTables/CreateTable/' pres = Presentation() # Get the first slide sld = pres.getSlides().get_Item(0) # Define columns with widths and rows with heights dblCols = [50, 50, 50] dblRows = [50, 30, 30, 30, 30] # Add table shape to slide tbl = sld.getShapes().addTable(100, 50, dblCols, dblRows) fill_type = FillType color = Color # Set border format for each cell row = 0 while (row < tbl.getRows().size()): cell = 0 while (cell < tbl.getRows().get_Item(row).size()): tbl.getRows().get_Item(row).get_Item(cell).getBorderTop().getFillFormat().setFillType(fill_type.Solid) tbl.getRows().get_Item(row).get_Item(cell).getBorderTop().getFillFormat().getSolidFillColor().setColor(color.RED) tbl.getRows().get_Item(row).get_Item(cell).getBorderTop().setWidth(5) tbl.getRows().get_Item(row).get_Item(cell).getBorderBottom().getFillFormat().setFillType(fill_type.Solid) tbl.getRows().get_Item(row).get_Item(cell).getBorderBottom().getFillFormat().getSolidFillColor().setColor(color.RED) tbl.getRows().get_Item(row).get_Item(cell).getBorderBottom().setWidth(5) tbl.getRows().get_Item(row).get_Item(cell).getBorderLeft().getFillFormat().setFillType(fill_type.Solid) tbl.getRows().get_Item(row).get_Item(cell).getBorderLeft().getFillFormat().getSolidFillColor().setColor(color.RED) tbl.getRows().get_Item(row).get_Item(cell).getBorderLeft().setWidth(5) tbl.getRows().get_Item(row).get_Item(cell).getBorderRight().getFillFormat().setFillType(fill_type.Solid) tbl.getRows().get_Item(row).get_Item(cell).getBorderRight().getFillFormat().getSolidFillColor().setColor(color.RED) tbl.getRows().get_Item(row).get_Item(cell).getBorderRight().setWidth(5) cell+=1 row+=1 # Merge cells 1 & 2 of row 1 tbl.mergeCells(tbl.getRows().get_Item(0).get_Item(0), tbl.getRows().get_Item(1).get_Item(0), False) # Add text to the merged cell tbl.getRows().get_Item(0).get_Item(0).getTextFrame().setText("Merged Cells") # Write the presentation as a PPTX file save_format = SaveFormat pres.save(dataDir + "CreateTable.pptx", save_format.Pptx) print "Created table, please check the output file."
def add_custom_error_bar_value(dataDir): dataDir = Settings.dataDir + 'WorkingWithCharts/ErrorBars' pres = Presentation() slide = pres.getSlides().get_Item(0) # Creating a bubble chart chartType = ChartType chart = pres.getSlides().get_Item(0).getShapes().addChart( chartType.Bubble, 50, 50, 400, 300, True) # Adding custom Error bars and setting its format error_bar_value_type = ErrorBarValueType series = chart.getChartData().getSeries().get_Item(0) error_bar_x = series.getErrorBarsXFormat() error_bar_y = series.getErrorBarsYFormat() #error_bar_x.isVisible(True) #error_bar_y.isVisible(True) error_bar_x.setValueType(error_bar_value_type.Custom) error_bar_y.setValueType(error_bar_value_type.Custom) #Accessing chart series data point and setting error bars values for individual point data_source_type = DataSourceType points = series.getDataPoints() points.getDataSourceTypeForErrorBarsCustomValues( ).setDataSourceTypeForXPlusValues(data_source_type.DoubleLiterals) points.getDataSourceTypeForErrorBarsCustomValues( ).setDataSourceTypeForXMinusValues(data_source_type.DoubleLiterals) points.getDataSourceTypeForErrorBarsCustomValues( ).setDataSourceTypeForYPlusValues(data_source_type.DoubleLiterals) points.getDataSourceTypeForErrorBarsCustomValues( ).setDataSourceTypeForYMinusValues(data_source_type.DoubleLiterals) # Setting error bars for chart series points i = 0 while i < points.size(): points.get_Item(i).getErrorBarsCustomValues().getXMinus( ).setAsLiteralDouble(i + 1) points.get_Item( i).getErrorBarsCustomValues().getXPlus().setAsLiteralDouble(i + 1) points.get_Item(i).getErrorBarsCustomValues().getYMinus( ).setAsLiteralDouble(i + 1) points.get_Item( i).getErrorBarsCustomValues().getYPlus().setAsLiteralDouble(i + 1) i += 1 save_format = SaveFormat pres.save(dataDir + "ErrorBarsCustomValues.pptx", save_format.Pptx) print "Added custom error bars values for chart, please check the output file."
def clone_to_other_presentation_at_end_of_existing_slide(dataDir): dataDir = Settings.dataDir + 'WorkingWithSlidesInPresentation/ChangingPosition/' # Instantiate Presentation class that represents the presentation file src_pres = Presentation(dataDir + 'Aspose.pptx') # Instantiate Presentation class for destination PPTX (where slide is to be cloned) dest_pres = Presentation() # Clone the desired slide from the source presentation to the end of the collection of slides in destination presentation slds = dest_pres.getSlides() slds.addClone(src_pres.getSlides().get_Item(0)) # Saving the presentation file save_format = SaveFormat dest_pres.save(dataDir + "Aspose_dest2.pptx", save_format.Pptx) print "Slide has been cloned, please check the output file."
def __init__(self): dataDir = Settings.dataDir + 'WorkingWithPresentation/PptToPptx/' # Instantiate a Presentation object that represents a PPTX file pres = Presentation(dataDir + "Presentation1.ppt") # Saving the PPTX presentation to PPTX format save_format = SaveFormat pres.save(dataDir + "Aspose.pptx", save_format.Pptx) print "Document has been converted, please check the output file."
def font_family_of_text(dataDir): dataDir = Settings.dataDir + 'WorkingWithText/TextFont/' # Create an instance of Presentation class pres = Presentation() # Get the first slide sld = pres.getSlides().get_Item(0) # Add an AutoShape of Rectangle type shapeType = ShapeType ashp = sld.getShapes().addAutoShape(shapeType.Rectangle, 50, 50, 200, 50) # Remove any fill style associated with the AutoShape fillType = FillType ashp.getFillFormat().setFillType(fillType.NoFill) # Access the TextFrame associated with the AutoShape tf = ashp.getTextFrame() tf.setText("Aspose TextBox") # Access the Portion associated with the TextFrame port = tf.getParagraphs().get_Item(0).getPortions().get_Item(0) # Set the Font for the Portion port.getPortionFormat().setLatinFont(FontData("Times New Roman")) # Set Bold property of the Font nullableBool = NullableBool port.getPortionFormat().setFontBold(nullableBool. True) # Set Italic property of the Font port.getPortionFormat().setFontItalic(nullableBool. True) # Set Underline property of the Font textUnderlineType = TextUnderlineType port.getPortionFormat().setFontUnderline(textUnderlineType.Single) # Set the Height of the Font port.getPortionFormat().setFontHeight(25) # Set the color of the Font color = Color port.getPortionFormat().getFillFormat().setFillType(fillType.Solid) port.getPortionFormat().getFillFormat().getSolidFillColor().setColor( color.BLUE) # Write the presentation as a PPTX file save_format = SaveFormat pres.save(dataDir + "FontFamilyOfText.pptx", save_format.Pptx) print "Done with font family for text, please check the output file."
def get_slide_by_index(dataDir): dataDir = Settings.dataDir + 'WorkingWithSlidesInPresentation/AccessSlides/' # Instantiate Presentation class that represents the presentation file pres = Presentation(dataDir + 'Aspose.pptx') # Accessing a slide using its slide index slide = pres.getSlides().get_Item(0) print "Slide: " print slide
def convert_to_pdf_notes(dataDir): dataDir = Settings.dataDir + 'WorkingWithPresentation/ConvertingToNotes/' # Instantiate a Presentation object that represents a PPTX file pres = Presentation(dataDir + "Aspose.pptx") # Saving the presentation save_format = SaveFormat pres.save(dataDir + "Notes.pdf", save_format.pdf) print "Document has been converted, please check the output file."
def font_properties(dataDir): dataDir = Settings.dataDir + 'WorkingWithText/TextFont/' # Create an instance of Presentation class pres = Presentation(dataDir + 'Welcome.pptx') # Get the first slide slide = pres.getSlides().get_Item(0) # Accessing the first and second placeholder in the slide and typecasting it as AutoShape tf1 = slide.getShapes().get_Item(0).getTextFrame() tf2 = slide.getShapes().get_Item(1).getTextFrame() # Accessing the first Paragraph para1 = tf1.getParagraphs().get_Item(0) para2 = tf2.getParagraphs().get_Item(0) # Accessing the first portion port1 = para1.getPortions().get_Item(0) port2 = para2.getPortions().get_Item(0) # Define fonts fd1 = FontData("Elephant") fd2 = FontData("Castellar") # Assign fonts to portion port1.getPortionFormat().setLatinFont(fd1) port2.getPortionFormat().setLatinFont(fd2) # Set font to Bold nullableBool = NullableBool port1.getPortionFormat().setFontBold(nullableBool. True) port2.getPortionFormat().setFontBold(nullableBool. True) # Set font to Italic port1.getPortionFormat().setFontItalic(nullableBool. True) port2.getPortionFormat().setFontItalic(nullableBool. True) # Set font color fillType = FillType color = Color port1.getPortionFormat().getFillFormat().setFillType(fillType.Solid) port1.getPortionFormat().getFillFormat().getSolidFillColor().setColor( color.BLUE) port2.getPortionFormat().getFillFormat().setFillType(fillType.Solid) port2.getPortionFormat().getFillFormat().getSolidFillColor().setColor( color.GREEN) # Write the presentation as a PPTX file save_format = SaveFormat pres.save(dataDir + "WelcomeFont.pptx", save_format.Pptx) print "Done with font properties, please check the output file."
def convert_with_default_size(dataDir): dataDir = Settings.dataDir + 'WorkingWithPresentation/ConvertingToXps/' # Instantiate a Presentation object that represents a PPTX file pres = Presentation(dataDir + "Aspose.pptx") # Saving the presentation to XPS format save_format = SaveFormat pres.save(dataDir + "Aspose.xps", save_format.Xps) print "Document has been converted, please check the output file."
def __init__(self): dataDir = Settings.dataDir + 'WorkingWithShapes/FindShape/' # Create an instance of Presentation class pres = Presentation(dataDir + 'demo.pptx') # Get the first slide slide = pres.getSlides().get_Item(0) shape = self.find_shape(slide) print "Shape: ".shape
def remove_slide_by_id(dataDir): dataDir = Settings.dataDir + 'WorkingWithSlidesInPresentation/RemoveSlides/' # Instantiate Presentation class that represents the presentation file pres = Presentation(dataDir + 'Aspose.pptx') # Removing a slide using its slide index pres.getSlides().removeAt(1) # Saving the presentation file save_format = SaveFormat pres.save(dataDir + "Modified.pptx", save_format.Pptx) print "Removed slide by ID, please check the output file."
def set_size_and_type(dataDir): dataDir = Settings.dataDir + 'WorkingWithSlidesInPresentation/SizeAndLayout/' # Instantiate Presentation class that represents the presentation file pres = Presentation(dataDir + 'demo.pptx') aux_pres = Presentation() slide = pres.getSlides().get_Item(0) # Set the slide size of generated presentations to that of source aux_pres.getSlideSize().setType(pres.getSlideSize().getType()) aux_pres.getSlideSize().setSize(pres.getSlideSize().getSize()) # Clone required slide aux_pres.getSlides().addClone(pres.getSlides().get_Item(0)) aux_pres.getSlides().removeAt(0) # Saving the presentation save_format = SaveFormat pres.save(dataDir + "Slide_Size_Type.pptx", save_format.Pptx) print "Set slide size and type, please check the output file."
def __init__(self): dataDir = Settings.dataDir + 'WorkingWithSlidesInPresentation/Hyperlinks/' # Instantiate Presentation class that represents the presentation file pres = Presentation(dataDir + 'demo.pptx') # Removing the hyperlinks from presentation pres.getHyperlinkQueries().removeAllHyperlinks() # Saving the presentation save_format = SaveFormat pres.save(dataDir + "Hyperlinks.pptx", save_format.Pptx) print "Removed hyperlinks successfully, please check the output file."
def __init__(self): dataDir = Settings.dataDir + 'WorkingWithTables/AlignText/' pres = Presentation() # Get the first slide slide = pres.getSlides().get_Item(0) # Define columns with widths and rows with heights dbl_cols = [120, 120, 120, 120] dbl_rows = [100, 100, 100, 100] # Add table shape to slide tbl = slide.getShapes().addTable(100, 50, dbl_cols, dbl_rows) # Add text to the merged cell tbl.getRows().get_Item(0).get_Item(1).getTextFrame().setText("10") tbl.getRows().get_Item(0).get_Item(2).getTextFrame().setText("20") tbl.getRows().get_Item(0).get_Item(3).getTextFrame().setText("30") # Accessing the text frame txt_frame = tbl.getRows().get_Item(0).get_Item(0).getTextFrame() # Create the Paragraph object for text frame para = txt_frame.getParagraphs().get_Item(0) # Create Portion object for paragraph fillType = FillType() color = Color() portion = para.getPortions().get_Item(0) portion.setText("Text here") portion.getPortionFormat().getFillFormat().setFillType(fillType.Solid) portion.getPortionFormat().getFillFormat().getSolidFillColor( ).setColor(color.BLACK) # Aligning the text vertically textVerticalType = TextVerticalType() cell = tbl.getRows().get_Item(0).get_Item(0) textAnchorType = TextAnchorType() cell.setTextAnchorType(textAnchorType.Center) cell.setTextVerticalType(textVerticalType.Vertical270) # Write the presentation as a PPTX file save_format = SaveFormat() pres.save(dataDir + "AlignText.pptx", save_format.Pptx) print "Aligned Text, please check the output file."