Page 1 of 1

docx to PDF conversion, loses Excel embedded chart

PostPosted: Sat Aug 04, 2012 8:49 am
by dcelery
Hi, i will try speak english to explane. I am new to docx4j.

Word:
Have a docx with some protected elements. Then the users can only edit field values.
Have same fields into a header table(text, date and combobox), and a picture too.
Next i have another field Richtext type. Into this field, have text, tables, and a embedded chart from Microsoft Excel.

When i run the conversion, the result PDF loses de chart and the picture.
What should be the problem?


Code:
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
wordMLPackage.setFontMapper(new IdentityPlusMapper());
org.docx4j.convert.out.pdf.PdfConversion c = new org.docx4j.convert.out.pdf.viaXSLFO.Conversion(wordMLPackage);
OutputStream os = new java.io.FileOutputStream(inputfilepath + ".pdf");
PdfSettings pdfSet = new PdfSettings();
c.output(os,pdfSet);


Thanks for your help, i really need this...

Re: docx to PDF conversion, loses Excel embedded chart

PostPosted: Sat Aug 04, 2012 9:31 am
by jason
Typically a Word document with an embedded Excel chart contains the Excel file and a chart part like:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
<c:chartSpace xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
  <c:date1904 val="0"/>
  <c:lang val="en-AU"/>
  <c:roundedCorners val="0"/>
  <c:chart>
    <c:autoTitleDeleted val="0"/>
    <c:plotArea>
      <c:layout/>
      <c:barChart>
        <c:barDir val="col"/>
        <c:grouping val="stacked"/>
        <c:varyColors val="0"/>
        <c:ser>
          <c:idx val="0"/>
          <c:order val="0"/>
          <c:tx>
            <c:strRef>
              <c:f>Sheet1!$B$1</c:f>
              <c:strCache>
                <c:ptCount val="1"/>
                <c:pt idx="0">
                  <c:v>Series 1</c:v>
                </c:pt>
              </c:strCache>
            </c:strRef>
          </c:tx>
          <c:invertIfNegative val="0"/>
          <c:cat>
            <c:strRef>
              <c:f>Sheet1!$A$2:$A$5</c:f>
              <c:strCache>
                <c:ptCount val="4"/>
                <c:pt idx="0">
                  <c:v>Category 1</c:v>
                </c:pt>
                <c:pt idx="1">
                  <c:v>Category 2</c:v>
                </c:pt>
                <c:pt idx="2">
                  <c:v>Category 3</c:v>
                </c:pt>
                <c:pt idx="3">
                  <c:v>Category 4</c:v>
                </c:pt>
              </c:strCache>
            </c:strRef>
          </c:cat>
          <c:val>
            <c:numRef>
              <c:f>Sheet1!$B$2:$B$5</c:f>
              <c:numCache>
                <c:formatCode>General</c:formatCode>
                <c:ptCount val="4"/>
                <c:pt idx="0">
                  <c:v>4.3</c:v>
                </c:pt>
                <c:pt idx="1">
                  <c:v>2.5</c:v>
                </c:pt>
                <c:pt idx="2">
                  <c:v>3.5</c:v>
                </c:pt>
                <c:pt idx="3">
                  <c:v>4.5</c:v>
                </c:pt>
              </c:numCache>
            </c:numRef>
          </c:val>
        </c:ser>
        <c:ser>
          <c:idx val="1"/>
          <c:order val="1"/>
          <c:tx>
            <c:strRef>
              <c:f>Sheet1!$C$1</c:f>
              <c:strCache>
                <c:ptCount val="1"/>
                <c:pt idx="0">
                  <c:v>Series 2</c:v>
                </c:pt>
              </c:strCache>
            </c:strRef>
          </c:tx>
          <c:invertIfNegative val="0"/>
          <c:cat>
            <c:strRef>
              <c:f>Sheet1!$A$2:$A$5</c:f>
              <c:strCache>
                <c:ptCount val="4"/>
                <c:pt idx="0">
                  <c:v>Category 1</c:v>
                </c:pt>
                <c:pt idx="1">
                  <c:v>Category 2</c:v>
                </c:pt>
                <c:pt idx="2">
                  <c:v>Category 3</c:v>
                </c:pt>
                <c:pt idx="3">
                  <c:v>Category 4</c:v>
                </c:pt>
              </c:strCache>
            </c:strRef>
          </c:cat>
          <c:val>
            <c:numRef>
              <c:f>Sheet1!$C$2:$C$5</c:f>
              <c:numCache>
                <c:formatCode>General</c:formatCode>
                <c:ptCount val="4"/>
                <c:pt idx="0">
                  <c:v>2.4</c:v>
                </c:pt>
                <c:pt idx="1">
                  <c:v>4.4000000000000004</c:v>
                </c:pt>
                <c:pt idx="2">
                  <c:v>1.8</c:v>
                </c:pt>
                <c:pt idx="3">
                  <c:v>2.8</c:v>
                </c:pt>
              </c:numCache>
            </c:numRef>
          </c:val>
        </c:ser>
        <c:ser>
          <c:idx val="2"/>
          <c:order val="2"/>
          <c:tx>
            <c:strRef>
              <c:f>Sheet1!$D$1</c:f>
              <c:strCache>
                <c:ptCount val="1"/>
                <c:pt idx="0">
                  <c:v>Series 3</c:v>
                </c:pt>
              </c:strCache>
            </c:strRef>
          </c:tx>
          <c:invertIfNegative val="0"/>
          <c:cat>
            <c:strRef>
              <c:f>Sheet1!$A$2:$A$5</c:f>
              <c:strCache>
                <c:ptCount val="4"/>
                <c:pt idx="0">
                  <c:v>Category 1</c:v>
                </c:pt>
                <c:pt idx="1">
                  <c:v>Category 2</c:v>
                </c:pt>
                <c:pt idx="2">
                  <c:v>Category 3</c:v>
                </c:pt>
                <c:pt idx="3">
                  <c:v>Category 4</c:v>
                </c:pt>
              </c:strCache>
            </c:strRef>
          </c:cat>
          <c:val>
            <c:numRef>
              <c:f>Sheet1!$D$2:$D$5</c:f>
              <c:numCache>
                <c:formatCode>General</c:formatCode>
                <c:ptCount val="4"/>
                <c:pt idx="0">
                  <c:v>2</c:v>
                </c:pt>
                <c:pt idx="1">
                  <c:v>2</c:v>
                </c:pt>
                <c:pt idx="2">
                  <c:v>3</c:v>
                </c:pt>
                <c:pt idx="3">
                  <c:v>5</c:v>
                </c:pt>
              </c:numCache>
            </c:numRef>
          </c:val>
        </c:ser>
        <c:dLbls>
          <c:showLegendKey val="0"/>
          <c:showVal val="0"/>
          <c:showCatName val="0"/>
          <c:showSerName val="0"/>
          <c:showPercent val="0"/>
          <c:showBubbleSize val="0"/>
        </c:dLbls>
        <c:gapWidth val="150"/>
        <c:overlap val="100"/>
        <c:axId val="62488576"/>
        <c:axId val="58691520"/>
      </c:barChart>
      <c:catAx>
        <c:axId val="62488576"/>
        <c:scaling>
          <c:orientation val="minMax"/>
        </c:scaling>
        <c:delete val="0"/>
        <c:axPos val="b"/>
        <c:majorTickMark val="out"/>
        <c:minorTickMark val="none"/>
        <c:tickLblPos val="nextTo"/>
        <c:crossAx val="58691520"/>
        <c:crosses val="autoZero"/>
        <c:auto val="1"/>
        <c:lblAlgn val="ctr"/>
        <c:lblOffset val="100"/>
        <c:noMultiLvlLbl val="0"/>
      </c:catAx>
      <c:valAx>
        <c:axId val="58691520"/>
        <c:scaling>
          <c:orientation val="minMax"/>
        </c:scaling>
        <c:delete val="0"/>
        <c:axPos val="l"/>
        <c:majorGridlines/>
        <c:numFmt formatCode="General" sourceLinked="1"/>
        <c:majorTickMark val="out"/>
        <c:minorTickMark val="none"/>
        <c:tickLblPos val="nextTo"/>
        <c:crossAx val="62488576"/>
        <c:crosses val="autoZero"/>
        <c:crossBetween val="between"/>
      </c:valAx>
    </c:plotArea>
    <c:legend>
      <c:legendPos val="r"/>
      <c:overlay val="0"/>
    </c:legend>
    <c:plotVisOnly val="1"/>
    <c:dispBlanksAs val="gap"/>
    <c:showDLblsOverMax val="0"/>
  </c:chart>
  <c:externalData r:id="rId1">
    <c:autoUpdate val="0"/>
  </c:externalData>
</c:chartSpace>
 
Parsed in 0.026 seconds, using GeSHi 1.0.8.4


Sorry, but docx4j's PDF/HTML export doesn't know how to interpret that. And the docx doesn't include an image of the chart we can use instead (unless maybe there is an option somewhere in Word to force that?)

You can vote for this feature request at docx4j.userecho.com

On your other question: What does the XML for the picture look like? Please start a new thread, and post it (unzip the docx, and look inside word/document.xml)