aspose-pdf / Aspose.PDF-for-Java

Aspose.PDF for Java examples, plugins and showcases
https://products.aspose.com/pdf/java
MIT License
127 stars 132 forks source link

convert pdf to word uses a lot of ram usage unlike convert excel to pdf #27

Open saeedAliakbary opened 7 years ago

saeedAliakbary commented 7 years ago

Why, when I use aspose-pdf for convert pdf to word, It uses a lot of RAM, and my Tomcat goes down, while I do not have access to increase permsize. why convert pdf to word uses a lot of ram usage unlike convert excel to pdf? my code is :


import com.aspose.cells.FileFormatType;
import com.aspose.cells.Workbook;
import com.aspose.cells.WorksheetCollection;
import com.aspose.pdf.Document;
import com.aspose.pdf.SaveFormat;
import com.bpm.mis.config.Constants;
import com.sun.corba.se.impl.orbutil.closure.Constant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

public class AsposeExporter {
    private final Logger log = LoggerFactory.getLogger(AsposeExporter.class);
    private String homePath = System.getProperty("user.home");
    private String licenseDir = homePath + "/aspose/";
    private final String token;
    private Workbook workbook;

    public AsposeExporter(String token) throws Exception {
        this.token = token;
        checkAsposeLicense();
        workbook = new Workbook(Constants.EXP_DIR + token + ".xlsx");
    }

    private void checkAsposeLicense() {
        try {
            com.aspose.cells.License licenseCell = new com.aspose.cells.License();
            licenseCell.setLicense(licenseDir+"Aspose.Cells.lic");
            com.aspose.pdf.License licensePdf = new com.aspose.pdf.License();
            licensePdf.setLicense(licenseDir+"Aspose.Pdf.lic");
        } catch (Exception e) {
            log.warn("aspose licence is not set!",e);
        }
    }

    public void trimExcelWorkbook(){
        WorksheetCollection indList =workbook.getWorksheets();
        for(int ind=indList.getCount()-1;ind>1;ind--) {
            workbook.getWorksheets().removeAt(ind);
        }
    }

    public void exportPdf() {
        try {
            workbook.save(Constants.EXP_DIR + token + ".pdf", FileFormatType.PDF);
            workbook.dispose();
        } catch (Exception e) {
            log.error("aspose export to pdf error!", e);
        }
    }

    public void exportWord() {
        exportPdf();
        Document document = new Document(Constants.EXP_DIR +token+".pdf");
        document.save(Constants.EXP_DIR + token + ".docx", SaveFormat.DocX);
    }
}
aspose-pdf commented 7 years ago

@saeedbaba , The amount of memory required to perform conversion of PDF to DOC depends upon the structure and complexity of input PDF file. In order for us to further investigate this issue, please share the input PDF file, so that we can further test the scenario in our environment. We are sorry for this inconvenience.

LemjidMohamed commented 5 years ago

Hello, When talking about the pdf file, I got a bad word with the Aspose library: image image

Our client does not accept blocks, he sees a word document like that of the original office. Do you have an idea please?

asadalikhan90 commented 2 years ago

Please try to use Aspose.PDF for Java 22.4 for PDF to Word Conversion as we have improved this feature lately. Furthermore, please create a post in our official support forum in case you notice any issues. We will further proceed to assist you accordingly.