incubator-odf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dimitrios Kateros <dkate...@gmail.com>
Subject Re: adding in memory image to document table cell
Date Tue, 11 Dec 2012 15:10:42 GMT
Close this, I will post my solution for reference.

FileInputStream fis = new FileInputStream(new File("/tmp/test.jpg"));

OdfPackage pkg = odt.getPackage();
pkg.insert(fis, "Pictures/test.jpg", "image/jpeg");
fis.close();

Table table = odt.addTable(1, 2);
Cell cell = table.getCellByPosition(0, 0);
cell.setStringValue("some text");
Cell cell2 = table.getCellByPosition(1, 0);

Paragraph p = Paragraph.newParagraph(cell2);
TextPElement firstParagraph =
OdfElement.findFirstChildNode(TextPElement.class, cell2.getOdfElement());
DrawFrameElement frame = firstParagraph.newDrawFrameElement();
frame.setSvgHeightAttribute("0.672cm"); //hardcoded
frame.setSvgWidthAttribute("3.444cm"); //hardcoded
DrawImageElement imgElement = frame.newDrawImageElement();
imgElement.setXlinkHrefAttribute("Pictures/test.jpg");
imgElement.setXlinkTypeAttribute("simple");

odt.save("/tmp/test.odt");



On Tue, Dec 11, 2012 at 2:56 PM, Dimitrios Kateros <dkateros@gmail.com>wrote:

> OK, made some progress. The following snippet will add the image to the
> document package, but I still cannot add it to the Table using the
> org.odftoolkit.simple.table.Cell#setImage(URI uri) method (it still ends up
> looking to the filesystem).
>
> byte[] img; //assume this is the image.
>
> TextDocument odt = TextDocument.newTextDocument();
> OdfPackage pkg = odt.getPackage();
> pkg.insert(new ByteArrayInputStream(img), "Pictures/test.jpg",
> "image/jpeg");
>
> It looks that I have to manipulate the XML to look like this:
>
> <table:table-cell table:style-name="a860a14">
>     <text:p>
>         <draw:frame svg:height="0.672cm" svg:width="3.444cm"
> text:anchor-type="paragraph">
>             <draw:image xlink:href="Pictures/test.jpg"
> xlink:type="simple"></draw:image>
>         </draw:frame>
>     </text:p>
> </table:table-cell>
>
> Is the advanced API my only bet right now?
>
> Thx again // Dimitris
>
> PS: I obviously do not have enough experience with the library (just today
> tbh), but, if there is no other way to do it with the simple API, would it
> be too far-fetched for the implementation to handle it correctly if the
> relative odf package path is used as the URI input?
>
>
>
>
> On Tue, Dec 11, 2012 at 12:54 PM, Dimitrios Kateros <dkateros@gmail.com>wrote:
>
>> Greetings,
>>
>> I have an in memory image that I wish to add to a specific table cell of
>> a document.
>>
>> As far as I can tell, the OdfToolkit API only allows this if the user
>> provides a java.net.URI instance.
>>
>> Is there anyway to circumvent this using either the simple or the dom
>> api? I would prefer not to write the image to disk (or anything similar) in
>> order to provide a URI.
>>
>> Thank you in advance,
>>
>> Dimitris
>>
>
>
>
> --
> Dimitrios Kateros
>



-- 
Dimitris Kateros

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message