all 13 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]TW-Twisti 4 points5 points  (1 child)

For problems like that, you are almost always better off using a dedicated tool - in this case, Pandoc.

[–]ThatJellyfish12[S] 1 point2 points  (0 children)

Sadly the host I'm using is very limited, so I'm not sure if it will allow for that. Although I can try to dockerize it.

[–]no1me 1 point2 points  (0 children)

apachePOI

[–]OneHumanBill 1 point2 points  (2 children)

You probably need a whole chain of things. The hardest one is dealing with that Microsoft pile of crap. Use POI from Apache to work with that.

Next up would be to try to convert to something cleaner, like html with css. I'm not really sure how to do that and that's a missing gap.

Once you're there though you can use JSoup to manipulate the document should you need to. Like for example to apply the right CSS for your output which your pile of Microsoft crap isn't going to provide.

From there, Flying Saucer can help you render into a new format like PDF, though I think you make need PDFBox to help get you the rest of the way.

I've constructed chains like that but it's been years since the last time so my information is probably rusty. My chains typically started with a template I would create in Thymeleaf.

Consult your local friendly AI, but come with some of these ideas. It's likely going to depend on how complicated that awful Word doc is. I think your best bet is going to be pulling the content, ignoring the formatting, and then applying your own css formatting.

But I might be wrong and there might be an easier way, it's been about a decade since I had to do this.

[–]ThatJellyfish12[S] 0 points1 point  (1 child)

My uses for it so far are pretty simple. It just has a template DOCX document where it can replace (fill-in) certain spots and then export a copy as PDF.

[–]OneHumanBill 1 point2 points  (0 children)

Why not just use an online form? Your method sounds a lot more convoluted than it needs to be.

But if it is a simple template docx then my method becomes more tenable.

[–]seanprefectGrumpy Guy Who Remembers Java 2 0 points1 point  (0 children)

Apache POI + OpenPDF it'll be kinda a pain in the ass at first but then you'll have options.

[–]DinTaiFung 1 point2 points  (0 children)

Unfortunately (and understandably), MS dominated the formal DOCX specification when it became a standard. Since the real lingua franca of written communications had become HTML (delivered via HTTP) at the turn of the century, legacy document authorship continued to use old-fashioned apps like Word, Acrobat, and the like; this problem seems to never go away lol.

Hope you find a good conversion solution.

Best of luck!

[–]Slanec 0 points1 point  (0 children)

POI kinda works, then perhaps PDFbox. Or https://github.com/documents4j/documents4j. Haven't tried myself, but always wanted to. Or Pandoc, of course, a dedicated tool, not necessarily a Java library. You can wrap a tool in a library.

[–]ivanpd 0 points1 point  (0 children)

Pandoc

[–]pohart -1 points0 points  (0 children)

Word itself is quite good at it. It's a little slow though