Jump to content
MrGrj

Export PDF to Excel

Recommended Posts

  • Active Members
Posted (edited)

Am facut recent un mic proiect in Java, care exporta anumite date(nume,prenume,sex,telefon,email,limbi straine cunoscute) dintr-un PDF ( in cazul meu un CV de pe Ejobs sau BestJobs) intr-un Excel.

De mentionat ca functioneaza doar in cazul CV-urilor downloadate de catre angajator

Aveti mai jos codul. Poate este util cuiva.


package elance.pdf.cv;

import java.awt.Desktop;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.prefs.Preferences;
import javax.imageio.ImageIO;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.util.PDFTextStripper;

public class win extends javax.swing.JFrame {

private Preferences pref = Preferences.userNodeForPackage(getClass());
private Point initialClick;
private final String cv0 = "Nici un CV gasit";
private final String cv1 = "1 CV";
private ArrayList<String[]> details_best = new ArrayList<>();
private ArrayList<String[]> details_ejobs = new ArrayList<>();

public win() {
super("Aplicatie PDF to Excel");
setResizable(false);
setUndecorated(true);
setLocation(100, 100);
initComponents();

moveUndecoratedFrame();

imageButton(jButton1, "close.png", "close2.png");
imageButton(jButton2, "best2.png", "best3.png");
imageButton(jButton3, "ejobs2.png", "ejobs3.png");
imageButton(jButton4, "loadfolder.png", "loadfolder2.png");
imageButton(jButton5, "loadfolder.png", "loadfolder2.png");
imageButton(jButton6, "openfile.png", "openfile2.png");
imageButton(jButton7, "opencv.png", "opencv2.png");
imageButton(jButton8, "openfile.png", "openfile2.png");
imageButton(jButton9, "opencv.png", "opencv2.png");
imageButton(jButton10, "loadfiles.png", "loadfiles2.png");
imageButton(jButton11, "loadfiles.png", "loadfiles2.png");

jTextField1.setText(pref.get("best", ""));
jTextField2.setText(pref.get("ejobs", ""));
try {
if (jTextField1.getText().length() > 0) {
numberOfCVs(jTextField3, jTextField1.getText());
}
if (jTextField2.getText().length() > 0) {
numberOfCVs(jTextField4, jTextField2.getText());
}
} catch (Exception ex) {
}
}

@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

jPanel1 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
jButton2 = new javax.swing.JButton();
jTextField1 = new javax.swing.JTextField();
jButton4 = new javax.swing.JButton();
jTextField3 = new javax.swing.JTextField();
jButton6 = new javax.swing.JButton();
jButton7 = new javax.swing.JButton();
jButton10 = new javax.swing.JButton();
jPanel3 = new javax.swing.JPanel();
jButton3 = new javax.swing.JButton();
jTextField2 = new javax.swing.JTextField();
jButton5 = new javax.swing.JButton();
jTextField4 = new javax.swing.JTextField();
jButton8 = new javax.swing.JButton();
jButton9 = new javax.swing.JButton();
jButton11 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jPanel1.setBackground(new java.awt.Color(255, 255, 255));
jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

jButton1.setBackground(new java.awt.Color(255, 255, 255));
jButton1.setBorder(null);
jButton1.setMargin(new java.awt.Insets(0, 0, 0, 0));
jButton1.setPreferredSize(new java.awt.Dimension(20, 20));
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jPanel2.setBackground(new java.awt.Color(255, 255, 255));
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("BestJobs"));

jButton2.setBorder(null);
jButton2.setMargin(new java.awt.Insets(0, 0, 0, 0));
jButton2.setPreferredSize(new java.awt.Dimension(223, 55));
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

jTextField1.setEditable(false);
jTextField1.setMaximumSize(new java.awt.Dimension(216, 20));
jTextField1.setPreferredSize(new java.awt.Dimension(216, 20));

jButton4.setBackground(new java.awt.Color(255, 255, 255));
jButton4.setBorder(null);
jButton4.setMargin(new java.awt.Insets(0, 0, 0, 0));
jButton4.setPreferredSize(new java.awt.Dimension(90, 20));
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});

jTextField3.setEditable(false);
jTextField3.setBackground(new java.awt.Color(255, 255, 255));
jTextField3.setText("Status");

