hrugani
hrugani

Reputation: 477

How do I do to view PDF content saved in Codename One Storage?

In my App, I downloaded several PDF files and saved all of them into Codename One Storage.

Now, I want to write a code that allows the user view the content of each PDF file (one at a time) using any app that can handle PDF (like a PDF viewer).

How do I do that?

Upvotes: 3

Views: 330

Answers (1)

Shai Almog
Shai Almog

Reputation: 52770

See this: https://www.codenameone.com/blog/open-file-rendering.html

Form hi = new Form("PDF Viewer", BoxLayout.y());
Button devGuide = new Button("Show PDF");
devGuide.addActionListener(e -> {
    FileSystemStorage fs = FileSystemStorage.getInstance();
    String fileName = fs.getAppHomePath() + "pdf-sample.pdf";
    if(!fs.exists(fileName)) {
        Util.downloadUrlToFile("http://www.polyu.edu.hk/iaee/files/pdf-sample.pdf", fileName, true);
    }
    Display.getInstance().execute(fileName);
});
hi.add(devGuide);

hi.show();

Upvotes: 2

Related Questions