首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用ICEpdf“内部”java程序

使用ICEpdf“内部”java程序
EN

Stack Overflow用户
提问于 2016-05-24 01:31:12
回答 3查看 1.2K关注 0票数 0

我们已经创建了一个程序作为uni赋值,并希望使用ICEpdf或其他用于java的pdf查看器。

我们创建了不同的选项卡,在其中一个选项卡中,用户可以选择一个pdf文件进行“上传”和查看。问题是,我们希望让用户可以在应用程序中查看pdf,而ICEpdf目前创建了一个额外的窗口并单独显示pdf。

这可以用ICEpdf查看器组件实现吗?

附件中是一些图像,以帮助解释正在发生的事情。

编辑/更新:基本上需要一个ICEpdf,而我们需要它在当前窗口中运行。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-09-02 20:58:37

我们想要做的事情不会/不能工作,所以我们只需要通过程序内部的一个按钮在它自己的窗口中打开它。

票数 0
EN

Stack Overflow用户

发布于 2018-05-31 19:00:14

代码语言:javascript
复制
You will need to get border pane in your current window pane   
 /**
     * FXML Controller class
     *
     * @author Sudarshan
     */
    public class PDFFXMLController implements Initializable {    
        private static String pdfPath;
        private SwingController swingController;
        private JComponent viewerPanel;
        @FXML
        private BorderPane borderPane;  
        /**
         * Initializes the controller class.
         */
      @Override
        public void initialize(URL url, ResourceBundle rb) {
         String pdfPathLoad;
        try {
            pdfPathLoad = loadPDF("http://21-04-2017/17854381660C617.pdf");    
            createViewer(borderPane);
            openDocument(pdfPathLoad );
        } catch (IOException ex) {
            Logger.getLogger(PDFFXMLController.class.getName()).log(Level.SEVERE, null, ex);
        }
        }

        private void createViewer(BorderPane borderPane) {
            try {
                SwingUtilities.invokeAndWait(() -> {
                    swingController = new SwingController();
                    swingController.setIsEmbeddedComponent(true);
                    PropertiesManager properties = new PropertiesManager(System.getProperties(),
                            ResourceBundle.getBundle(PropertiesManager.DEFAULT_MESSAGE_BUNDLE));
                    properties.set(PropertiesManager.PROPERTY_SHOW_TOOLBAR_FIT, "false");
                    properties.set(PropertiesManager.PROPERTY_SHOW_TOOLBAR_ROTATE, "false");
                    properties.set(PropertiesManager.PROPERTY_SHOW_TOOLBAR_TOOL, "false");
                    properties.set(PropertiesManager.PROPERTY_DEFAULT_ZOOM_LEVEL, "1.25");
                    properties.setBoolean(PropertiesManager.PROPERTY_SHOW_STATUSBAR_VIEWMODE, Boolean.FALSE);
                    properties.set(PropertiesManager.PROPERTY_SHOW_TOOLBAR_PAGENAV, "false");
                    ResourceBundle messageBundle = ResourceBundle.getBundle(PropertiesManager.DEFAULT_MESSAGE_BUNDLE);
                    new FontPropertiesManager(properties, System.getProperties(), messageBundle);
                    swingController.getDocumentViewController().setAnnotationCallback(
                            new org.icepdf.ri.common.MyAnnotationCallback(swingController.getDocumentViewController()));
                    SwingViewBuilder factory = new SwingViewBuilder(swingController, properties);
                    viewerPanel = factory.buildViewerPanel();
                    viewerPanel.revalidate();
                    SwingNode swingNode = new SwingNode();
                    swingNode.setContent(viewerPanel);
                    borderPane.setCenter(swingNode);
                    swingController.setToolBarVisible(false);
                    swingController.setUtilityPaneVisible(false);
                });
            } catch (InterruptedException | InvocationTargetException e) {
            }
        }
        private void openDocument(String document) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    swingController.openDocument(document);
                    viewerPanel.revalidate();
                }
            });
        }
        public String loadPDF(String adresse) throws IOException {
            System.out.println("In load PDf");
            if (!adresse.toLowerCase().endsWith("pdf")) {
                return null;
            }
            String fileName = adresse.substring(adresse.lastIndexOf("/") + 1,
                    adresse.lastIndexOf("."));
            String suffix = adresse.substring(adresse.lastIndexOf("."),
                    adresse.length());
            File temp = null;
        try {
                InputStream input = new URL(adresse).openStream();
                temp = File.createTempFile(fileName, suffix);
                temp.deleteOnExit();
                Files.copy(input, Paths.get(temp.toURI()),
                        StandardCopyOption.REPLACE_EXISTING);
        } catch (MalformedURLException ex) {
      Logger.getLogger(PDFFXMLController.class.getName()).log(Level.SEVERE, null, ex);
        }
            return temp.getAbsolutePath();
        }

    }
票数 1
EN

Stack Overflow用户

发布于 2016-08-18 05:16:23

它可以查看ICEpdf捆绑包中的./examples/component/ViewerComponentExample.java示例。它将演示如何创建可嵌入的JPanel并设置键盘命令。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37397133

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档