Fórum Abrir um arquivo pdf em java #566918
09/04/2009
0
Fabio Volpe
Curtir tópico
+ 0Posts
09/04/2009
Fabio Volpe
Runtime.getRuntime().exec(//aki vc digita o codigo que voce usaria no prompot);
Gostei + 0
09/04/2009
Fabio Volpe
package pdfpaneltest;
import com.sun.pdfview.PDFFile;
import com.sun.pdfview.PDFPage;
import com.sun.pdfview.PagePanel;
import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import javax.swing.*;
/**
* An example of using the PagePanel class to show PDFs. For more advanced
* usage including navigation and zooming, look ad the
* com.sun.pdfview.PDFViewer class.
*
* @author joshua.marinacci@sun.com
*/
public class Main {
public static void setup() throws IOException {
//set up the frame and panel
JFrame frame = new JFrame("PDF Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
PagePanel panel = new PagePanel();
frame.add(panel);
frame.pack();
frame.setVisible(true);
//load a pdf from a byte buffer
File file = new File("test.pdf");
RandomAccessFile raf = new RandomAccessFile(file, "r");
FileChannel channel = raf.getChannel();
ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY,
0, channel.size());
PDFFile pdffile = new PDFFile(buf);
// show the first page
PDFPage page = pdffile.getPage(0);
panel.showPage(page);
}
public static void main(final String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
Main.setup();
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
}
}
Gostei + 0
09/04/2009
Carlos H
File pdf = new File("arquivo.pdf");
try {
Desktop.getDesktop().open(pdf);
} catch(Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(null, "Erro no Desktop: " + ex);
}
Gostei + 0
03/04/2012
Ramiro Pamponet
Gostei + 0
28/08/2013
Fabio Volpe
String caminho = txtSalvoem.getText();
File arquivo = new File(caminho);
try {
Desktop.getDesktop().open(arquivo);
} catch (Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(null, ex, "ERRO",JOptionPane.ERROR_MESSAGE);
}Gostei + 0
28/08/2013
Ramiro Pamponet
JFileChooser arquivo = new JFileChooser();//instancia da classe JFileChooser
String caminhoArquivo = "";
int retorno = arquivo.showOpenDialog(null);//variavel recebendo o caminho escolhido por vc
if (retorno == JFileChooser.APPROVE_OPTION) {
caminhoArquivo = arquivo.getSelectedFile().getAbsolutePath();
txtSalvoem.setText("" + caminhoArquivo);//campo recebendo o caminho do arquivo
} else {
//não abriu
}
String caminho = txtSalvoem.getText();
File arquivo = new File(caminho);
try {
Desktop.getDesktop().open(arquivo);
} catch (Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(null, ex, "ERRO",JOptionPane.ERROR_MESSAGE);
}Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)