jButton6.setBackground(new java.awt.Color(255, 255, 255));
jButton6.setBorder(null);
jButton6.setMargin(new java.awt.Insets(0, 0, 0, 0));
jButton6.setPreferredSize(new java.awt.Dimension(90, 20));
jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton6ActionPerformed(evt);
}
});

jButton7.setBackground(new java.awt.Color(255, 255, 255));
jButton7.setBorder(null);
jButton7.setMargin(new java.awt.Insets(0, 0, 0, 0));
jButton7.setPreferredSize(new java.awt.Dimension(90, 20));
jButton7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton7ActionPerformed(evt);
}
});

jButton10.setBackground(new java.awt.Color(255, 255, 255));
jButton10.setBorder(null);
jButton10.setMargin(new java.awt.Insets(0, 0, 0, 0));
jButton10.setPreferredSize(new java.awt.Dimension(90, 20));
jButton10.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton10ActionPerformed(evt);
}
});

javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jTextField3)
.addComponent(jTextField1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jButton6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton7, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);

jPanel3.setBackground(new java.awt.Color(255, 255, 255));
jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("EJobs"));

jButton3.setBorder(null);
jButton3.setMargin(new java.awt.Insets(0, 0, 0, 0));
jButton3.setPreferredSize(new java.awt.Dimension(223, 55));
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});

jTextField2.setEditable(false);
jTextField2.setMaximumSize(new java.awt.Dimension(216, 20));
jTextField2.setPreferredSize(new java.awt.Dimension(216, 20));

jButton5.setBackground(new java.awt.Color(255, 255, 255));
jButton5.setBorder(null);
jButton5.setMargin(new java.awt.Insets(0, 0, 0, 0));
jButton5.setPreferredSize(new java.awt.Dimension(90, 20));
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});

jTextField4.setEditable(false);
jTextField4.setBackground(new java.awt.Color(255, 255, 255));
jTextField4.setText("Status");

jButton8.setBackground(new java.awt.Color(255, 255, 255));
jButton8.setBorder(null);
jButton8.setMargin(new java.awt.Insets(0, 0, 0, 0));
jButton8.setPreferredSize(new java.awt.Dimension(90, 20));
jButton8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton8ActionPerformed(evt);
}
});

jButton9.setBackground(new java.awt.Color(255, 255, 255));
jButton9.setBorder(null);
jButton9.setMargin(new java.awt.Insets(0, 0, 0, 0));
jButton9.setPreferredSize(new java.awt.Dimension(90, 20));
jButton9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton9ActionPerformed(evt);
}
});

jButton11.setBackground(new java.awt.Color(255, 255, 255));
jButton11.setBorder(null);
jButton11.setMargin(new java.awt.Insets(0, 0, 0, 0));
jButton11.setPreferredSize(new java.awt.Dimension(90, 20));
jButton11.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton11ActionPerformed(evt);
}
});

javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jTextField4)
.addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(jButton9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(0, 0, Short.MAX_VALUE))
.addComponent(jButton11, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel3Layout.createSequentialGroup()
.addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
);

pack();
}// </editor-fold>//GEN-END:initComponents

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
System.exit(0);
}//GEN-LAST:event_jButton1ActionPerformed

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
String x = loadFolder();
jTextField1.setText(x);
pref.put("best", x);
numberOfCVs(jTextField3, x);
}//GEN-LAST:event_jButton4ActionPerformed

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
String x = loadFolder();
jTextField2.setText(x);
pref.put("ejobs", x);
numberOfCVs(jTextField4, x);
}//GEN-LAST:event_jButton5ActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
details_best.clear();
String folder = jTextField1.getText();

