Forum Discussion
Sytriox
1 year agoNew Member
Capture Screenshot of Custom Visual with Button
Hi, I am currently developing a custom visual for Power BI and I would like to add a feature that allows users to take a screenshot of the visual. The idea is to include a button within the visu...
Anonymous
1 year agoNot applicable
Hi Sytriox ,
You can refer the following links to get it:
import * as d3 from "d3";
// Other imports as needed
import "html2canvas";
export class MyVisual implements IVisual {
// Visual properties and constructor
private captureButton: HTMLButtonElement;
constructor(options: VisualConstructorOptions) {
// Your constructor code
this.captureButton = document.createElement("button");
this.captureButton.innerText = "Capture Screenshot";
this.captureButton.onclick = this.captureScreenshot.bind(this);
options.element.appendChild(this.captureButton);
}
public update(options: VisualUpdateOptions) {
// Your update code
// Optionally append the button to the visual's DOM if it isn't already there
if (!this.captureButton.parentElement) {
options.element.appendChild(this.captureButton);
}
}
private captureScreenshot() {
html2canvas(document.querySelector('YOUR_VISUAL_ROOT_ELEMENT_SELECTOR')).then(canvas => {
const link = document.createElement('a');
link.download = 'screenshot.png';
link.href = canvas.toDataURL();
link.click();
});
}
}
In addition, you can raise a ticket in the Custom Visuals Development community for dedicated support.
Custom Visuals Development Discussion - Microsoft Fabric Community
Best Regards