Automatically insert empty line breaks into .docx

Asked 2 years ago, Updated 2 years ago, 125 views

Creating an XSLT style sheet that generates a batch of Word (.docx) from XML.

I think the layout is as follows. Place the description and instructions to the left and the image to the right.

floatfig Example

An element is provided on the XML side that can describe it, the XSLT style sheet contains w:p (paragraph) and the image on the right is placed in the text box. (Both are w:drawing and the text box is generated at the beginning of w:p)

)

It's fine if it's alone, but if the first description is less than the one on the right, the second image will overlap with the first one.

Patterns with overlapping images

We have looked into various ways to solve this problem, but it seems that the only way is to empty the text as follows.

Enter Empty Line

However, doing this manually requires a huge amount of work. We hope the program can somehow automatically generate empty lines. That is, we calculate b-a, convert it into empty lines, and insert it automatically.

The ingredients you have are

  • b height is easy to obtain because it is the height of the image.
  • a height is the problem. You can get the results of w:p converted to WordprocessingML instead of the original XML.

In other words, from the latter, you want to simulate the composition/drawing that Microsoft Word will do and find the height of a.

Since the XSLT processor is Java, I think you can use Java's help to calculate this (make some Java module and call it from the XSLT style sheet).

Unfortunately, I'm not familiar with this kind of Java composition/drawing field. I'd appreciate it if you could give me any tips, methods, or tips.

That's it

java xml xslt open-xml

2022-09-30 16:23

1 Answers

I'm self RES. I solved it with the advice of my colleagues.

Word had an element to keep the text from going around. You can enter its "separate" from the menu below.

Turn Back String

When I looked at WordprocessingML, I found something special about line breaks, such as the following.

<w:r>
  <w:brw:type="textWrapping"w:clear="all"/>
</w:r>

Similar to XSL-FO's @clear property. @clear is the object to solve the loop, while w:br must be right in front of the paragraph to solve the loop. This seems to be the difference. Now it's solved somehow.


2022-09-30 16:23

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.