if (folder.length() < 1) {
return;
}
if (jTextField3.getText().equalsIgnoreCase(cv0)) {
message("Nici un CV gasit in folderul respectiv");
return;
} else {
ArrayList<String> files = new ArrayList<>();
if (new File(folder).isDirectory()) {
files = getCVsFromFolder(folder);
} else {
for (String h : folder.split(";")) {
files.add(h);
}
folder = new File(folder.split(";")[0]).getParent().toString();
}
for (String f : files) {
String nume = "";
String sex = "";
String telefon = "";
String mail = "";
String limbi = "";
String[] det = new String[6];
String x = readPDFasText(f);
String[] x2 = x.split("\n");
for (int i = 0; i < x2.length; i++) {
// nume = x2[0].replace("\n", "");
// sex = getSex(x2[1]);
int indexTelefon=0;
if (x2[i].toLowerCase().indexOf("mobil:") == 0) {
telefon = getTelefon(x2[i]);
indexTelefon=i;
}
int indexNume=0;
for(int j=indexTelefon;j>0;j--){
if(getSex(x2[j]).length()>0){
sex=getSex(x2[j]);
indexNume=j;
}
}
if(indexNume>0){
nume = x2[indexNume-1].replace("\n", "");
}

if (x2[i].toLowerCase().indexOf("email:") == 0) {
mail = getMail(x2[i]);
}
if (x2[i].toLowerCase().indexOf("limbi straine") == 0) {
for (int j = 1; j < x2.length - i; j++) {
if (x2[i + j].toLowerCase().indexOf("certificari") == 0) {
break;
}
limbi += x2[i + j].trim() + " ";
}
}
}
det[0] = "0";
det[1] = nume.trim();
det[2] = sex.trim();
det[3] = telefon.trim();
det[4] = mail.trim();
det[5] = limbi.trim();
details_best.add(det);
}
String[][] table = new String[details_best.size() + 1][5];
String[] headers = new String[]{"ID", "Nume", "Sex", "Telefon", "Email", "Limbi straine"};
table[0] = headers;
for (int i = 1; i < table.length; i++) {
table[i] = details_best.get(i - 1);
table[i][0] = i + "";
}
// determina celalat fisier
String dir = jTextField2.getText();
if (!new File(dir).isDirectory()) {
dir = new File(dir.split(";")[0]).getParent().toString();
}
String othertable = dir + File.separator + "Candidati Ejobs.xls";
if (new File(othertable).exists()) {
verificaDubluri(table, readsheet(othertable));
}
try {
scriefisier(table, folder + File.separator + "Candidati BestJobs.xls");
jTextField3.setText("fisier pregatit");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}//GEN-LAST:event_jButton2ActionPerformed

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
String dir = jTextField1.getText();
if (!new File(dir).isDirectory()) {
dir = new File(dir.split(";")[0]).getParent().toString();
}
openFile(dir + File.separator + "Candidati BestJobs.xls");
}//GEN-LAST:event_jButton6ActionPerformed

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
details_ejobs.clear();
String folder = jTextField2.getText();
if (folder.length() < 1) {
return;
}
if (jTextField4.getText().equalsIgnoreCase(cv0)) {
message("Nici un CV gasit in folderul respectiv");
return;
} else {
ArrayList<String> files = new ArrayList<>();
if (new File(folder).isDirectory()) {
files = getCVsFromFolder(folder);
} else {
for (String h : folder.split(";")) {
files.add(h);
}
folder = new File(folder.split(";")[0]).getParent().toString();
}
for (String f : files) {
String nume = "";
String sex = "";
String telefon = "";
String mail = "";
String limbi = "";
String[] det = new String[6];
String x = readPDFasText(f);
String[] x2 = x.split("\n");
for (int i = 0; i < x2.length; i++) {
nume = x2[0].replace("\n", "");
sex = getSex_ejobs(x2[3].trim());
if (x2[i].trim().toLowerCase().indexOf("telefon:") == 0) {
telefon = getTelefon(x2[i]);
}
if (x2[i].trim().toLowerCase().indexOf("email") == 0) {
mail = getMail_ejobs(x2[i].trim());
}
if (x2[i].toLowerCase().indexOf("limbi straine (nivel cunoastere):") >= 0) {
for (int j = 1; j < x2.length - i; j++) {
if (x2[i + j].trim().toLowerCase().indexOf("abilitati") == 0) {
break;
}
limbi += x2[i + j].trim() + " ";
}
}
}
det[0] = "0";
det[1] = nume.trim();
det[2] = sex.trim();
det[3] = telefon.trim();
det[4] = mail.trim();
det[5] = limbi.trim();
details_ejobs.add(det);
}
String[][] table = new String[details_ejobs.size() + 1][5];
String[] headers = new String[]{"ID", "Nume", "Sex", "Telefon", "Email", "Limbi straine"};
table[0] = headers;
for (int i = 1; i < table.length; i++) {
table[i] = details_ejobs.get(i - 1);
table[i][0] = i + "";
}
// determina celalat fisier
String dir = jTextField1.getText();
if (!new File(dir).isDirectory()) {
dir = new File(dir.split(";")[0]).getParent().toString();
}
String othertable = dir + File.separator + "Candidati BestJobs.xls";
if (new File(othertable).exists()) {
verificaDubluri(table, readsheet(othertable));
}
try {
scriefisier(table, folder + File.separator + "Candidati Ejobs.xls");
jTextField4.setText("fisier pregatit");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}//GEN-LAST:event_jButton3ActionPerformed

private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
details_best.clear();
String folder = jTextField1.getText();
ArrayList<String> files = new ArrayList<>();
if (new File(folder).isDirectory()) {
files = getCVsFromFolder(folder);
} else {
for (String h : folder.split(";")) {
files.add(h);
}
folder = new File(folder.split(";")[0]).getParent().toString();
}
if (folder.length() < 1) {
return;
}
for (String f : files) {
String nume = "";
String sex = "";
String telefon = "";
String mail = "";
String limbi = "";
String[] det = new String[6];
String x = readPDFasText(f);
String[] x2 = x.split("\n");
for (int i = 0; i < x2.length; i++) {
nume = x2[0].replace("\n", "");
sex = getSex(x2[1]);
if (x2[i].toLowerCase().indexOf("mobil:") == 0) {
telefon = getTelefon(x2[i]);
}
if (x2[i].toLowerCase().indexOf("email:") == 0) {
mail = getMail(x2[i]);
}
if (x2[i].toLowerCase().indexOf("limbi straine") == 0) {
for (int j = 1; j < x2.length - i; j++) {
if (x2[i + j].toLowerCase().indexOf("certificari") == 0) {
break;
}
limbi += x2[i + j].trim() + " ";
}
}
}
det[0] = "0";
det[1] = nume.trim();
det[2] = sex.trim();
det[3] = telefon.trim();
det[4] = mail.trim();
det[5] = limbi.trim();
details_best.add(det);
}
int x = -1;
if (details_best.size() < 1) {
return;
} else if (details_best.size() == 1) {
openFile(files.get(0));
return;
}
String t = JOptionPane.showInputDialog(null, "Introdu ID-ul! (intre 1 - " + details_best.size() + ")", "");
try {
x = Integer.parseInt(t);
x = Math.abs(x);
} catch (Exception ex) {
}
if (x < 0 || x > details_best.size()) {
return;
}
// ArrayList<String> files = getCVsFromFolder(jTextField1.getText());
openFile(files.get(x - 1));
}//GEN-LAST:event_jButton7ActionPerformed

