I have seen many topics about it but most of it is old.
I am a new Java learner and have tried to build my first project so that I can apply what I have learned, the idea of the project is simple and it is a program that brings all the PDF files that you have and displays them for you and allows them to be opened and classified and shows the percentage of reading and many other things.
I have finished the section related to fetching and processing PDF files and adding information about them in a database that used for that PDFBox and Derpy library, the interface part is almost finished.
And it's about opening the PDF files. I tried using ICEpdf and succeeded in that, but I had problems displaying a lot of PDF files as the font did not appear clearly and there were not many pictures that did not appear and in Arabic PDF files a lot of text appeared in the form of boxes.
In addition, the ICEpdf format is bad and difficult to change the display language and format.
I tried to use PDF.js but failed to do so, perhaps due to my lack of experience. Indeed, I saw the response here using PDF.js, but it did not work for me even though I wrote the same code in accordance with my program : https://stackoverflow.com/a/42040344/12782195
This code you used to view pdf files with ICEpdf :
import javafx.embed.swing.SwingNode;
import javafx.scene.layout.BorderPane;
import org.icepdf.ri.common.SwingController;
import org.icepdf.ri.common.SwingViewBuilder;
import org.icepdf.ri.util.FontPropertiesManager;
import org.icepdf.ri.util.PropertiesManager;
import javax.swing.*;
import java.lang.reflect.InvocationTargetException;
import java.util.ResourceBundle;
public class PDFFXMLController {
private SwingController swingController;
private JComponent viewerPanel;
public 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, "true");
properties.set(PropertiesManager.PROPERTY_SHOW_TOOLBAR_ROTATE, "true");
properties.set(PropertiesManager.PROPERTY_SHOW_TOOLBAR_TOOL, "true");
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, "true");
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 ignored) {
}
}
public void openDocument(String document) {
SwingUtilities.invokeLater(() -> {
swingController.openDocument(document);
viewerPanel.revalidate();
});
}
}