Page 1 of 1

TOC updation

PostPosted: Thu Mar 22, 2018 8:40 pm
by thiruveni
Hi Jason,

Thanks for all of your responses to my queries. Here is another one.

My objective is to replace certain strings in a docx file with some values.

So, I have used docx4j to read the docx file and then convert it into xml ,replace the string . A few sections were also added as part of this change.
so the TOC had to be updated accordingly.

when I tried updating the TOC, I got this error

org.docx4j.toc.TocException: Error in toc web service at http://converter-eval.plutext.com:80/v1 ... 00/convert
HTTP response: 301 Moved Permanently

Can you please let me know the mistake I am making.


Thanks in advance :-)

Re: TOC updation

PostPosted: Fri Mar 23, 2018 10:52 am
by jason
You should now test against https://converter-eval.plutext.com:443/ ... 00/convert

(and ultimately install your own instance!)

You can do that in your docx4j.properties: https://github.com/plutext/docx4j/commi ... 82bb052e4e

Re: TOC updation

PostPosted: Fri Mar 23, 2018 5:07 pm
by thiruveni
Hi Jason,

Thanks for your reply,

Should we override the doc4j.properties to modify the url(I am using the docx4j.jar)or how are we supposed to do ?

can you please elaborate ?

Re: TOC updation

PostPosted: Mon Mar 26, 2018 5:17 pm
by jason
You can add a docx4j.properties file to your classpath.

Or you can now use https://www.docx4java.org/docx4j/docx4j-3.3.7.jar (not yet in Maven Central). which defaults to the correct setting.

Re: TOC updation

PostPosted: Mon Mar 26, 2018 6:03 pm
by thiruveni
I get this error :-(


This behaviour may be Windows client OS specific; please look in the server logs or try a Linux client
org.docx4j.toc.TocException: Error in toc web service at http://converter-eval.plutext.com:443/v ... 00/convert
Connection reset

Re: TOC updation

PostPosted: Tue Mar 27, 2018 9:55 am
by jason
That's a SocketException, most likely due to a problem with the document.

Can you attach the document, or email it to me?

Otherwise, feel free to download/install the converter locally, and if this error still occurs, look in the server log to see what the problem is.

For log file location, please see https://converter-eval.plutext.com/troubleshooting.html

Re: TOC updation

PostPosted: Tue Mar 27, 2018 3:37 pm
by thiruveni
test.docx
(26.67 KiB) Downloaded 273 times
Attaching the document,

Re: TOC updation

PostPosted: Tue Mar 27, 2018 4:09 pm
by jason
Works for me using the code at https://github.com/plutext/docx4j/blob/ ... eDemo.java

DEBUG output:

Code: Select all
DEBUG org.docx4j.toc.TocGenerator .getPageNumbersMapViaService line 669 - getPageNumbersMapViaService() starting..
INFO org.docx4j.jaxb.NamespacePrefixMapperUtils .getPrefixMapperRelationshipsPart line 136 - Using NamespacePrefixMapperRelationshipsPartSunInternal, which is suitable for Java 6
DEBUG org.docx4j.services.client.ConverterHttp .<init> line 60 - starting, with endpointURL: https://converter-eval.plutext.com:443/v1/00000000-0000-0000-0000-000000000000/convert
DEBUG org.docx4j.toc.TocGenerator .getPageNumbersMapViaService line 703 - page numbers successfully received from service
DEBUG org.docx4j.toc.TocGenerator .getPageNumbersMapViaService line 775 - page number map size 10


But this is your input template right? I guess the problem is being introduced when you:

convert it into xml ,replace the string . A few sections were also added as part of this change.

Re: TOC updation

PostPosted: Tue Mar 27, 2018 6:50 pm
by thiruveni
I am pasting the xml section which was added as part of the variable replace. Can you please take a look if I am missing something.

Re: TOC updation

PostPosted: Wed Mar 28, 2018 1:47 pm
by jason
Adding XML via variable replace isn't really supported!

Please save the docx as it exists immediately before you do the ToC update, and let's take a look at that.

Re: TOC updation

PostPosted: Wed Mar 28, 2018 7:27 pm
by thiruveni
Hi Jason,

I am not adding xml, rather replacing few variables in the docx file with values.
The way I am doing is,

1) Read the docx file. Save it as xml using the docx4j.
2) convert this xml as string . Replace the variables using apache velocity.
3) Save the string as xml and then again to docx file.
4)Now update the TOC.

Note : The xml file I have uploaded is part of section where variable replace was performed.

Re: TOC updation

PostPosted: Wed Mar 28, 2018 8:11 pm
by jason
Somewhere along the way you are breaking the document. Need to look at the output of your step 3.

Re: TOC updation

PostPosted: Thu Mar 29, 2018 3:43 pm
by thiruveni
Hi Jason,

I tried doing this ignoring the updation of page numbers,

TocGenerator tocGenerator = new TocGenerator(wordMLPackage);
tocGenerator.updateToc(wordMLPackage, true,true);


This works perfectly.

The issue occurs only while considering the page numbers while updation !!

Re: TOC updation

PostPosted: Fri Mar 30, 2018 7:24 am
by jason
Interesting, but still: how do you expect us to look into it without a reproducible test case (ie the document causing the problem)?

If its sensitive, you could anonymise it first https://github.com/plutext/docx4j/blob/ ... ingle.java

If that result still causes the issue, then great.

Re: TOC updation

PostPosted: Fri Mar 30, 2018 4:06 pm
by thiruveni
outputfile.docx
(46.78 KiB) Downloaded 265 times
Attaching the document,

Re: TOC updation

PostPosted: Thu Apr 05, 2018 7:11 pm
by jason
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
        TocGenerator tocGenerator = new TocGenerator(wordMLPackage);
        tocGenerator.updateToc( false); // true --> skip page numbering
 
Parsed in 0.014 seconds, using GeSHi 1.0.8.4


works for me with that document.

The deprecated:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
        tocGenerator.updateToc(wordMLPackage, false, true);
 
Parsed in 0.013 seconds, using GeSHi 1.0.8.4


seems ok as well.