Is it possible to open on a given PDF page?

Asked

Viewed 85 times

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();
}

inserir a descrição da imagem aqui

I tried to change the line that calls the pdf file to:

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

But the parameters were ignored.

  • Already tried to execute as process? acrobat.exe /A "page=2" "C:/testes/teste.pdf"

  • I’ve never used it like this, it would have to give me an example of how to run as a process?

  • You want to open the file on a given page or open "page x" and manipulate its content in your application?

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();
  • Perfect @joccafi. It worked like this. Know if I can do it this way only by opening the browser?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.