We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Not able to split a Document into pages using Aspose words 17.6

Hi,

We have upgraded Aspose words 14 to Aspose Words .17.6 Java.
And we are not able to split a word document into pages using aspose words 17.
We are getting an error., at DocumentPageSplitter(LayoutCollector)

Please find the below error for your reference.,

java.lang.NoClassDefFoundError: com/aspose/words/CustomXmlMarkup
at asposepagesplit.PageNumberFinder.SplitNodesAcrossPages(PageNumberFinder.java:89)
at asposepagesplit.DocumentPageSplitter.(DocumentPageSplitter.java:22)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.mozilla.javascript.MemberBox.newInstance(MemberBox.java:159)
at org.mozilla.javascript.NativeJavaClass.constructInternal(NativeJavaClass.java:266)
at org.mozilla.javascript.NativeJavaClass.constructSpecific(NativeJavaClass.java:205)
at org.mozilla.javascript.NativeJavaClass.construct(NativeJavaClass.java:166)
at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1525)
at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:815)
at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:109)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:393)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3280)
at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:120)
at com.mirth.connect.server.util.javascript.JavaScriptTask.executeScript(JavaScriptTask.java:142)
at com.mirth.connect.server.transformers.JavaScriptFilterTransformer$FilterTransformerTask.doCall(JavaScriptFilterTransformer.java:143)
at com.mirth.connect.server.transformers.JavaScriptFilterTransformer$FilterTransformerTask.doCall(JavaScriptFilterTransformer.java:119)
at com.mirth.connect.server.util.javascript.JavaScriptTask.call(JavaScriptTask.java:113)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.aspose.words.CustomXmlMarkup
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
… 24 more

Looks like no class called customXmlMarkup has been defined in aspose v.17.Was this been renamed or any other method has been implemented for the same functionality?

Can you help in clearing this error.
Thanks in advance.

@mjagatha,

Thanks for your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word does. We used to keep CustomXmlMarkup nodes marked as Obsolete, but now it is fully removed as per:
Custom XML markup is removed when you open a document in Word 2013

Starting from Microsoft Word 2013, Microsoft removed the Custom XML feature from Microsoft Word. Please check following public API changes page for your kind reference.
Public API Changes in Aspose.Words 15.8.0

Please let us know if you have any more queries.

Thanks for your prompt response, Manzoor.
Then how do we split a document into pages using Aspose words Version 17.6?
Do we have any alternative for this?
Can we have a working code snippet for the same?

Thanks in advance.

@mjagatha,

Thanks for your inquiry. Please ZIP and attach your input Word document here for testing. We will investigate the issue on our side and provide you more information.

Aspose.zip (23.7 KB)

Hi Manzoor,

I have attached the working code ., which is working in aspose words 14 version.

A test document and Aspose page splitter jar (where we are trying to split the document into pages) and the code template which we are tying to convert from RTF to ASCII. have been attached.

The same code is not working in aspose words 17.

Please review and let us know the solution.
Kindly, let me know if you need any more documents to be uploaded.

Thanks in advance.

@mjagatha,

Thanks for sharing the detail. We have tested the scenario using latest version of Aspose.Words for Java 17.8 with following code example and have not found the shared issue. Please use Aspose.Words for Java 17.8.

Document doc = new Document(MyDir + "Sample TEST document for testing.rtf");
LayoutCollector layoutCollector = new LayoutCollector(doc);
doc.updatePageLayout();

DocumentPageSplitter splitter = new  DocumentPageSplitter(layoutCollector);
int pageCount = doc.getPageCount();

for (int i = 1; i <= pageCount; i++) {
    ByteArrayOutputStream dstStream = new  java.io.ByteArrayOutputStream();
    Document pageDoc = splitter.GetDocumentOfPage(i);
    pageDoc.save(dstStream, SaveFormat.TEXT);
}

Hi Manzoor,

Thanks for your prompt reply.
We tried using the latest version of Aspose.Words for Java 17.8., but still it is showing the same exception.
How did it work at your end?Any other changes or jars which have customXmlMarkUp class definition to be added?
Please advice.

//code snippet I have used below.,


import java.io.ByteArrayOutputStream;

import asposepagesplit.DocumentPageSplitter;

