You can add a DropTargetListener to your application or frame in order to listen to PDF files being dropped and then have the files be opened in Qoppa’s PDF component (jPDFViewer, jPDFNotes, jPDFEditor).

We have implemented this feature in our sample demo applications so you can download our demo to try and then look into the code to see if this feature is implemented.

This sample shows how to receive PDF documents but it could also be applied to all the image formats supported by Qoppa’s PDF components (jpg, tiff, png, ..). When an image is opened, it is converted to PDF on the fly.

// Set ourselves as a drop target, to receive PDF files
setDropTarget(new DropTarget(PDFEditorSample.this, PDFEditorSample.this));
// PDFEditorSample implements DropTargetListener
public class PDFEditorSample extends JFrame implements DropTargetListener
{
....
    //
    // Implementation of drop target methods
    //
    public void dragEnter(DropTargetDragEvent dtde){}
    public void dragExit(DropTargetEvent dte) {}
    public void dragOver(DropTargetDragEvent dtde) {}
    public void dropActionChanged(DropTargetDragEvent dtde) {}
 
    public void drop(java.awt.dnd.DropTargetDropEvent dtde) 
    {
        // Get the action and accept the drop
        int action = dtde.getDropAction();
        dtde.acceptDrop(action);
 
        // Get the transferable
        Transferable t = dtde.getTransferable();
        if (t != null)
        {
            try
            {
            	List list = null; 
            	DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
 
                // We can take files as dropped objects
                if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) 
                {
                    // Get the list of files
                    list = (List) t.getTransferData(DataFlavor.javaFileListFlavor); 
                }
				else if (t.isDataFlavorSupported(uriListFlavor))
				{
					// Parse the list of files
					list = textURIListToFileList((String) t.getTransferData(uriListFlavor));
				}
 
                if (list != null && list.size() > 0)
                {
                    File file = (File) list.get(0);
                    // when a pdf file is dropped, open it in pdfeditor bean
                    if (file.getName() != null && file.getName().toLowerCase().endsWith(".pdf"))
                    {
                    	// Load the PDF
                        getPDFEditor().loadPDF(file.getAbsolutePath());
                    }
                }
            }
            catch (Throwable te)
            {
                JOptionPane.showMessageDialog(this, te.getMessage());
            }
        }
    }