0 Replies Latest reply on May 3, 2016 10:36 AM by f5549e64-3b64-404c-8f7a-1c109bcef5cb

    I need to save a file only as pdf documents in java swings using a filechooser button . Can U please guys help me out in finding the solution for it???

    f5549e64-3b64-404c-8f7a-1c109bcef5cb

      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