Page 1 of 1

Wingdings and PDF Conversion

PostPosted: Wed Jun 04, 2014 12:08 am
by MikeH
Hello,

I'm working on a project taking an xml file and merging with a docx template, ultimately creating a PDF file. I've been able to use the ContentControlsMergeXML and ConvertOutPDF sample files to create a basic application to merge and convert. So far, so good.

The templates I'm working with include checkboxes. I was hoping to use conditional content controls to display a checked box/unchecked check box depending on xml values. I can get the conditional to work, however I was using Wingdings (Actually, Wingdings 2) to display the checkbox (whether checked or unchecked.) I can place wingding characters within the docx, however I am unable to convert wingding characters to PDF, ultimately any wingding character being displayed as a #.

I have created a simple docx that I've run through the unmodified ConvertOutPDF sample code that displays the behavior of the wingdings font. And if I upload the docx to the webapp, the webapp also generates a pdf using # for any wingdings

I'm sure I'm missing something simple somewhere, but I can't figure out what it is. Anyone have any ideas what I need to do to get wingdings/wingdings 2 characters to appear in a PDF created from docx4j?

Thanks for any assistance

Mike

Re: Wingdings and PDF Conversion

PostPosted: Thu Jun 05, 2014 12:52 am
by jason
I see the same behaviour.

The following makes it work for your sample docx:

Code: Select all
diff --git a/src/main/java/org/docx4j/fonts/RunFontSelector.java b/src/main/java/org/docx4j/fonts/RunFontSelector.java
index c1d6aeb..e9e3f50 100644
--- a/src/main/java/org/docx4j/fonts/RunFontSelector.java
+++ b/src/main/java/org/docx4j/fonts/RunFontSelector.java

@@ -516,7 +521,7 @@
         * and the ascii (or asciiTheme if defined) and hAnsi (or hAnsiTheme if defined) attributes are equal,
         * then the ascii (or asciiTheme if defined) font is used.
         */
-      if (("Times New Roman").equals(eastAsia)) {
+      if (("Times New Roman").equals(eastAsia)) {      
      
           if (ascii!=null
                 && ascii.equals(hAnsi)) {
@@ -771,7 +776,15 @@
                     vis.fontAction(eastAsia);
                   } else {
                      // Usual case
-                    // TODO .. do what???                                       
+                    // TODO .. do what???
+                     
+                     // Experimental: may be more correct to use hAnsi
+                     if ("Wingdings".equals(ascii)
+                           || "Wingdings 2".equals(ascii)
+                           ) {
+                        vis.fontAction(ascii);
+                     }
+                     
                   }
                   vis.addCharacterToCurrent(c);


but what is actually correct will take more thought/experimentation.

What part of <w:rFonts w:ascii="Wingdings" w:hAnsi="Wingdings" ... is important here?

All your symbols were in the char range (c>='\uE000' && c<='\uF8FF') , but is that always the case for Wingdings/Wingdings2?

The other thing to be careful of (in the ConvertOutPDF sample) is that you don't have a regex which prevents Wingdings2 from being used.

Tracking this at https://github.com/plutext/docx4j/issues/118

If you do explore this further before I do (which won't be for a while), please let us know what you find.

Re: Wingdings and PDF Conversion

PostPosted: Fri Jun 06, 2014 5:01 am
by MikeH
Thanks Jason for the reply.

The two characters I was looking for from wingdings 2 are Decimal 82 - boxcheck (83 or 84 would probably work as well), and decimal 163 - box1

This would allow me to place a 'checked' checkbox and an 'unchecked' checkbox wherever I needed. Currently I'm just using 'X' and 'O', which works in a pinch.

I'll have to figure out later how to return the equivalent of a chr$ through xpath (in order to get decimal 163)

Thanks for the tip about the regex. All I need to do to add in wingdings 2 is to add |WINGDNG2 to the end of the regex, correct? (For a windows system)

I'm just looking for a way to place a checkbox (or it's equivalent) in a docx and check/uncheck it using docx4j.

Currently, I'm using the following xpath to bind with text using OpenDoPE. I can then place a 'checkbox' without worrying about a conditional.

Code: Select all
concat(substring('X', 1 div boolean(/form/formFields/questions/question[@line='Line01']/yesNo[@checked='true'])),substring('O', 1 div not(boolean(/form/formFields/questions/question[@line='Line01']/yesNo[@checked='true']))))


Sample XML:

Code: Select all
<form>
  <formFields>
    <questions>
      <question line="Line24">
        <yesNo checked="true"></yesNo>
      </question>
    </questions>
  </formFields>
</form>


If a box was unchecked, there would be no <yesNo> node.

Once the wingdings gets sorted out, I should be able to replace the 'X' and 'O' with appropriate wingdings characters. At least that's my hope.

If there's a better way to do it, I'm all ears.

Thanks

Re: Wingdings and PDF Conversion

PostPosted: Fri Jul 11, 2014 11:37 am
by jason
Turns out it is hAnsi which matters