0

I'm trying to create a document in java

WordprocessingMLPackage wordPackage = WordprocessingMLPackage.createPackage();
wordPackage.getMainDocumentPart().addStyledParagraphOfText("Title","User comments");
for(
... adding comments with a line between
)
SaveToZipFile saver = new SaveToZipFile(wordPackage);
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
response.setHeader("content-disposition","filename=My_file.doc");
saver.save(response.getOutputStream());

To add comments with the line, I'm adding a border to my content following the setup here: http://www.docx4java.org/forums/docx-java-f6/tip-constructing-complex-objects-t7.html

With regards to the border.. It doesn't show up properly unless it contains both the addParagraph lines, which means I have extra white space, I'm trying to fix (even out) this by adjusting the font size of my empty addParagraph (with the border) to 2 (or 0) so that there is equal space above and below. The CTBorder.setSz() doesn't seem to be doing anything and neither does Spacing.setAfter() / Spacing.setBefore()

The point I'm at is trying to figure out how to create or edit a style to apply a font size to the empty paragraph, which I can't figure out... However I'm also open to other suggestions to solve my problem.

Emma
  • 167
  • 1
  • 9

1 Answers1

1

Instead of using addStyledParagraphOfText, I'd suggest you upload a docx sample containing what you want to the docx4j code generator, then copy/paste the code for the paragraph you want.

Then just add it: wordPackage.getMainDocumentPart().getContent().add(yourp)

JasonPlutext
  • 15,352
  • 4
  • 44
  • 84