- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在寻找一种在我的 JavaFx 应用程序中显示 pdf 文件的方法。我正在尝试使用 icePDF 来做到这一点,但我似乎只能找到 swing 的代码。现在我将代码插入到 SwingNode 并将其嵌入到 Pane 中,但问题是包含 icePDF pdf 阅读器的 JPanel 不适合 JavaFx Pane 的大小。
我是这样做的:
private void handleApercuBtn(){
SwingController controller = new SwingController();
SwingViewBuilder factory = new SwingViewBuilder(controller);
JPanel viewerComponentPanel = factory.buildViewerPanel();
ComponentKeyBinding.install(controller, viewerComponentPanel);
controller.getDocumentViewController().setAnnotationCallback(
new org.icepdf.ri.common.MyAnnotationCallback(
controller.getDocumentViewController()));
final SwingNode swingNode = new SwingNode();
createAndSetSwingContent(swingNode,viewerComponentPanel);
apercuPane.getChildren().add(swingNode);
controller.openDocument(filePath);
}
如何将包含 icePDF 阅读器的 JPanel 放入我的面板 (apercuPane)?我怎么能不使用 Swing 代码来执行此操作?
最佳答案
/**
* 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();
}
}
关于JavaFX : display pdf with icepdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32611666/
除了 Display.getOrientation() 已弃用之外,Display.getRotation() 和 Display.getOrientation() 之间还有什么区别? 是否都返回等于
我的问题 这些方法中有哪一种是专业网页设计师所偏爱的吗? Web 浏览器在绘制网站时是否首选这些方法中的任何一种? 这只是个人喜好吗? 我还缺少其他技巧吗? 注意:以上问题是关于设计多列布局 floa
我的问题 专业网页设计师是否喜欢这些方法? 网页浏览器在绘制网站时是否首选这些方法? 这只是个人喜好吗? 我还缺少其他技术吗? 注意:以上问题与设计多列布局有关 float :左; http://js
我有一些代码返回 MyTrait 类型的特征对象,这样它就可以返回几个不同结构之一。我想为 trait 对象实现 Display trait,这样我就可以打印对象,并将详细信息委托(delegate)
package polymorphism; /* * @author Rahul Tripathi */ public class OverLoadingTest { /** *
我希望 Display.timerExec(int,Runnable)与 Display.asyncExec(Runnable) 大致相同但有指定的延迟。然而,似乎Display.timerExec只
就像标题所暗示的,有什么区别吗?我当时使用的是pygame.display.flip,我在互联网上看到的是,他们使用pygame.display.update而不是使用flip。哪一个更快? 最佳答案
Sample.this.display() 和 this.display() 哪个更好? class Sample{ void display(){ System.out.println("d
当图像的 CSS 属性“显示”已被任何其他 JS 脚本/函数更改时,我想运行一些 JS 代码。有什么方法可以监视该更改并设置回调函数吗? $(this).bind.('propertychange',
在浏览 Google 字体时我注意到第一个过滤器包含这些类别: Serif Sans 衬线 展示 手写 我知道什么是 (Sans)Serif 和 Handwriting 类别(这很明显)但是显示类别过
我想知道是否可以在列标记内渲染自定义 html,这是显示表标记的一部分。 例如,我希望我的专栏里面有一些下拉列表? 使用纯 html,如下所示: ... Volvo Saab Me
display.newImage() 和 display.newImageRect() 有什么区别? 哪个更好用? 最佳答案 display.newImage() 的文档具体提到: NOTE: dis
我正在使用纯 JS 和 flexbox 为我的元素创建网格。 元素的某些部分在页面加载时被显示隐藏:无,但单击按钮后它应该在不显示和阻止之间切换。 可悲的是,这完全破坏了 display: flex
我目前正在参加 HTML/CSS 类(class),这本书推荐我使用.desktop {display:none;}/.mobile {display:inline;} 以及div class="de
这个问题在这里已经有了答案: Css transition from display none to display block, navigation with subnav [duplicat
我理解 style="display: none" 隐藏一个 HTML 元素,而 style="display: block" 显示一个 block 级 HTML 元素。 我看到一些使用 style=
设置控件的样式 display: none 和 display: block 有什么区别? 最佳答案 display 属性定义了某个 HTML 元素应该如何显示。 Display block 和 no
这个问题已经有答案了: Javascript AND operator within assignment (7 个回答) 已关闭 4 年前。 假设我只想在 this.state.display 为
我不确定如何命名这个问题,因为我是 Rust 新手,所以请随意提出修改建议。 我有两个结构。一个是 Job 结构,其中包含一些数字,例如作业需要多长时间等。另一个是 JobSequence,其中包含
我不确定如何命名这个问题,因为我是 Rust 新手,所以请随意提出修改建议。 我有两个结构。一个是 Job 结构,其中包含一些数字,例如作业需要多长时间等。另一个是 JobSequence,其中包含
我是一名优秀的程序员,十分优秀!