private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
details_ejobs.clear();
String folder = jTextField2.getText();
if (folder.length() < 1) {
return;
}
ArrayList<String> files = new ArrayList<>();
if (new File(folder).isDirectory()) {
files = getCVsFromFolder(folder);
} else {
for (String h : folder.split(";")) {
files.add(h);
}
folder = new File(folder.split(";")[0]).getParent().toString();
}
for (String f : files) {
String nume = "";
String sex = "";
String telefon = "";
String mail = "";
String limbi = "";
String[] det = new String[6];
String x = readPDFasText(f);
String[] x2 = x.split("\n");
for (int i = 0; i < x2.length; i++) {
nume = x2[0].replace("\n", "");
sex = getSex_ejobs(x2[3].trim());
if (x2[i].trim().toLowerCase().indexOf("telefon:") == 0) {
telefon = getTelefon(x2[i]);
}
if (x2[i].trim().toLowerCase().indexOf("email") == 0) {
mail = getMail_ejobs(x2[i].trim());
}
if (x2[i].toLowerCase().indexOf("limbi straine (nivel cunoastere):") >= 0) {
for (int j = 1; j < x2.length - i; j++) {
if (x2[i + j].trim().toLowerCase().indexOf("abilitati") == 0) {
break;
}
limbi += x2[i + j].trim() + " ";
}
}
}
det[0] = "0";
det[1] = nume.trim();
det[2] = sex.trim();
det[3] = telefon.trim();
det[4] = mail.trim();
det[5] = limbi.trim();
details_ejobs.add(det);
}
int x = -1;
if (details_ejobs.size() < 1) {
return;
} else if (details_ejobs.size() == 1) {
openFile(files.get(0));
return;
}
String t = JOptionPane.showInputDialog(null, "Introdu ID-ul! (intre 1 - " + details_ejobs.size() + ")", "");
try {
x = Integer.parseInt(t);
x = Math.abs(x);
} catch (Exception ex) {
}
if (x < 0 || x > details_ejobs.size()) {
return;
}
openFile(files.get(x - 1));
}//GEN-LAST:event_jButton9ActionPerformed

