Free Support Forum - aspose.com

Any chance to hook into the layout process?

Hello!

Is there any chance to hook into the layout process during rendering / layouting the document? I'm thinking of a callback info like "place paragraph p at location x,y with size w,h".

We're using Aspose.Words for Java 4.0.3.

Best regards
Klemens Schrage

Hi Klemens.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. There is no way to hook into layout process. Layout of MS Word document is quite complex task and has very complex algorithm.

During layout, the document is converted into the internal fixed page model that is used to render document into fixed page formats, like PDF. In this model you will not find such things like paragraphs or tables. Whole document is represented by simple pieces like: Glyphs (to represent text), Path (to represent lines and figures), Canvas (to represent areas) and Image (to represent images). Then using these simple chunks, renderer builds the final document, like PDF.

Best regards,

The issues you have found earlier (filed as WORDSNET-2978) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(68)
Hi,

Could you please provide me with some demo code of how to use the LayoutEnumerator? I tried it like this:

Document d = new Document("c:/myfile.rtf");
d.updatePageLayout();
final LayoutEnumerator layoutEnumerator = new LayoutEnumerator(d);

d.accept(new DocumentVisitor()
{
@Override
public int visitParagraphStart(Paragraph paragraph) throws Exception
{
if (layoutEnumerator.moveNode(paragraph))
{
System.out.println(paragraph.getText());
walk(layoutEnumerator);
}
return super.visitParagraphStart(paragraph);
}

@Override
public int visitRun(Run run) throws Exception
{
if (layoutEnumerator.moveNode(run))
{
print(layoutEnumerator);
}

return super.visitRun(run);
}
});

Unfortunately I only get information for the paragraphs which seem to be odd because of very unmatching x-coordinates from paragraphs of same alignment.

I hope you can help me. It would be enough to have a snippet which simply walks through the tree down to the run-level.

Update: While playing around I think I managed to get the desired walk through. Unfortunately I'm stuck at the SPAN(TEXT)-level because I haven't found a way of getting the font and stuff from the "current" object of the LayoutEnumerator. Any chance to get this?

Best regards
Klemens Schrage

Hi Klemens,


Please accept my apologies for late response.

Thanks for your inquiry.
Klemens Schrage:
Unfortunately I only get information for the paragraphs which seem to be odd because of very unmatching x-coordinates from paragraphs of same alignment.
Could you please attach your input Word document here for testing? I will investigate the issue on my side and provide you more information.
Klemens Schrage:
I hope you can help me. It would be enough to have a snippet which simply walks through the tree down to the run-level.
LayoutEnumerator.MoveNode Method do not work for Run node because typically inline nodes of a document have multiple corresponding spans in layout. This method works for inline nodes which represent indivisible content, e.g. paragraph break, shape anchor, footnote reference.
Klemens Schrage:
Update: While playing around I think I managed to get the desired walk through. Unfortunately I’m stuck at the SPAN(TEXT)-level because I haven’t found a way of getting the font and stuff from the “current” object of the LayoutEnumerator. Any chance to get this?
Could you please attach your input Word document and code here for testing? I will investigate the issue on my side and provide you more information.