How to correctly position a header image with docx4j?

本秂侑毒 提交于 2019-12-12 02:43:00

问题


I am trying to convert this Word document with a header showing an image on the right

http://www.filesnack.com/files/cduiejc7

to PDF using this sample code:

https://github.com/plutext/docx4j/blob/master/src/samples/docx4j/org/docx4j/samples/ConvertOutPDF.java

Here's the result:

http://www.filesnack.com/files/ctjs659h

While the Word document has the header image on the right, the converted PDF shows it on the left.

How can I make docx4j to reproduce the original document as PDF?


回答1:


Your image is positioned relative to a paragraph:

      <w:drawing>
    <wp:anchor distT="0" distB="0" distL="114300" distR="114300" simplePos="0" relativeHeight="251658240" behindDoc="0" locked="0" layoutInCell="1" allowOverlap="1" wp14:anchorId="791936E3" wp14:editId="575B92C8">
      <wp:simplePos x="0" y="0"/>
      <wp:positionH relativeFrom="column">
        <wp:posOffset>5317388</wp:posOffset>
      </wp:positionH>
      <wp:positionV relativeFrom="paragraph">
        <wp:posOffset>-325755</wp:posOffset>
      </wp:positionV>

docx4j potential to support stuff like that in PDF output is limited by what XSL FO supports. See docx4j's TextBoxTest class for what we can do with text boxes.

Currently, although we can position some textBoxes; we don't do the same for floating images: https://github.com/plutext/docx4j/issues/127

In the meantime, a possible workaround for some cases (eg float right) is to use a table.

Or possibly, you could try putting the image inside a text box!



来源:https://stackoverflow.com/questions/24745423/how-to-correctly-position-a-header-image-with-docx4j

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!