Jump to content

Dark Mode export to PPT


TannerE

Recommended Posts

How do I do what is in the attached image in iron python? 

Outside of iron python, in just the standard spotfire environment, I can easily export all the visualizations on a page to PowerPoint. In fact, I can cycle through the active page's trellis options that are not visible and export all of them to the open PowerPoint. I tend to work in dark mode and customize all of my HTML for it.

I was trying to automate this exporting to PowerPoint, as all the options were not necessarily intuitive to those unfamiliar with Spotfire. Use iron python, I found a method to capture a visualization as an image, save it to a temporary file, and then render that file into a slide in my presentation. 

Unfortunately, this method left all axis, legends, and tables with a white background. Given that I'm in dark mode, all of these have white text that is now invisible. 

What is odd, is that the core image itself (the scatter plot or box plot) maintains the dark mode background within the same image.

I don't have this issue when exporting to PowerPoint outside of iron python. I spent several hours trying to find a solution to this with no luck. Any insights or known solutions? 

Any solutions to rendering the unseen trellis panels? I currently am using a filtering schema to loop through groups so that only a select few are filtered to at a time. I take a screenshot using the pre-described method with each iteration. Effectively doing the same thing, but in a much more complicated way. 

Anyways, hoping for some insights as to how to do this more easily. Thank you ahead of time for any help you can give!

IMG_20240822_204248.png

Edited by TannerE
Clarify Post and add picture
Link to comment
Share on other sites

Yes, 

I have yet to make it look nice as I am hammering out how it will work in the first place. That being said, here is what I have working right now. All visuals are brought in as variables to the script.

I tried some things that didn't work. They are now commented out. 

```

from Spotfire.Dxp.Application.Export import Report
import clr
clr.AddReference("Microsoft.Office.Interop.PowerPoint")
import Microsoft.Office.Interop.PowerPoint as PowerPoint
from System.IO import *
from Spotfire.Dxp.Application.Visuals import VisualContent
from System.Drawing import *
import System.Drawing as Drawing
from System import IO

# Get the prepared report
#result = Application.Document.TryGetReport("Second page")
#print (result[1])

#report = result[1]

powerpoint = PowerPoint.ApplicationClass()
powerpoint.Visible = True
presentation = powerpoint.Presentations.Add()

#presslide = pres.Slides.Add(1,PowerPoint.PpSlideLayout.ppLayoutTitleOnly)
#presentation = powerpoint.Presentations.Open("C:\\Users\\User1\\Downloads\\Test.pptx")
# Add slides to the existing presentation
slideCounter = presentation.Slides.Count + 1
slide = presentation.Slides.Add(slideCounter, PowerPoint.PpSlideLayout.ppLayoutTitleOnly)
slide.FollowMasterBackground = False

slide.Background.Fill.BackColor.RGB = (255 << 16) | (0 << 8) | 0
vc = TitlePage_Vis
bm = Bitmap(2000, 1200)
g = Graphics.FromImage(bm)
r = Rectangle(Point(0,0), bm.Size)
#brush = Drawing.SolidBrush(Drawing.Color.FromArgb(255, 200, 200, 200))  # Replace with your desired color
# Fill the rectangle with the background color
#g.FillRectangle(brush, r)
#g.Color.Black
vc.Render(g, r)
file = Path.GetTempFileName()
bm.Save(file)

# Add content to the slide

export_path = Path.Combine(IO.Path.GetTempPath(), "visualization.png")

# Export the visualization to an image file
visual = vc  # Get the first visualization
visual.Export(export_path)

# Insert the exported image into the slide
slide.Shapes.AddPicture(export_path, False, True, 30, 60, 650, 400)

# Set the slide title

title = slide.Shapes.Title
title.TextFrame.TextRange.Text = visual.Title
#slide.Shapes.AddPicture((file), False, True, 30, 60, 650, 400)
txt=slide.Shapes.AddTextBox(1,10,500,500,100)
title.Top=0.1
obj=slide.Shapes.Title.TextFrame.TextRange
obj.Font.Size=24


Visuals = [Group_Vis1,Group_Vis2,Single_Vis1]


slideCounter = presentation.Slides.Count + 1
slide = presentation.Slides.Add(slideCounter, PowerPoint.PpSlideLayout.ppLayoutTitleOnly)
vc = Visuals [0]
bm = Bitmap(2000, 1200)
g = Graphics.FromImage(bm)
r = Rectangle(Point(0,0), bm.Size)
#brush = Drawing.SolidBrush(Drawing.Color.FromArgb(255, 200, 200, 200))  # Replace with your desired color
# Fill the rectangle with the background color
#g.FillRectangle(brush, r)
#g.Clear(Color.LightGray)
vc.Render(g, r)
file = Path.GetTempFileName()
bm.Save(file)
# Add content to the slide
title = slide.Shapes.Title
title.TextFrame.TextRange.Text = 'Testing'
slide.Shapes.AddPicture((file), False, True, 30, 60, 650, 400)
txt=slide.Shapes.AddTextBox(1,10,500,500,100)
title.Top=0.1
obj=slide.Shapes.Title.TextFrame.TextRange
obj.Font.Size=24

slideCounter = presentation.Slides.Count + 1
slide = presentation.Slides.Add(slideCounter, PowerPoint.PpSlideLayout.ppLayoutTitleOnly)
vc = Visuals [1]
bm = Bitmap(2000, 1200)
g = Graphics.FromImage(bm)
r = Rectangle(Point(0,0), bm.Size)
#brush = Drawing.SolidBrush(Drawing.Color.FromArgb(255, 200, 200, 200))  # Replace with your desired color
# Fill the rectangle with the background color
#g.FillRectangle(brush, r)
#g.Clear(Color.LightGray)
vc.Render(g, r)
file = Path.GetTempFileName()
bm.Save(file)
# Add content to the slide
title = slide.Shapes.Title
title.TextFrame.TextRange.Text = 'Testing'
slide.Shapes.AddPicture((file), False, True, 30, 60, 650, 400)
txt=slide.Shapes.AddTextBox(1,10,500,500,100)
title.Top=0.1
obj=slide.Shapes.Title.TextFrame.TextRange
obj.Font.Size=24

slideCounter = presentation.Slides.Count + 1
slide = presentation.Slides.Add(slideCounter, PowerPoint.PpSlideLayout.ppLayoutTitleOnly)
vc = Visuals [2]
bm = Bitmap(2000, 1200)
g = Graphics.FromImage(bm)

#brush = Drawing.SolidBrush(Drawing.Color.FromArgb(255, 200, 200, 200))  # Replace with your desired color
# Fill the rectangle with the background color
#g.FillRectangle(brush, r)
#g.Clear(Color.LightGray)
r = Rectangle(Point(0,0), bm.Size)
vc.Render(g, r)
file = Path.GetTempFileName()
bm.Save(file)
# Add content to the slide
title = slide.Shapes.Title
title.TextFrame.TextRange.Text = 'Testing'
slide.Shapes.AddPicture((file), False, True, 30, 60, 650, 400)
txt=slide.Shapes.AddTextBox(1,10,500,500,100)
title.Top=0.1
obj=slide.Shapes.Title.TextFrame.TextRange
obj.Font.Size=24


# Save and close the presentation
#presentation.Save()
#presentation.Close()
#powerpoint.Quit()

```

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...