You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2016/11/04 10:08:40 UTC
[Bug 60339] New: POI cannot add Picture to docx by CTAnchor
https://bz.apache.org/bugzilla/show_bug.cgi?id=60339
Bug ID: 60339
Summary: POI cannot add Picture to docx by CTAnchor
Product: POI
Version: 3.14-FINAL
Hardware: PC
Status: NEW
Severity: normal
Priority: P2
Component: XWPF
Assignee: dev@poi.apache.org
Reporter: 515951184@163.com
Target Milestone: ---
POI XWPF usage anchor tag add position picture failure.
Using inline is ok, but using anchor can not open word, prompt
/word/document.xml line 2, col ...
docx4j is ok.
//========================================
// code: @see org.apache.poi.xwpf.usermodel.XWPFRun#addPicture
//========================================
XWPFDocument doc = new XWPFDocument();
XWPFParagraph p = doc.createParagraph();
XWPFRun r = p.createRun();
String relationId = doc.addPictureData(new FileInputStream(filename),
XWPFDocument.PICTURE_TYPE_PNG);
String xml = readFile("doc.xml");
xml = xml.replaceAll("embed=\"rId3\"", "embed=\"" + relationId + "\"");
CTDrawing drawing = r.getCTR().addNewDrawing();
drawing.set(XmlToken.Factory.parse(xml, DEFAULT_XML_OPTIONS));
CTPicture pic = getCTPictures(drawing).get(0);
XWPFPicture xwpfPicture = new XWPFPicture(pic, r);
r.getEmbeddedPictures().add(xwpfPicture);
...
public List<CTPicture> getCTPictures(XmlObject o) {
List<CTPicture> pictures = new ArrayList<CTPicture>();
XmlObject[] picts = o.selectPath("declare namespace pic='"
+ CTPicture.type.getName().getNamespaceURI() + "' .//pic:pic");
for (XmlObject pict : picts) {
if (pict instanceof XmlAnyTypeImpl) {
// Pesky XmlBeans bug - see Bugzilla #49934
try {
pict = CTPicture.Factory.parse(pict.toString(),
DEFAULT_XML_OPTIONS);
} catch (XmlException e) {
throw new POIXMLException(e);
}
}
if (pict instanceof CTPicture) {
pictures.add((CTPicture) pict);
}
}
return pictures;
}
//==============================
// doc.xml:
//==============================
<anchor allowOverlap="true" layoutInCell="false" locked="false"
behindDoc="false" relativeHeight="0" simplePos="false" distR="0" distL="0"
distB="0" distT="0">
<simplePos y="0" x="0"/>
<positionH relativeFrom="margin">
<align>right</align>
</positionH>
<positionV relativeFrom="page">
<posOffset>360000</posOffset>
</positionV>
<extent cy="4997254" cx="5732145"/>
<effectExtent b="0" r="0" t="0" l="0"/>
<wrapNone/>
<docPr descr="Picture Alt" name="Picture Hit" id="0"/>
<cNvGraphicFramePr>
<a:graphicFrameLocks noChangeAspect="true"
xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" />
</cNvGraphicFramePr>
<a:graphic
xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
<a:graphicData
uri="http://schemas.openxmlformats.org/drawingml/2006/picture"
xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
<pic:pic
xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture">
<pic:nvPicPr>
<pic:cNvPr name="Picture Hit" id="1"/>
<pic:cNvPicPr/>
</pic:nvPicPr>
<pic:blipFill>
<a:blip r:embed="rId3"/>
<a:stretch>
<a:fillRect/>
</a:stretch>
</pic:blipFill>
<pic:spPr>
<a:xfrm>
<a:off y="0" x="0"/>
<a:ext cy="4997254"
cx="5732145"/>
</a:xfrm>
<a:prstGeom prst="rect">
<a:avLst/>
</a:prstGeom>
</pic:spPr>
</pic:pic>
</a:graphicData>
</a:graphic>
</anchor>
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 60339] POI cannot add Picture to docx by CTAnchor
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60339
apache <51...@163.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |FIXED
--- Comment #1 from apache <51...@163.com> ---
The problem has been resolved.
By reference docx4j project, it is found that XML is missing a namespace
prefix.
Resolved by modify doc.xml.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 60339] POI cannot add Picture to docx by CTAnchor
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60339
Dominik Stadler <do...@gmx.at> changed:
What |Removed |Added
----------------------------------------------------------------------------
OS| |All
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org