Page 1 of 1

ColdFusion load up the classes needed for Wordprocessing?

PostPosted: Tue May 29, 2012 4:39 am
by ColdBreeze
I'm trying to use the JAR and it is a big complicated piece (I'm not really a Java guy, I'm calling it from ColdFusion).

Where in the JAR are the classes I need to create objects out of to manipulate docx documents? What I'm doing is dropping the JAR on the server, loading it up, but I am going to have to transverse inside the JAR to get the necessary classes to create an object out of.

Re: How do I load up the classes needed for Wordprocessing?

PostPosted: Tue May 29, 2012 9:37 am
by jason
In the jar in org/docx4j.

Have a look at the import statements in the source code for the sample closest to what you want to do, to see which classes are used. Probably best to get things working in Java first, before you try calling from Cold Fusion. Remember you'll need the relevant dependency jars (inc log4j).

Re: How do I load up the classes needed for Wordprocessing?

PostPosted: Wed May 30, 2012 11:18 pm
by ColdBreeze
I'm trying to create an object out of:
Code: Select all
<cfset docObj = createObject("java","org.docx4j.openpackaging.packages.WordprocessingMLPackage") />


Since this is what I saw in one of the examples. I guess I should try to create an object out of a package? And that I should first create an object of of log4j?

Re: How do I load up the classes needed for Wordprocessing?

PostPosted: Wed May 30, 2012 11:20 pm
by ColdBreeze
I mean shouldn't*. I am just trying to do a simple find/replace placeholders in a docx.

Re: How do I load up the classes needed for Wordprocessing?

PostPosted: Thu May 31, 2012 8:43 am
by jason
Are you talking about this https://github.com/plutext/docx4j/blob/ ... place.java

WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));

is using a static method. I don't know anything about ColdFusion, so this topic would seem to be a good candidate for StackOverflow. Use docx4j, java, ColdFusion tags, and post a link to the source code.

Re: How do I load up the classes needed for Wordprocessing?

PostPosted: Sat Jun 02, 2012 11:29 am
by ColdBreeze
Thank you sir. I got everything up and running on ColdFusion. Seems like everything works just fine. I'll probably write out a tutorial/blog post for those wanting to use docx4j with ColdFusion.

I have one more question... I noticed that with the example dealing with replacing placeholders, that it does not work if you open up and play with a docx a couple of times, since Word loves to toss in random w:t elements everywhere which can cause the placeholder not to work. Can you point me to examples that have something that can overcome that?

Re: How do I load up the classes needed for Wordprocessing?

PostPosted: Mon Jun 04, 2012 7:44 pm
by jason
Great to hear you got it working; I'm sure a blog post would be most useful to / appreciated by anyone following in your footsteps :-)

In answer to your question https://github.com/plutext/docx4j/blob/ ... ilter.java may be a start, but you still need to join up adjacent w:r/w:t .. it may be enough for your purposes to do this if they have no run properties (w:rPr), but a more complete solution would join them up if they have the same run properties.

I haven't written anything like this, because I prefer the content control custom xml binding approach, where this problem does not arise :-)

XSLT (used by Filter) probably isn't a good way to join up adjacent w:r/w:t .. you're better off doing this with a method in Java, pretty easy List manipulation (for a Java programmer anyway!).

Re: ColdFusion load up the classes needed for Wordprocessing

PostPosted: Tue Jun 05, 2012 5:52 am
by Leigh
I prefer the content control custom xml binding approach
...
XSLT (used by Filter) probably isn't a good way to join up adjacent w:r/w:t .. you're better off doing this with a method in Java, pretty easy List manipulation (for a Java programmer anyway!).


Sorry to be dense, but is there an example of that so we can see how it differs from the other approach? Because if it is just List manipulation, that will probably end up being pretty simple in ColdFusion as well. (It runs atop java, so many of its functions are very closely aligned to java's).

Re: ColdFusion load up the classes needed for Wordprocessing

PostPosted: Tue Jun 05, 2012 1:44 pm
by jason
Just to be clear, content control custom xml binding approach is an alternative to VariableReplace.java.

The examples are "ContentControl*" in https://github.com/plutext/docx4j/tree/ ... 4j/samples

Start with ContentControlsMergeXML: https://github.com/plutext/docx4j/blob/ ... geXML.java

Re: ColdFusion load up the classes needed for Wordprocessing

PostPosted: Tue Jun 05, 2012 1:49 pm
by Leigh
Cool, thanks Jason.

Re: ColdFusion load up the classes needed for Wordprocessing

PostPosted: Fri Jun 15, 2012 7:37 am
by ColdBreeze
Is it possible to get VariableReplace.java replaced with the content control custom xml binding approach of finding/replacing variables? I'm scratching my head trying to figure this out.

Re: ColdFusion load up the classes needed for Wordprocessing

PostPosted: Fri Jun 15, 2012 8:56 am
by jason
Not sure I understand the question. Do you mean convert a docx containing VariableReplace variables to one containing content controls bound to XML?

Re: ColdFusion load up the classes needed for Wordprocessing

PostPosted: Sat Jun 16, 2012 12:37 am
by ColdBreeze
Well you said here:

jason wrote:Just to be clear, content control custom xml binding approach is an alternative to VariableReplace.java.


So I am thinking this is a better way of replacing variables inside of a word doc since in the original VariableReplace.java example it will not find/replace variables spreadout across multple elements, such as properties, of a docx document.

I was wondering if we could get a Java sample on how to use the "content control custom xml binding approach" replacement/alternative to the original VariableReplace.java example since it seems like it would be far superior.

Re: ColdFusion load up the classes needed for Wordprocessing

PostPosted: Sun Jun 17, 2012 6:05 pm
by jason
ContentControlsMergeXML mentioned above, or were you looking for something else?

Re: ColdFusion load up the classes needed for Wordprocessing

PostPosted: Wed Jun 27, 2012 10:59 pm
by jason
Clean up for VariableReplace: see https://github.com/plutext/docx4j/blob/ ... epare.java for one approach.

Re: ColdFusion load up the classes needed for Wordprocessing

PostPosted: Wed Jul 04, 2012 6:45 am
by ColdBreeze
Ah, thank you.

Will the new VariableReplace be able to search and replace through something liek this?

Code: Select all
<w:r><w:t>${</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>exampleVariable</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>}</w:t></w:r>


This would not work on the original VariableReplace when trying to find/replace the placeholder ${exampleVariable} since Word tosses in all the extra markup.

Re: ColdFusion load up the classes needed for Wordprocessing

PostPosted: Wed Jul 04, 2012 9:29 am
by jason
VariableReplace is unchanged, but the new VariablePrepare is intended to convert that to <w:r><w:t>${exampleVariable}</w:t></w:r>.

You could run VariablePrepare to clean up your docx "template" whenever a user has edited it. Or turn off spelling and grammar checking in Word.