Hi Devin,

Sure, here is my little test case.
I don't know if I can attach files to the mailing list, let me know...

Generate.java creates a odt file using Simple, and Read.java reads it using
ODFDOM.

After generating and opening in LibreOffice the picture is stretched
vertically and overflows to the right.
If you manually insert the picture in the next Cell: "Insert > Picture >
>From File ( Link == true )" , then the picture is sized correctly and an
external link is used.

I would like to generate an odt file with pictures of type "external link"
and retrieve the link while reading.

thanks,
Jan


On Mon, Dec 5, 2011 at 4:33 AM, Devin Han <[email protected]> wrote:

> Hi,
>
> Simple API supports automatically sizes the image to stay inside the cell,
> no need insert frame by yourself.
> Could you share me you test case? Maybe there are some differences.
>
> 2011/12/5 ikeamanual <[email protected]>
>
> > Hi,
> >
> > I am using Cell.setImage() and the image is larger then the cell, it
> > overflows the cell boundary.
> >
> > I have a table with 2 columns. If I do the same in LibreOffice is
> > automatically sizes the image to stay inside the left column.
> >
> > Do I somehow need to insert a Frame into the Cell?
> >
> > thanks,
> > Jan
> >
>
>
>
> --
> -Devin
>
import java.net.URI;

import org.odftoolkit.simple.TextDocument;
import org.odftoolkit.simple.draw.Image;
import org.odftoolkit.simple.table.Cell;
import org.odftoolkit.simple.table.Table;
import org.odftoolkit.simple.text.Paragraph;

public class Generate {
	public static void main(String[] args) throws Exception {
		TextDocument document1 = TextDocument.newTextDocument();

		Paragraph para = document1.addParagraph("Acrobaat");
		para.applyHeading(true, 1);
		para = document1.addParagraph("Feedback1");
		para.applyHeading(true, 2);
		Table t = document1.addTable(1, 2);
		Cell cell = t.getCellByPosition(0, 0);
		Image image1 = cell.setImage(new URI("Krokodil.jpg"));

		para = document1.addParagraph("Feedback2");
		para.applyHeading(true, 2);

		para = document1.addParagraph("Clowntje");
		para.applyHeading(true, 1);
		
		document1.save("goodbad-generated.odt");

	}
}
import org.odftoolkit.odfdom.doc.OdfDocument;
import org.odftoolkit.odfdom.doc.OdfTextDocument;
import org.odftoolkit.odfdom.doc.table.OdfTable;
import org.odftoolkit.odfdom.doc.table.OdfTableCell;
import org.odftoolkit.odfdom.dom.element.draw.DrawFrameElement;
import org.odftoolkit.odfdom.dom.element.draw.DrawImageElement;
import org.odftoolkit.odfdom.dom.element.office.OfficeTextElement;
import org.odftoolkit.odfdom.dom.element.table.TableTableElement;
import org.odftoolkit.odfdom.dom.element.text.TextHElement;
import org.odftoolkit.odfdom.dom.element.text.TextPElement;
import org.odftoolkit.odfdom.pkg.OdfElement;

public class Read {

	/**
	 * @param args
	 */
	public static void main(final String[] args) {

		OdfTextDocument odt;
		try {
			odt = (OdfTextDocument) OdfDocument
					.loadDocument("goodbad-generated.odt");
			OfficeTextElement officeText = odt.getContentRoot();
			TextHElement firstHeader = OdfElement.findFirstChildNode(
					TextHElement.class, officeText);
			System.out.println("firstHeader = " + firstHeader.getTextContent());
			TextHElement secondHeader = OdfElement.findNextChildNode(
					TextHElement.class, firstHeader);
			System.out.println("secondHeader = "
					+ secondHeader.getTextContent());
			TableTableElement table = OdfElement.findNextChildNode(
					TableTableElement.class, secondHeader);
			//System.out.println("table = " + table);
			OdfTable t = OdfTable.getInstance(table);
			OdfTableCell cell = t.getCellByPosition(0, 0);
			//System.out.println("cell = " + cell);
			//System.out.println("cell.valueType = " + cell.getValueType());

			OdfElement e = cell.getOdfElement();
			TextPElement pElement = OdfElement.findFirstChildNode(
					TextPElement.class, e);
			// copied from SimpleAPI Cell::getImage()
			if (pElement != null) {
				DrawFrameElement drawFrame = OdfElement.findFirstChildNode(
						DrawFrameElement.class, pElement);
				if (drawFrame != null) {
					DrawImageElement imageElement = OdfElement
							.findFirstChildNode(DrawImageElement.class,
									drawFrame);
					System.out.println("image href = "
							+ imageElement.getXlinkHrefAttribute());
				}
			} else {
				DrawFrameElement drawFrame = OdfElement.findFirstChildNode(
						DrawFrameElement.class, e);
				if (drawFrame != null) {
					DrawImageElement imageElement = OdfElement
							.findFirstChildNode(DrawImageElement.class,
									drawFrame);
					System.out.println("image href = "
							+ imageElement.getXlinkHrefAttribute());
				}
			}

			TextHElement thirdHeader = OdfElement.findNextChildNode(
					TextHElement.class, table);
			System.out.println("thirdHeader = " + thirdHeader.getTextContent());
			TextHElement fourthHeader = OdfElement.findNextChildNode(
					TextHElement.class, thirdHeader);
			System.out.println("fourthHeader = " + fourthHeader.getTextContent());

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}

Reply via email to