import com.aspose.words.Document;
import com.aspose.words.LayoutCollector;
import com.aspose.words.SaveFormat;

public class AsposeDocumentPageSplitTest {

public static void main (String[] args) throws Exception{
	String fileName = "C:\\Users\\User\\Downloads\\Test.rtf";
	Document doc = new Document(fileName);
	LayoutCollector layoutCollector = new LayoutCollector(doc);
	doc.updatePageLayout();

	DocumentPageSplitter splitter = new  DocumentPageSplitter(layoutCollector);
	int pageCount = doc.getPageCount();

	for (int i = 1; i <= pageCount; i++) {
	    ByteArrayOutputStream dstStream = new  java.io.ByteArrayOutputStream();
	    Document pageDoc;
		try {
			pageDoc = splitter.getDocumentOfPageRange(1, i);
			pageDoc.save(dstStream, SaveFormat.TEXT);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	   
	}

}
}


Please find the exception as below., for your reference.,

Exception in thread “main” java.lang.NoClassDefFoundError: com/aspose/words/CustomXmlMarkup
at asposepagesplit.PageNumberFinder.SplitNodesAcrossPages(PageNumberFinder.java:89)
at asposepagesplit.DocumentPageSplitter.(DocumentPageSplitter.java:22)
at AsposeDocumentPageSplitTest.main(AsposeDocumentPageSplitTest.java:18)
Caused by: java.lang.ClassNotFoundException: com.aspose.words.CustomXmlMarkup
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
… 3 more

Sorry., the below is the code which we are trying to use(I mean the one which you have shared)., but still it is not working at our end.

import java.io.ByteArrayOutputStream;

import asposepagesplit.DocumentPageSplitter;

import com.aspose.words.Document;
import com.aspose.words.LayoutCollector;
import com.aspose.words.SaveFormat;

public class AsposeDocumentPageSplitTest {

public static void main (String[] args) throws Exception{
	String fileName = "C:\\Users\\User\\Downloads\\409001_Default_753417074_98_170814174555850.rtf";
	Document doc = new Document(fileName);
	LayoutCollector layoutCollector = new LayoutCollector(doc);
	doc.updatePageLayout();

	DocumentPageSplitter splitter = new  DocumentPageSplitter(layoutCollector);
	int pageCount = doc.getPageCount();

	for (int i = 1; i <= pageCount; i++) {
	    ByteArrayOutputStream dstStream = new  java.io.ByteArrayOutputStream();
	    Document pageDoc;
		try {
			pageDoc = splitter.getDocumentOfPage(i);
			pageDoc.save(dstStream, SaveFormat.TEXT);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	   
	}

}
}

@mjagatha,

Thanks for your inquiry. Please remove visitCustomXmlMarkupEnd method from your code. We suggest you please use updated code of “DocumentPageSplitter” in Aspose.Words for Java examples repository at GitHub.

    public int visitCustomXmlMarkupEnd(CustomXmlMarkup customXmlMarkup) throws Exception {
        if (IsCompositeAcrossPage(customXmlMarkup))
            SplitComposite(customXmlMarkup);

        return VisitorAction.CONTINUE;
    }

Hi Manzoor,
Thank you so much …! for your prompt reply.
We are able to split document into pages now.
But while trying to get the document content., we are not able to get the page numbers properly.
Attaching the actual rtf document and document content after reading the each of the page for your reference and the jar file as zip the code which we are using.
I am also Split files.zip (27.0 KB)
attaching the split files where in page numbers are not properly coming for you r reference.
If you can see the document content in the file attached in the zip ., the page numbers are not properly showing up for each page content.
Can you please help me out in clearing this issue.?
Thanks in advance.

AsposeSplit.zip (27.3 KB)

@mjagatha,

Thanks for your inquiry. We have tested the scenario using latest version of Aspose.Words for Java 17.8 and have not found the shared issue. Please use Aspose.Words for Java 17.8. We have attached the output documents this post for your kind reference. Docs.zip (30.1 KB)

Please note that in evaluation mode there are some limitations applied. E.g. Aspose.Words injects an evaluation watermark at the top of the document. The document’s contents are truncated after a certain number of paragraphs during import or export.

Please request for 30-days temporary license from here:
Get temporary license