private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
String dir = jTextField2.getText();
if (!new File(dir).isDirectory()) {
dir = new File(dir.split(";")[0]).getParent().toString();
}
openFile(dir + File.separator + "Candidati Ejobs.xls");

}//GEN-LAST:event_jButton8ActionPerformed

private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
String x = loadfile();
jTextField1.setText(x);
String[] files = x.split(";");
if (files.length == 0) {
jTextField3.setText(cv0);
} else if (files.length == 1) {
jTextField3.setText(cv1);
} else {
jTextField3.setText(files.length + " CV-uri");
}
pref.put("best", x);
}//GEN-LAST:event_jButton10ActionPerformed

private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
String x = loadfile();
jTextField2.setText(x);
pref.put("ejobs", x);
numberOfCVs(jTextField4, x);
}//GEN-LAST:event_jButton11ActionPerformed

public static void run() {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new win().setVisible(true);
}
});
}

private void moveUndecoratedFrame() {
this.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
initialClick = e.getPoint();
getComponentAt(initialClick);
}
});

this.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent e) {
// get location of Window
int thisX = getLocation().x;
int thisY = getLocation().y;
// Determine how much the mouse moved since the initial click
int xMoved = (thisX + e.getX()) - (thisX + initialClick.x);
int yMoved = (thisY + e.getY()) - (thisY + initialClick.y);
// Move window to this position
int X = thisX + xMoved;
int Y = thisY + yMoved;
setLocation(X, Y);
}
});
}

private String readPDFasText(String pdfFile) {
String result = "";
PDDocument doc;
try {
// doc = new PDDocument();
doc = PDDocument.load(pdfFile);
PDFTextStripper textStripper = new PDFTextStripper();
result = textStripper.getText(doc);
doc.close();
} catch (Exception ex) {
System.out.println("readPDFasText - " + ex.getMessage());
}
// System.out.println(result);
return result;
}

private String loadfile() {
JFileChooser choose = new JFileChooser(System.getProperty("user.home") + File.separator + "Desktop");
choose.setMultiSelectionEnabled(true);
Action details = choose.getActionMap().get("viewTypeDetails");
details.actionPerformed(null);
choose.showOpenDialog(null);
File[] files = choose.getSelectedFiles();
String x = "";
if (files.length > 1) {
for (File f : files) {
x += f.getPath() + ";";
}
x = x.substring(0, x.length() - 1);
} else {
try {
x = choose.getSelectedFile().getPath();
} catch (Exception ex) {
}
}
return x;
}

private static void openurl(String url) {
try {
Desktop.getDesktop().browse(new URI(url));
} catch (Exception ex) {
}
}

private void openFile(String file) {
try {
Desktop.getDesktop().open(new File(file));
} catch (Exception ex) {
}
}

private void imageButton(JButton but, String image1, String image2) {
try {
but.setRolloverIcon(new ImageIcon(ImageIO.read(getClass().getResource("/" + image2))));
but.setRolloverEnabled(true);
but.setIcon(new ImageIcon(ImageIO.read(getClass().getResource("/" + image1))));
} catch (Exception ex) {
}
}

public static void scriefisier(String[][] tabel, String nume) throws IOException, WriteException {
try {
WritableWorkbook wb = Workbook.createWorkbook(new File(nume));
WritableSheet sheet = wb.createSheet("Sheet1", 0);
int[] columns = new int[tabel[0].length];
for (int i = 0; i < columns.length; i++) {
columns[i] = 5;
}
for (int i = 0; i < tabel.length; i++) {
for (int j = 0; j < tabel[i].length; j++) {
sheet.addCell(new Label(j, i, tabel[i][j]));
columns[j] = Math.max(columns[j], tabel[i][j].length() + 3);
}
}
for (int i = 0; i < columns.length; i++) {
sheet.setColumnView(i, columns[i]);
}
wb.write();
wb.close();
} catch (Exception ex) {
}
}

private String loadFolder() {
JFileChooser choose = new JFileChooser();
choose.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
choose.showOpenDialog(null);
String x = "";
try {
x = choose.getSelectedFile().getPath();
} catch (Exception ex) {
}
return x;
}

