Hi @Basha!
Here's a code to help you with your problem statement. I have used ZeonPad to convert .msg to .pdf and used PDFBox to merge the pdfs files:
import java.io.File;
public class pdf {
public static void main(String[] args) {
// TODO Auto-generated method stub
String path = "path to folder";
File folder = new File(path);
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
String name=listOfFiles[i].getName();
//System.out.println(name);
String substring = name.length() > 4 ? name.substring(name.length() - 4) : name;
//System.out.println(substring);
if (substring.equals(".msg")) {
String fullname=path+"\\\\"+name;
System.out.println(fullname);
System.out.println(substring);
String pdfname=fullname.substring(0, fullname.length() - 4);
pdfname=pdfname+".pdf";
System.out.println(pdfname);
OutlookToPdf outlookToPdf = new OutlookToPdf();
OutlookToPdf.convert(fullname, pdfname);
}
}
File file = new File("path of the new file")
PDDocument document = PDDocument.load(file);
PDFMergerUtility PDFmerger = new PDFMergerUtility();
PDFmerger.setDestinationFileName(path+"/merged.pdf");
for (int i = 0; i < listOfFiles.length; i++) {
String name=listOfFiles[i].getName();
//System.out.println(name);
String substring = name.length() > 4 ? name.substring(name.length() - 4) : name;
//System.out.println(substring);
if (substring.equals(".pdf")) {
String fullname=path+"\\\\"+name;
//System.out.println(fullname);
PDFmerger.addSource(fullname);
}
PDFmerger.mergeDocuments();
}
}
}