Illustrator uses either PDF and AICB for the clipboard. I'm interested in filling the clipboard from within java as PDF to then be able to paste it in Illustrator.
I thought it's probably more easy to first try to other way around. So copy from illustrator to java.
If i copy some circles in Illustrator, then the method getTransferDataFlavors
from the Clipboard
doesn't return any DataFlavors.
And for all isDataFlavorSupported
I get a false.
import java.awt.datatransfer.*;
import java.awt.Toolkit;
public class ClipBoardTest {
public static void main(String[] args) {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable content = clipboard.getContents(null);
if (content != null) {
DataFlavor[] dataFlavors = content.getTransferDataFlavors();
for (DataFlavor df : dataFlavors) {
System.out.println(df.getHumanPresentableName());
System.out.println("---");
}
System.out.println(content.isDataFlavorSupported(DataFlavor.stringFlavor));
System.out.println(content.isDataFlavorSupported(DataFlavor.imageFlavor));
System.out.println(content.isDataFlavorSupported(DataFlavor.allHtmlFlavor));
System.out.println(content.isDataFlavorSupported(DataFlavor.fragmentHtmlFlavor));
System.out.println(content.isDataFlavorSupported(DataFlavor.selectionHtmlFlavor));
System.out.println(content.isDataFlavorSupported(DataFlavor.javaFileListFlavor));
DataFlavor myDF = new DataFlavor("application/pdf", "PDF");
System.out.println(content.isDataFlavorSupported(myDF));
}
}
}
output:
false
false
false
false
false
false
false
I'm clueless of what to do next. I have been trying things for the last few hours but it doesn't seem to lead anywhere. What could I do?
The Transferable
you get from the clipboard already contains all the clipboard content. It is just that you cannot convert it to any of the enlisted data flavors. If you copy it back to the clipboard as is, then it should be pastable in the app that produced it.
For the other way round, you could try making your custom Transferable
having the content and the structure that can be interpreted by the target application. Then just put it to the clipboard so that it can be pasted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With