Page 1 of 1

Problem with version v3.3.0

PostPosted: Tue Jul 05, 2016 4:09 am
by borja
Hello

I have a problem with New version of docx4j that never happend to me before. I used some merge fields to edit a word file. Works great. File is opened correctly and all fields have the correct text.
But now, when I click on file - > print to print the document all fields are deleted and only appear the tag of the merge field.
It's very strange because if I export to pdf instead, everything works fine.

Re: Problem with version v3.3.0

PostPosted: Tue Jul 05, 2016 8:42 am
by jason
Word's "Print Field Codes Instead of Their Values" check box?

See http://wordribbon.tips.net/T006701_Prin ... Codes.html

Re: Problem with version v3.3.0

PostPosted: Tue Jul 05, 2016 5:35 pm
by borja
jason wrote:Word's "Print Field Codes Instead of Their Values" check box?

See http://wordribbon.tips.net/T006701_Prin ... Codes.html


Sorry but is not the same problem. I tried to select and unselect checkbox and is printing the code in different formats but never the value. I also think is something related to word configuration, because is exporting well to PDF, but i can't find the problem.

Thanks.

Re: Problem with version v3.3.0

PostPosted: Tue Jul 05, 2016 6:00 pm
by borja
More info about the problem.

In office 2016, PDF exporting is also not working. When i click on file -> print, all merge fields are reset. it does not matter if i really print or not. If i open the dialog and return to main view i only see the merge field codes. I have to click on Undo to see their values again.
I think when click on print button, word is updating merge fields, i tried to unselect the "update fields when printing" option but i get the same. I used docx4j 3.2.2 many times and i dont remember this happened me.

Thanks.

Re: Problem with version v3.3.0

PostPosted: Tue Jul 05, 2016 8:23 pm
by jason
Feel free to upload or send me the docx, and I'll take a look.

Did you play with the various F9 toggles?

Quoting http://www.techrepublic.com/blog/10-thi ... rd-fields/

To toggle between the field code and its resulting value, select the entire field and press Shift + F9.

To toggle all the fields in your document, press Alt + F9. So if you open a document and see field codes instead of results, simply press Alt + F9 to toggle them all.

Re: Problem with version v3.3.0

PostPosted: Wed Jul 06, 2016 11:46 pm
by borja
jason wrote:Feel free to upload or send me the docx, and I'll take a look.

Did you play with the various F9 toggles?

Quoting http://www.techrepublic.com/blog/10-thi ... rd-fields/

To toggle between the field code and its resulting value, select the entire field and press Shift + F9.

To toggle all the fields in your document, press Alt + F9. So if you open a document and see field codes instead of results, simply press Alt + F9 to toggle them all.


Hi,

I sent you the file by email. I post this because maybe you dont receive the file.

Thanks

Re: Problem with version v3.3.0

PostPosted: Thu Jul 07, 2016 4:39 pm
by jason
I've looked at your document.

The behaviour is as described by Cindy:

When you switch views, or a document is updated, fields in the document header/footer will be updated automatically; this is not the case for all fields in the document body. Since the text you assigned to the merge fields was not coming from a linked data source, when the fields in the header/footer updated at printing, they reset. The fields in the document body did not update, so the text was retained.


See https://social.msdn.microsoft.com/Forum ... um=oxmlsdk

A workaround is to remove the MERGEFIELDs in the header and footer.

docx4j's MailMerger contains:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
        protected static OutputField fieldFate = OutputField.REMOVED;
    /**
     * What to do with the MERGEFIELD in the output docx.
     *
     * Default is REMOVED.
     *
     * KEEP_MERGEFIELD will allow you to perform
         * another merge on the output document.
         *
         * The AS_FORMTEXT options convert the MERGEFIELD to a FORMTEXT field.
         * This is convenient if you want users to
         * be able to edit the field, where editing is restricted
         * to forms.
         *
     * @param fieldFate
     */

    public static void setMERGEFIELDInOutput(OutputField fieldFate) {
        MailMerger.fieldFate = fieldFate;
    }

       
          public enum OutputField {

                    DEFAULT,
                    REMOVED,
                    KEEP_MERGEFIELD,
                    AS_FORMTEXT_REGULAR;
//                  AS_FORMTEXT_TYPED,
//                  AS_FORMTEXT_TYPED_FORMATTED;
          }    
 
Parsed in 0.015 seconds, using GeSHi 1.0.8.4


So you want setMERGEFIELDInOutput(OutputField.REMOVED), which is the default. Are you setting it to something different?

Re: Problem with version v3.3.0

PostPosted: Thu Jul 07, 2016 5:32 pm
by borja
jason wrote:I've looked at your document.

The behaviour is as described by Cindy:

When you switch views, or a document is updated, fields in the document header/footer will be updated automatically; this is not the case for all fields in the document body. Since the text you assigned to the merge fields was not coming from a linked data source, when the fields in the header/footer updated at printing, they reset. The fields in the document body did not update, so the text was retained.


See https://social.msdn.microsoft.com/Forum ... um=oxmlsdk

A workaround is to remove the MERGEFIELDs in the header and footer.

docx4j's MailMerger contains:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
        protected static OutputField fieldFate = OutputField.REMOVED;
    /**
     * What to do with the MERGEFIELD in the output docx.
     *
     * Default is REMOVED.
     *
     * KEEP_MERGEFIELD will allow you to perform
         * another merge on the output document.
         *
         * The AS_FORMTEXT options convert the MERGEFIELD to a FORMTEXT field.
         * This is convenient if you want users to
         * be able to edit the field, where editing is restricted
         * to forms.
         *
     * @param fieldFate
     */

    public static void setMERGEFIELDInOutput(OutputField fieldFate) {
        MailMerger.fieldFate = fieldFate;
    }

       
          public enum OutputField {

                    DEFAULT,
                    REMOVED,
                    KEEP_MERGEFIELD,
                    AS_FORMTEXT_REGULAR;
//                  AS_FORMTEXT_TYPED,
//                  AS_FORMTEXT_TYPED_FORMATTED;
          }    
 
Parsed in 0.014 seconds, using GeSHi 1.0.8.4


So you want setMERGEFIELDInOutput(OutputField.REMOVED), which is the default. Are you setting it to something different?


Thank you very much,

Yes, i had OutField.KEEP_MERGEFIELD, not sure about why, maybe i copied it from some example. I did a fast test and is working. I really appreciate your help.
Thanks