Get clipboard contents from illustrator using java

Illustrator uses PDF or AICB for the clipboard. I am interested in filling in the clipboard from java as a PDF, then pasting it into Illustrator.

I thought it might be easier to try differently first. So copy from illustrator in java.

If you copy some circles in Illustrator, the getTransferDataFlavors method from Clipboard does not return any DataFlavors. And for all isDataFlavorSupported I get 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)); } } } 

exit:

 false false false false false false false 

I do not know what to do next. I have tried things over the past few hours, but it seems like it is not going anywhere. What can I do?

+7
java clipboard adobe-illustrator
source share
1 answer

Transferable that you get from the clipboard already contains all the contents of the clipboard. It is simply that you cannot convert it to any of the credited data. If you copy it back to the clipboard as is, then it should be available in the application that created it.

On the other hand, you can try to create your own Transferable content and structure that can be interpreted by the target application. Then just put it on the clipboard so that it can be pasted.

+1
source share

All Articles