Free Support Forum - aspose.com

Exception trying to split word document into single page documents

Hi,

I tried splitting the word document via pdf route. But it is giving me exception for large documents. Please find my code :

public class WordSplitViaPdf {

public static void main(String... args) throws Exception {

    com.aspose.pdf.License license = new com.aspose.pdf.License();
    com.aspose.words.License wordLicense = new  com.aspose.words.License();
    license.setLicense(new java.io.FileInputStream("/home/sauravarora/Desktop/aspose-licence"));
    wordLicense.setLicense("/home/sauravarora/Desktop/aspose-licence");

    PdfSaveOptions options = new PdfSaveOptions();
    com.aspose.pdf.DocSaveOptions docSaveOptions = new com.aspose.pdf.DocSaveOptions();
    docSaveOptions.setMode(com.aspose.pdf.DocSaveOptions.RecognitionMode.Flow);
    docSaveOptions.setFormat(com.aspose.pdf.DocSaveOptions.DocFormat.DocX);

    Document document = new Document("/home/sauravarora/data/1005/bulkupload/contracttemplate/1404/1523299617685/docWithoutContent.docx");
    String folder = "/home/sauravarora/data/1005/bulkupload/contracttemplate/1404/1523299617685";

    for (int page = 1; page <= document.getPageCount(); page++) {
        options.setPageIndex(page - 1);
        options.setPageCount(1);
        FileOutputStream fileOutputStreamForPdf = new FileOutputStream(folder + "/" + page + ".pdf");
        document.save(fileOutputStreamForPdf, options);
        FileOutputStream fileOutputStreamForWord = new FileOutputStream(folder + "/" + page + ".docx");
        FileInputStream fileInputStreamForPdf = new FileInputStream(folder + "/" + page + ".pdf");
        com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(fileInputStreamForPdf);
        pdfDocument.save(fileOutputStreamForWord, docSaveOptions);
    }
}

}

Also the exception trace :

Exception in thread “main” java.lang.IllegalStateException: Infinite loop detected.
at com.aspose.words.zzYX9.zzAh(Unknown Source)
at com.aspose.words.zzYX9.zzRE(Unknown Source)
at com.aspose.words.zz9E.zzXv(Unknown Source)
at com.aspose.words.zz9F.zz5E(Unknown Source)
at com.aspose.words.zzZN8.zz5E(Unknown Source)
at com.aspose.words.zz1V.zzZWW(Unknown Source)
at com.aspose.words.zz1V.zzZ(Unknown Source)
at com.aspose.words.zz1V.zzZG(Unknown Source)
at com.aspose.words.Document.zzZ(Unknown Source)
at com.aspose.words.Document.zzZ(Unknown Source)
at com.aspose.words.Document.zzZ(Unknown Source)
at com.aspose.words.Document.save(Unknown Source)
at com.aspose.words.examples.cellsexamples.WordSplitViaPdf.main(WordSplitViaPdf.java:30)

I am attaching the document for your reference. Please help.docWithoutContent.docx.zip (12.6 KB)

Hi,

I was able to resolve this by upgrading the jars to latest version. But a problem i want to get the solution is the page size of certain spitted word documents. They are being spitted into 2 page documents. I am attaching the document for your reference . Please help. We are currently live with aspose with a paid licence.38.docx.zip (29.4 KB)
docWithoutContent.docx.zip (12.6 KB)

@saurabh.arora,

Thanks for your inquiry. Please note that Aspose.Words requires TrueType fonts when rendering document to fixed-page formats (JPEG, PNG, PDF or XPS). You need to install fonts that are used in your document on the machine where you’re converting documents to PDF. Please refer to the following article:

How Aspose.Words Uses True Type Fonts

Could you please share the page number of document that is exported into two pages?