When I upgrade to 7.8.0 from 2.9.4 it shows many errors.Seems to be like may changes in the class in the jar files.Could you kindy convert the below code compatibile to 7.8.0.I am using Java 1.6.Hope 7.8.0 will work in Java 1.6.
package com.mmm.singlePDF.PDFConverter;
import java.io.FileOutputStream;
import java.util.List;
import org.apache.log4j.Logger;
import org.w3c.dom.Element;
import org.w3c.dom.Text;
import com.aspose.pdf.kit.EncodingType;
import com.aspose.pdf.kit.FontColor;
import com.aspose.pdf.kit.FontStyle;
import com.aspose.pdf.kit.FormattedText;
import com.aspose.pdf.kit.PdfFileInfo;
import com.aspose.pdf.kit.PdfFileStamp;
import com.aspose.slides.FontsLoader;
import com.aspose.slides.License;
import com.aspose.slides.OleObjectFrame;
import com.aspose.slides.Presentation;
import com.aspose.slides.Shape;
import com.aspose.slides.Slide;
import com.aspose.slides.pptx.OleObjectFrameEx;
import com.aspose.slides.pptx.PresentationEx;
import com.aspose.slides.pptx.ShapeEx;
import com.aspose.slides.pptx.SlideEx;
import com.mmm.singlePDF.PDFFileEditor.PDFFileEditor;
import com.mmm.singlePDF.Util.AppHelper;
import com.mmm.singlePDF.system.ApplicationConstants;
import com.mmm.singlePDF.system.BaseApplicationException;
/**
*PresentationToPDFConverter class converts ppt,pptx and embedded objects to PDF
* @author Anand Sankaran
* @version 1.0
*/
public class PresentationToPDFConverter {
private static Logger logger =
Logger.getLogger(PresentationToPDFConverter.class.getName());
/**
* Constructor for PresentationToPDFConverter
* set the license of ASPOSE(Aspose.Total.Java.lic)
*/
public PresentationToPDFConverter()throws BaseApplicationException{
License license = new License();
try {
license.setLicense(this.getClass().getResourceAsStream(ApplicationConstants.ASPOSE_TOTAL_JAVA_LICENSE));
} catch (Exception e) {
logger.error(ApplicationConstants.ASPOSE_LICENSE_EXCEPTION + e.getMessage());
throw new BaseApplicationException();
}
}
/**
* Converts presentation to PDF
* @param Application server file path
* @param fileNamewithExtn file name with extension
* @param List having converted pdf name
*/
public void convertPresentationToPdf(String destination,String fileNameWithExtn,List convertedFileNames,org.w3c.dom.Document dom, Element parentEle,Element titleEle,ConvertFiles convertFiles,List errorFileNames)throws BaseApplicationException{
String fileName=AppHelper.getFileNameWithoutExtn(destination+fileNameWithExtn);
String fileNameBookmark=AppHelper.getFileNameWithoutExtn(destination+fileNameWithExtn);
fileName=AppHelper.convertToValidFileName(fileName);
try {
logger.info(ApplicationConstants.CONVERTINGFILE+fileNameWithExtn);
String inputFile=destination+fileNameWithExtn;
FontsLoader.loadExternalFonts(new String[] {convertFiles.getOfficeFontPath(),""});
String outputFile=destination+fileName+ApplicationConstants.pdf;
if(AppHelper.getFileExtn(fileNameWithExtn).equalsIgnoreCase(ApplicationConstants.PPTX)){
PresentationEx presentationx = new PresentationEx(inputFile);
presentationx.save(outputFile, com.aspose.slides.export.SaveFormat.PDF);
//@@@
//To add file name as footer-starts
boolean isFooterAdded=PDFFileEditor.addFooter(outputFile,destination,fileName);
//To add file name as footer-ends
int pageNum;
if(convertFiles.getCount()==0){
pageNum=convertFiles.getCount()+1;
}
else {
pageNum=convertFiles.getCount();
}
titleEle.setAttribute("Action", "GoTo");
titleEle.setAttribute("Page", pageNum+" "+"Fit");
Text nameValue = dom.createTextNode(fileNameBookmark+ApplicationConstants.pdf);
titleEle.appendChild(nameValue);
PdfFileInfo pdffileinfo=new PdfFileInfo(outputFile);
convertFiles.setCount(pdffileinfo.getNumberofPages()+pageNum);
//@@@
if(isFooterAdded){
convertedFileNames.add(fileName+ApplicationConstants.FOOTER_ADDED+ApplicationConstants.pdf);
}
else {
convertedFileNames.add(fileName+ApplicationConstants.pdf);
}
//To add line in the last page of the pdf-Starts
PDFFileEditor.addLineAtLastPage(destination+fileName+ApplicationConstants.FOOTER_ADDED+ApplicationConstants.pdf);
//To add line in the last page of the pdf-Ends
//To convert Embedded Objects to PDF
extractEmbeddedPptxObjects(presentationx,fileName,destination,convertedFileNames,dom,titleEle,convertFiles,errorFileNames);
}
else {
Presentation presentation = new Presentation(inputFile);
presentation.save(outputFile,com.aspose.slides.export.SaveFormat.PDF);
//@@@
//To add file name as footer-starts
boolean isFooterAdded=PDFFileEditor.addFooter(outputFile,destination,fileName);
//To add file name as footer-ends
int pageNum;
if(convertFiles.getCount()==0){
pageNum=convertFiles.getCount()+1;
}
else {
pageNum=convertFiles.getCount();
}
titleEle.setAttribute("Action", "GoTo");
titleEle.setAttribute("Page", pageNum+" "+"Fit");
Text nameValue = dom.createTextNode(fileNameBookmark+ApplicationConstants.pdf);
titleEle.appendChild(nameValue);
PdfFileInfo pdffileinfo=new PdfFileInfo(outputFile);
convertFiles.setCount(pdffileinfo.getNumberofPages()+pageNum);
//@@@
if(isFooterAdded){
convertedFileNames.add(fileName+ApplicationConstants.FOOTER_ADDED+ApplicationConstants.pdf);
}
else {
convertedFileNames.add(fileName+ApplicationConstants.pdf);
}
//To add line in the last page of the pdf-Starts
PDFFileEditor.addLineAtLastPage(destination+fileName+ApplicationConstants.FOOTER_ADDED+ApplicationConstants.pdf);
//To add line in the last page of the pdf-Ends
//To convert Embedded Objects to PDF
extractEmbeddedPptObjects(presentation,fileName,destination,convertedFileNames,dom,titleEle,convertFiles,errorFileNames);
}
} catch (Exception e) {
logger.error(ApplicationConstants.PRESENTATION_DOC_CONVERT_EXCEPTION+" "+fileName+" "+e.getMessage());
errorFileNames.add(fileName);
String exception=null;
if(e.getMessage()==null){
exception=ApplicationConstants.EXCEPTION_MESSAGE_1;
}
else {
exception=e.getMessage();
}
errorFileNames.add(ApplicationConstants.EXCEPTION_MESSAGE+exception);
parentEle.removeChild(titleEle);
throw new BaseApplicationException();
}
}
/**
* Extracts Embedded attachment in a pptx
* @param workbook object
* @param fileName file name
* @param destiantion destination server file path
* @param List having converted pdf name
*/
public void extractEmbeddedPptxObjects(PresentationEx presentationx ,String fileName,String destination,List convertedFileNames,org.w3c.dom.Document dom, Element parentTitle,ConvertFiles convertFiles,List errorFileNames)throws BaseApplicationException{
logger.info(ApplicationConstants.EXTRACTINGEMBEDDEDOBJ+fileName);
try {
SlideEx sld = presentationx.getSlides().get(0);
ShapeEx shape=null;
String extension=null;
for(int slideIndex=0;slideIndex<presentationx.getSlides().size();slideIndex++){//i indicates slide number j indicates embedded object shape number
sld = presentationx.getSlides().get(slideIndex);
for(int shapeIndex=0;shapeIndex<sld.getShapes().size();shapeIndex++){
shape=sld.getShapes().get(shapeIndex);
boolean isValidAttachment=true;
if(shape instanceof OleObjectFrameEx) {
//Cast the shape to OleObjectFrameEx
OleObjectFrameEx oleObjFrame = (OleObjectFrameEx)shape;
if(oleObjFrame.getObjectName().equals(ApplicationConstants.EXCEL_OBJECT_NAME) &&oleObjFrame.getObjectProgId().equals( ApplicationConstants.PROG_ID_XLSX)){
extension=ApplicationConstants.xlsx;
}
else if(oleObjFrame.getObjectName().equals(ApplicationConstants.EXCEL_OBJECT_NAME) &&oleObjFrame.getObjectProgId().equals(ApplicationConstants.PROG_ID_XLS)){
extension=ApplicationConstants.xls;
}
else if(oleObjFrame.getObjectName().equals(ApplicationConstants.DOCUMENT_OBJECT_NAME) &&oleObjFrame.getObjectProgId().equals(ApplicationConstants.PROG_ID_DOCX)){
extension=ApplicationConstants.docx;
}
else if(oleObjFrame.getObjectName().equals(ApplicationConstants.DOCUMENT_OBJECT_NAME) &&oleObjFrame.getObjectProgId().equals(ApplicationConstants.PROG_ID_DOC)){
extension=ApplicationConstants.doc;
}
else if(oleObjFrame.getObjectName().equals(ApplicationConstants.PRESENTATION_OBJECT_NAME) &&oleObjFrame.getObjectProgId().equals(ApplicationConstants.PROG_ID_PPTX)){
extension=ApplicationConstants.pptx;
}
else if(oleObjFrame.getObjectName().equals(ApplicationConstants.PRESENTATION_OBJECT_NAME) &&oleObjFrame.getObjectProgId().equals(ApplicationConstants.PROG_ID_PPT)){
extension=ApplicationConstants.ppt;
}
else if(oleObjFrame.getObjectName().equals(ApplicationConstants.PDF_OBJECT_NAME) &&oleObjFrame.getObjectProgId().equals(ApplicationConstants.PROG_ID_PDF)){
extension=ApplicationConstants.pdf;
}
else {
isValidAttachment=false;
}
if (oleObjFrame != null)
{
if(isValidAttachment==true){
//@@@
// Element titleEle_Embed = dom.createElement("Title");
// parentTitle.appendChild(titleEle_Embed);
//@@@
String convertedFileNameWithExtn= ApplicationConstants.ATTACHMENT
+ApplicationConstants.UNDERSCORE+slideIndex
+ApplicationConstants.UNDERSCORE+shapeIndex
+ApplicationConstants.UNDERSCORE
+fileName+extension;
FileOutputStream fos = new FileOutputStream(destination+convertedFileNameWithExtn);
byte[] fileData = oleObjFrame.getObjectData();
fos.write(fileData);
fos.close();
Element titleEle_Embed = dom.createElement("Title");
parentTitle.appendChild(titleEle_Embed);
try{
convertFiles.convertFilesToPdf(destination,convertedFileNameWithExtn, convertedFileNames,dom,parentTitle,titleEle_Embed,convertFiles,errorFileNames);
}
catch(Exception e){
logger.error(ApplicationConstants.EMBEDDED_DOC_INSIDE_PRESENTATION_DOC+" "+fileName+" "+e.getMessage());
}
}
}
}
}
}
}
catch(Exception e){
logger.error(ApplicationConstants.EMBEDDED_DOC_INSIDE_PRESENTATION_DOC+" "+fileName+" "+e.getMessage());
throw new BaseApplicationException();
}
}
/**
* Extracts Embedded attachment in a ppt
* @param workbook object
* @param fileName file name
* @param destiantion destination server file path
* @param List having converted pdf name
*/
public void extractEmbeddedPptObjects(Presentation presentation ,String fileName,String destination,List convertedFileNames,org.w3c.dom.Document dom, Element parentTitle,ConvertFiles convertFiles,List errorFileNames)throws BaseApplicationException{
logger.info(ApplicationConstants.EXTRACTINGEMBEDDEDOBJ+fileName);
try {
Slide sld = presentation.getSlides().get(0);
Shape shape=null;
String fileExtension=null;
for(int slideIndex=0;slideIndex<presentation.getSlides().size();slideIndex++) {
sld = presentation.getSlides().get(slideIndex);
for(int shapeIndex=0;shapeIndex<sld.getShapes().size();shapeIndex++){
shape=sld.getShapes().get(shapeIndex);
boolean isValidAttachment=true;
if(shape instanceof OleObjectFrame) {
//Cast the shape to OleObjectFrameEx
OleObjectFrame oleObjFrame = (OleObjectFrame)shape;
if(oleObjFrame.getObjectName().equals(ApplicationConstants.EXCEL_OBJECT_NAME) &&oleObjFrame.getObjectProgId().equals( ApplicationConstants.PROG_ID_XLSX)){
fileExtension=ApplicationConstants.xlsx;
}
else if(oleObjFrame.getObjectName().equals(ApplicationConstants.EXCEL_OBJECT_NAME) &&oleObjFrame.getObjectProgId().equals(ApplicationConstants.PROG_ID_XLS)){
fileExtension=ApplicationConstants.xls;
}
else if(oleObjFrame.getObjectName().equals(ApplicationConstants.DOCUMENT_OBJECT_NAME) &&oleObjFrame.getObjectProgId().equals(ApplicationConstants.PROG_ID_DOCX)){
fileExtension=ApplicationConstants.docx;
}
else if(oleObjFrame.getObjectName().equals(ApplicationConstants.DOCUMENT_OBJECT_NAME) &&oleObjFrame.getObjectProgId().equals(ApplicationConstants.PROG_ID_DOC)){
fileExtension=ApplicationConstants.doc;
}
else if(oleObjFrame.getObjectName().equals(ApplicationConstants.PRESENTATION_OBJECT_NAME) &&oleObjFrame.getObjectProgId().equals(ApplicationConstants.PROG_ID_PPTX)){
fileExtension=ApplicationConstants.pptx;
}
else if(oleObjFrame.getObjectName().equals(ApplicationConstants.PRESENTATION_OBJECT_NAME) &&oleObjFrame.getObjectProgId().equals(ApplicationConstants.PROG_ID_PPT)){
fileExtension=ApplicationConstants.ppt;
}
else if(oleObjFrame.getObjectName().equals(ApplicationConstants.PDF_OBJECT_NAME) &&oleObjFrame.getObjectProgId().equals(ApplicationConstants.PROG_ID_PDF)){
fileExtension=ApplicationConstants.pdf;
}
else {
isValidAttachment=false;
}
if (oleObjFrame != null)
{
if(isValidAttachment==true){
//@@@
//Element titleEle_Embed = dom.createElement("Title");
//parentTitle.appendChild(titleEle_Embed);
//@@@
String convertedFileNameWithExtn= ApplicationConstants.ATTACHMENT
+ApplicationConstants.UNDERSCORE+slideIndex
+ApplicationConstants.UNDERSCORE+shapeIndex
+ApplicationConstants.UNDERSCORE
+fileName+fileExtension;
FileOutputStream fos = new FileOutputStream(destination+convertedFileNameWithExtn);
byte[] fileData = oleObjFrame.getObjectData();
fos.write(fileData);
fos.close();
Element titleEle_Embed = dom.createElement("Title");
parentTitle.appendChild(titleEle_Embed);
//ConvertFiles convertFiles=new ConvertFiles();
try {
convertFiles.convertFilesToPdf(destination,convertedFileNameWithExtn, convertedFileNames,dom,parentTitle,titleEle_Embed,convertFiles,errorFileNames);
}
catch(Exception e){
logger.error(ApplicationConstants.EMBEDDED_DOC_INSIDE_PRESENTATION_DOC+" "+fileName+" "+e.getMessage());
}
}
}
}
}
}
}
catch(Exception e){
logger.error(ApplicationConstants.EMBEDDED_DOC_INSIDE_PRESENTATION_DOC+" "+fileName+" "+e.getMessage());
throw new BaseApplicationException();
}
}
}