0

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();
        });
    }
}
Tilman Hausherr
  • 17,731
  • 7
  • 58
  • 97
ismael
  • 3
  • 2
  • You can try the system property -Dorg.icepdf.core.awtFontLoading=true. I can help in some instances. The open source project is going through some changes of late and hopefully better font rendering will be available soon. – pcorless Feb 11 '20 at 04:30
  • IIRC there are two ICEpdf versions, the free one has less font support and the paid one has very good font support. I am removing the PDF.js label, this is a separate project and your question is really about ICEpdf (you are of course welcome to ask more questions). I'll also clean up your question slightly, there is no need to apologize. – Tilman Hausherr Feb 11 '20 at 10:08
  • It would also help if you link to one of the PDFs that doesn't display properly. – Tilman Hausherr Feb 11 '20 at 10:12
  • I know there is a paid version but I try to limit myself to free software, and also there is no way to pay in my area – ismael Feb 11 '20 at 11:20
  • I mentioned you pdf.js to avoid suggesting it from anyone, i will try again with it before i ask my question about it – ismael Feb 11 '20 at 11:22
  • You can post an issue/ticket for the os version here, https://github.com/pcorless/icepdf/issues – pcorless Feb 11 '20 at 16:31

0 Answers0