Is it possible to open a particular PDF page?

0
public static void main(String[] args) throws IOException, BiffException {
    Workbook workbook = Workbook.getWorkbook(new File("C:\testes\teste.xls"));
    Sheet sheet = workbook.getSheet(0);
    int linhas = sheet.getRows();
    File pdfFile = new File("C:\testes\teste.pdf");

    System.out.println("Iniciando a leitura da planilha XLS:");

    for (int i = 0; i < linhas; i++) {
        Cell a1 = sheet.getCell(0, i);
        Cell a2 = sheet.getCell(1, i);
        Cell a3 = sheet.getCell(2, i);

        String as1 = a1.getContents();
        String as2 = a2.getContents();
        String as3 = a3.getContents();

        if ("-".equals(as2)) {
            System.out.println("Coluna 1: " + as1);
            System.out.println("Coluna 2: Completar ");
            System.out.println("Coluna 3: " + as3);
            Desktop.getDesktop().open(pdfFile); //Abri o arquivo PDF na primeira página

        } else {

        System.out.println("Coluna 1: " + as1);
        System.out.println("Coluna 2: " + as2);
        System.out.println("Coluna 3: " + as3);
        }
    }
    workbook.close();
}

Itriedtochangethelinethatcallsthepdffileto:

Desktop.getDesktop().browse(newURI(pdfFile.toURI().toString()+"?page=2&zoom=10"));

But the parameters were ignored.

    
asked by anonymous 19.08.2016 / 13:45

1 answer

2

Use the following solution for Windows with Adobe Acrobat installed:

String cmd = "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe";
File pdfFile= new File ("C:\Seu Diretorio\Java.pdf");
String param1 = "/A";
String param2 = "page=1";

String[] cmds = new String[]{cmd, param1, param2, pdfFile.getAbsolutePath()};       
Process p = new ProcessBuilder(cmds).start();
    
19.08.2016 / 17:01