I am creating a program using processing(java) that outputs an SVG file for me to add it to PowerPoint and other programs.
I figured it would be a lot more convenient for the program to directly copy the generated file to my system clipboard, instead of having to copy the file from the output directory.
The trouble is that I can't find a way to set the contents of the clipboard to an SVG file. I've found ways that work with images, but not SVG. To clarify, I want the pasted file to be an SVG too because I want to edit the shapes and lines in PowerPoint afterward.
I am also open to javascript solutions which may work on the web. The goal is to be able to paste an editable collection of shapes, lines, and texts into PowerPoint.
All help is appreciated, thanks in advance!
Edit: Here is the code that works for images:
import java.awt.image.*;
import java.awt.*;
import java.awt.datatransfer.*;
import javax.imageio.*;
void setup() {
size(200, 200);
background(0);
Image img=null;
try {
img = ImageIO.read(new File("path/to/file.jpg"));//path to image file
}
catch (IOException e) {
print(e);
}
ImageSelection imageSelection = new ImageSelection(img);
Toolkit toolkit = Toolkit.getDefaultToolkit();
toolkit.getSystemClipboard().setContents(imageSelection, null);
}
void draw() {
}
public class ImageSelection implements Transferable {
private Image image;
public ImageSelection(Image image) {
this.image = image;//added on
}
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
if (flavor.equals(DataFlavor.imageFlavor) == false) {
throw new UnsupportedFlavorException(flavor);//usually with transferable
}
return image;
}
public boolean isDataFlavorSupported(DataFlavor flavor) {
return flavor.equals(DataFlavor.imageFlavor);//usually with transferable
}
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[] {
DataFlavor.imageFlavor//usually with transferable
};
}
}