private ArrayList<String> getCVsFromFolder(String folder) {
// returneaza toate pdfurile din folderul respectiv
// asa se poate afla numarul lor si adresa dintr-o singure metoda
ArrayList<String> result = new ArrayList<>();
File f = new File(folder);
if (f.isDirectory()) {
File[] all = f.listFiles();
for (File g : all) {
String name = g.toString();
if (name.substring(name.length() - 4).equalsIgnoreCase(".pdf")) {
result.add(name);
}
}
}
return result;
}

private void message(String message) {
JOptionPane.showMessageDialog(null, message, "", JOptionPane.ERROR_MESSAGE);
}

private void p(Object t) {
System.out.println(t);
}

private void numberOfCVs(JTextField displayResult, String folder) {
ArrayList<String> files = new ArrayList<>();
if (new File(folder).isDirectory()) {
files = getCVsFromFolder(folder);
} else {
for (String h : folder.split(";")) {
files.add(h);
}
folder = new File(folder.split(";")[0]).getParent().toString();
}
if (files.size() == 0) {
displayResult.setText(cv0);
} else if (files.size() == 1) {
displayResult.setText(cv1);
} else {
displayResult.setText(files.size() + " CV-uri");
}
}

private String getSex(String text) {
String result = "";
if (text.indexOf("(") == 0) {
text = text.substring(1);
if (text.toLowerCase().indexOf("m") == 0/*mascul, masculin*/ || text.toLowerCase().indexOf("b") == 0/*barbat*/) {
result = "masculin";
} else if (text.toLowerCase().indexOf("f") == 0) {
result = "feminin";
}
}
return result;
}

private String getSex_ejobs(String text) {
String result = "";
if (text.toLowerCase().indexOf("m") == 0/*mascul, masculin*/ || text.toLowerCase().indexOf("b") == 0/*barbat*/) {
result = "masculin";
} else if (text.toLowerCase().indexOf("f") == 0) {
result = "feminin";
}
return result;
}

private String getTelefon(String text) {
String result = "";
result = text.substring(text.indexOf(":") + 1);
return result;
}

private String getMail(String text) {
String result = "";
result = text.substring(text.indexOf(":") + 1);
return result;
}

private String getMail_ejobs(String text) {
String result = "";
result = text.substring(text.indexOf(" ") + 1);
return result.trim();
}

private String[][] readsheet(String file) {
//reads the first sheet from an excel file
String[][] tt; // the file in table format
Workbook workbook;
Sheet sheet = null;
try {
workbook = Workbook.getWorkbook(new File(file));
sheet = workbook.getSheet(0); // 0 is the first sheet
} catch (IOException | IndexOutOfBoundsException | BiffException exec) {
JOptionPane.showMessageDialog(null, exec, "not working!!", JOptionPane.ERROR_MESSAGE);
}
int x = sheet.getRows();
int y = sheet.getColumns();
tt = new String[x][y];
for (int i = 0; i < tt.length; i++) {
for (int j = 0; j < tt[0].length; j++) {
try {
tt[i][j] = sheet.getCell(j, i).getContents().toString() + "";
} catch (Exception ex) {
}
}
}
return tt;
}

private void verificaDubluri(String[][] candidatiNoi, String[][] candidatiVechi) {
for (int i = 1; i < candidatiNoi.length; i++) {
for (int j = 0; j < candidatiVechi.length; j++) {
if (candidatiNoi[i][3].equals(candidatiVechi[j][3])) {
message("Telefon duplicat pentru candidatul\n" + candidatiNoi[i][1].toUpperCase());
break;
}
}
}
}

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton10;
private javax.swing.JButton jButton11;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JButton jButton7;
private javax.swing.JButton jButton8;
private javax.swing.JButton jButton9;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
// End of variables declaration//GEN-END:variables
}

Sursa aplicatie: FileShare Download Sursa-program-PDF-to-Excel.rar

Aplicatia propriu-zisa: FileShare Download Aplicatie PDF to Excel - final.rar

Edited by MrGrj
  • Upvote 1
Posted

Bun si util :D

Doua mici corecturi in win.java (ai inversat numele a doua text field-uri):

Linia 446 (metoda jButton2ActionPerformed):

- String dir = jTextField2.getText();
+ String dir = jTextField1.getText();

Linia 533 (metoda jButton3ActionPerformed):

- String dir = jTextField1.getText();
+ String dir = jTextField2.getText();

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...