I need to save a file only as pdf documents in java swings using a filechooser button . Can U please — oracle-tech

    Forum Stats

  • 3,702,028 Users
  • 2,239,548 Discussions
  • 7,835,719 Comments

Discussions

I need to save a file only as pdf documents in java swings using a filechooser button . Can U please

private void exportPDF() {

       

        JFileChooser filechoose=new JFileChooser();

            filechoose.addChoosableFileFilter(new FileNameExtensionFilter( "PDF Documents","pdf"));

            filechoose.setAcceptAllFileFilterUsed(true);

            filechoose.showSaveDialog(null);

            f=filechoose.getSelectedFile();

            try{

                f1 = new File(f.getAbsolutePath());

            try (FileWriter fw = new FileWriter(f1.getAbsoluteFile());

                   BufferedWriter bw = new BufferedWriter(fw)) {              

                   for(int j = 0; j < table.getColumnCount(); j++){

                       bw.write(table.getColumnName(j)+"\t");

                   }

                       bw.write("\n");

                   for(int i = 0; i < table.getRowCount(); i++){

                   for(int j = 0; j < table.getColumnCount(); j++){

                       bw.write(table.getModel().getValueAt(i, j)+"\t");

                   }

                       bw.write("\n");

                   }

               }

               JOptionPane.showMessageDialog(null, "Data Stored successfully ");

               }catch(IOException | HeadlessException ex){

               }

    }

                         This is my code , it is saving only as a file nd it is not opening in pdf format .... please help me find a solution for this guys     @Ashok

This discussion has been closed.