Hi Aspose Team, we need some help with the Aspose PDF java library. We are building a document management solution in Mulesoft (with Java plugin) which will have the option to upload and download documents. Users can upload a document of any type (pdf, tiff, gif, jpg, jpeg, png, doc, docx, xlsx) for a given order. An order can have multiple files associated with it. While downloading an order, we need to merge all these files into one single PDF and send back to the user.
We just need help with the download part. The input to the java function will be an array of base64 encoded strings, which can contain any number of files of the types mentioned above. We need to iterate through the list and add them to a PDF document.
We are not java or aspose experts so will appreciate any help in this regard! Please find below a skeleton code of what we are trying to do -
public class Merge {
public static Object createPdf(String[] base64EncodedFiles, String[] fileTypes, String orderNum) {
try {
System.out.println("**** PDF BUILDING STARTED ****");
System.out.println(base64EncodedFiles.length);
System.out.println(fileTypes);
Base64.Decoder dec = Base64.getDecoder();
List<InputStream> list = new ArrayList<InputStream>();
System.out.println("**** PDF FILES SETUP STARTED ****");
for (int i = 0; i < base64EncodedFiles.length; i++){
byte[] decbytes = dec.decode(base64EncodedFiles[i]);
InputStream inputStream = new ByteArrayInputStream(decbytes);
list.add(inputStream);
System.out.println("**** PDF FILES SETUP: " + (i+1) + " of " + base64EncodedFiles.length + " ****");
}
//Initialize main PDF here
for (int i = 0; i < list.size(); i++) {
InputStream inStr = list.get(i);
System.out.println("NEXT FILE IS OF TYPE: " + fileTypes[i]);
//Convert the file and add to the main PDF below
if (fileTypes[i].contains("PDF") || fileTypes[i].contains("pdf")) {
//add to main PDF
} else if(fileTypes[i].contains("TIFF") || fileTypes[i].contains("tif") || fileTypes[i].contains("TIF")) {
//add to main PDF
} else if(fileTypes[i].contains("jpg") || fileTypes[i].contains("JPG")) {
//add to main PDF
} else if(fileTypes[i].contains("JPEG") || fileTypes[i].contains("jpeg")) {
//add to main PDF
} else if(fileTypes[i].contains("PNG") || fileTypes[i].contains("png")) {
//add to main PDF
} else if(fileTypes[i].contains("GIF") || fileTypes[i].contains("gif")) {
//add to main PDF
} else if(fileTypes[i].contains("DOC") || fileTypes[i].contains("doc") || fileTypes[i].contains("docx")) {
//add to main PDF
} else if(fileTypes[i].contains("XLSX") || fileTypes[i].contains("xlsx")) {
//add to main PDF
}
}
} catch (Exception e) {
e.printStackTrace();
}
return base64String;
}
}