insertDocument method in Coldfusion

Hello,

I’m having trouble inserting one document into another. Here is my code in ColdFusion:

<cfset mainDoc = CreateObject("java", "com.aspose.words.Document").init("D:\InetPub\wwwroot\Intranet\twg\marketing\temp\qualifications_base.doc")>
<cfset subDoc = CreateObject("java","com.aspose.words.Document").init("D:\InetPub\wwwroot\Intranet\twg\marketing\temp\InsertDocument2.doc")>

<cfset attempt1 = mainDoc.getRange().getBookmarks().get("project_title")>

<cfset insertDocument(attempt1.getBookmarkStart().getParentNode(), subDoc)>

<cfset mainDoc.save("D:\InetPub\wwwroot\Intranet\twg\marketing\temp\outt.doc")>

Everything works up to the <cfset insertDocument … line.

Thanks for your help,
Mike

Hi

Thanks for your request. Please make sure that you properly implemented insertDocument method, as described here:
https://docs.aspose.com/words/java/insert-and-append-documents/
Best regards.

Hi Michael,
Most likely the node you are trying to insert the document into is not a paragraph or table node. Please verify that your code is returning this type of node when passing it to the insertDocument method.
If this does not help, could you please post the full stacktrace for the exception you are getting.
Thanks,

Hi Adam,

I looked in the template document and the bookmark we are referencing has a paragraph mark on it if I enable annotations. I also added some text in just for testing. Is there something else I need to check?

Here is my entire stack trace - thanks:

The web site you are accessing has experienced an unexpected error.
Please contact the website administrator.

The following information is meant for the website developer for debugging purposes.
Error Occurred While Processing Request

The insertDocument method was not found.

Either there are no methods with the specified method name and argument types, or the insertDocument method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that matched the provided arguments. If this is a Java object and you verified that the method exists, you may need to use the javacast function to reduce ambiguity.
The error occurred in D:\InetPub\wwwroot\Intranet\twg\marketing\prac2.cfm: line 16
14 : <cfset attempt1 = mainDoc.getRange().getBookmarks().get(“project_title”)>
15 :
16 : <cfset mainDoc.insertDocument(attempt1.getBookmarkStart().getParentNode(), subDoc)>
17 :
18 : <cfset mainDoc.save(“D:\InetPub\wwwroot\Intranet\twg\marketing\temp\outt.doc”)>

Resources:

- Check the ColdFusion documentation to verify that you are using the correct syntax.

- Search the Knowledge Base to find a solution to your problem.

Browser Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.99 Safari/533.4
Remote Address 76.121.5.59
Referrer
Date/Time 12-Jul-10 02:45 PM

Stack Trace
at cfprac22ecfm1940075178.runPage(D:\InetPub\wwwroot\Intranet\twg\marketing\prac2.cfm:16)

coldfusion.runtime.java.MethodSelectionException: The insertDocument method was not found.
at coldfusion.runtime.java.ObjectHandler.findMethodUsingCFMLRules(ObjectHandler.java:322)
at coldfusion.runtime.StructBean.invoke(StructBean.java:527)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2300)
at cfprac22ecfm1940075178.runPage(D:\InetPub\wwwroot\Intranet\twg\marketing\prac2.cfm:16)
at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:196)
at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:370)
at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65)
at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:273)
at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
at coldfusion.filter.PathFilter.invoke(PathFilter.java:86)
at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:70)
at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46)
at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
at coldfusion.CfmServlet.service(CfmServlet.java:175)
at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
at jrun.servlet.FilterChain.doFilter(FilterChain.java:86)
at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)
at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
at jrun.servlet.FilterChain.doFilter(FilterChain.java:94)
at jrun.servlet.FilterChain.service(FilterChain.java:101)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:286)
at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543)
at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:203)
at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:320)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428)
at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:266)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)

Hi

Thanks for your request. insetDocument is not built-in method. You should implement it as described here:
https://docs.aspose.com/words/java/insert-and-append-documents/
Best regards.

Hi Alexey,

I’m not very well versed at Java - I’ve tried compiling the insertDocument method into a class, but with no luck. Is there any resource you can point me at to integrate this into my ColdFusion code?

Thanks,
Mike

Hi

Thanks for your request. Please see the attached document. There are few code example, which might be useful for you. Especially take a look at “Execute With Regions” code example, this example describes what you need to do to use Java class in ColdFusion.
Best regards.

Hi Alexey,

I’ve attempted to copy and paste the mail merge example into a new Java Class using JCreator. When I go to build I get 6 errors with the following output:

--------------------Configuration: --------------------
C:\Users\User\Documents\insertDoc.java:10: class RelationSet is public, should be declared in a file named RelationSet.java
public class RelationSet
^
C:\Users\User\Documents\insertDoc.java:12: cannot find symbol
symbol : class ResultSet
location: class RelationSet
public static ResultSet execQuery()
^
C:\Users\User\Documents\insertDoc.java:33: cannot find symbol
symbol : class Statement
location: class RelationSet
private static Statement createStatement() throws Exception
^
C:\Users\User\Documents\insertDoc.java:19: cannot find symbol
symbol : class Statement
location: class RelationSet
Statement stmt = createStatement();
^
C:\Users\User\Documents\insertDoc.java:40: cannot find symbol
symbol : class Connection
location: class RelationSet
Connection connection = DriverManager.getConnection(connectionString);
^
C:\Users\User\Documents\insertDoc.java:40: cannot find symbol
symbol : variable DriverManager
location: class RelationSet
Connection connection = DriverManager.getConnection(connectionString);
^
6 errors

Process completed.

Is there an easier way you can recommend to compile this to a .jar?

Thanks,
Mike

Hi

Thanks for your request. I attached this java class. I use IntellyJ IDEA IDE to compile it and create JAR. You can use any other IDE to achieve this.
Best regards.

Hi Alexey,

ok - we were able to get your example to compile to a jar. When we try to compile the method for inserting documents we are getting 12 errors. Can you assist with the class we need to compile to get the insert document going?

Thanks,
Mike

Hi

Thanks for your inquiry. Please try using the attached class.
Best regards,

Hi Alexey,

We receive 15 errors when trying to compile? Can you send it over as a .jar?

Thanks,
Mike

Hi Mike,

Thanks for your request. I think, you just forgot to add reference to Aspose.Words JAR and that is why you cannot compile the class.
Best regards,

Hi Alexey,

Thanks for your help in all this - Using a new download of Aspose Words I was able to open the demo files in IntelliJ. I placed in the ‘helper’ class and was able to get it to output the .class file. If you can assist on these last 2 questions, I think I’ll be able to get it working:

  1. How do I get IntelliJ to export the .class to a Jar?
  2. Is it ok that I compile on my local, then upload the jar to the server (different aspose files?).

Thanks,
Mike

Alexey -

Disregard my last message - I finally got it working. Thanks so much for all your help!

Mike

Hi

It is perfect that you finally got it working. Please feel free to ask if you have any questions, I will be glad to help you.
Best regards,