I was writing code to merge .pdf documents when I wrote this line:
PDFmerger.mergeDocuments();
When I wrote it, Java told me that The method mergeDocuments()
from the type PDFMergerUtility
is deprecated, and told me to add this line:
@SuppressWarnings("deprecation")
and later, it has the command mergeDocuments();
struck through. This command still works, but I would like to ask: Why did my code cross out the line? The code still works, but I don't know why this happens. By the way, I am using PDFBox to merge two different pdfs. The full code is below (and imagine a line running across the text .mergedocuments()):
JButton btnMerge = new JButton("Merge");
btnMerge.addActionListener(new ActionListener() {
@SuppressWarnings("deprecation")
public void actionPerformed(ActionEvent e) {
try {
PDDocument doc1 = PDDocument.load(rearrange[0]);
PDDocument doc2 = PDDocument.load(rearrange[1]);
PDDocument doc3 = PDDocument.load(rearrange[2]);
//Instantiating PDFMergerUtility class
PDFMergerUtility PDFmerger = new PDFMergerUtility();
String finalname = name.substring(0, 8);
PDFmerger.setDestinationFileName(path.replace(name, finalname+"_Pin Plug List.pdf"));
PDFmerger.addSource(rearrange[0]);
PDFmerger.addSource(rearrange[1]);
PDFmerger.addSource(rearrange[2]);
PDFmerger.mergeDocuments();
doc1.close();
doc2.close();
doc3.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
btnMerge.setFont(new Font("Tahoma", Font.PLAIN, 20));
btnMerge.setBounds(12, 261, 388, 50);
contentPane.add(btnMerge);