0

As the title says, I have a PDF document which is stored locally and using Java I would like to open it on an arbitrary page. My question is much the same as this question, however the proposed solution seems rather hacky so I would prefer a more conventional answer if possible. I understand that the code shown below will not work because #page=5 should be appended to the URL in the browser and not the file path, however I'm really not sure what to try next. Any help would be much appreciated!

import java.io.File;
import java.io.IOException;
import java.net.URL;

public class OpenPdfTest {

    public OpenPdfTest(){
        try {
            File myFile = new File("test.pdf");
            URL url = myFile.toURI().toURL();
            Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url + "#page=5");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args){
        new OpenPdfTest();
    }
}
Community
  • 1
  • 1
Hungry
  • 1,645
  • 1
  • 16
  • 26

1 Answers1

0

What about using http://tika.apache.org/ and read the whole file, convert it and use the part of the pdf File that you want. You can read in any File you want with Apache Tika. With this Lib you can open any kind of files, also pdf-Files and proceed them.

Take my Answer just as a first guess.

Marty_in_a_Box
  • 401
  • 4
  • 8