0

I am currently developing an application for this company as my last year of studies project, and in this application there's this function that allows you to print a paper, so i used the jeditorpane obviously, with the Charles Bell HTMLEditorKit for the predefined functions like setting the font and printing, etc... and there's this pre-written text that i have to load from a text file and then the program is supposed to add some text inside the file automatically, and the user also is allowed to add more if he needs to, or change the font or style or whatever.

So here is the problem, since the predefined text should be already aligned with the font already set and some other properties already in place, and since the txt file doesn't allow that, i tried to use a docx file, which makes the text incomprehensible in the editorpane, i also tried the docx4j api, but then i wouldn't have the HTMLEditorKit menu and functions, (or maybe i could but i don't know how) and the execution of the app becomes rather slow with this api. I also tried this metaphase editor kit which i found it to be really useful with a lot of functions to offer, but i couldn't load a text file to it's textpane.

So my question(s) to be exact is(are): 1)How can i use the charles bell HTMLEditorKit and load a docx file into the edtiorpane in question? 2)Or how can i use the docx4j api with the HTMLEditorKit with the functions menu (style, print, font...) or maybe another predefined menu? 3)Or even better, how can i still use the metaphaseEditorPane with its full of functions menu and at the same time load an existing docx file in its textpane?

Sorry for the long question and any help would count, i would really need and appreciate it.

user3610008
  • 79
  • 2
  • 11

2 Answers2

0

See Adding custom shapes to JTextpane and saved to new Word document for references to two projects which use docx4j to provide rich text editing of docx within Swing.

Community
  • 1
  • 1
JasonPlutext
  • 15,352
  • 4
  • 44
  • 84
  • Okay this is probably a stupid question, but does the docx4all have a tool bar? i mean the toolbar showing in the projects you gave me the link to, with the "print" menu, the alignment and all of that... to make more sense, does the editorkit have a tool bar? – user3610008 May 07 '14 at 07:49
  • docx4all is a standalone application, as opposed to a component. – JasonPlutext May 07 '14 at 08:29
  • i tried to integrate the docx4all to my app but i couldn't do it, i searched everywhere to find a "how to" integrate it but i didn't find anything, so do you have a link to a tutorial on how to integrate it, or if not i'd be more than grateful if you explain to me briefly how can i do it. (the idea of course is to launch docx4all when the user hits this button, this way he'll have a text in the textpane, and then he can modify it or print it or save it using the tool bar) Thank you in advance. – user3610008 May 07 '14 at 10:41
0

I found finally the solution after days of searching and testing, It turns out to be very simple actually.

All i had to do is use a metaphase editor panel, (which has a great toolbar by the way) create a DocxEditorkit and then set the editorkit of the metaphase editor panel's textpane to this DocxEditorKit, although the metamorphose works with HTML text pane, it miraculously worked...

DocxEditorKit DEK=new DocxEditorKit;
MetaphaseEditorPanel MEP=new MetaphaseEditorPanel;
MEP.getHTMLTextPane().setEditorKit(DEK);

   //Try and Catch blocks of course to read the file
DEK.read(new FileInputStream(PathToFile), MEP.getHTMLTextPane().getDocument(), 0);
getContentPane.add(MEP, BorderLayout.CENTER);

And that was it... Who thought it would be as simple as this.

user3610008
  • 79
  • 2
  • 11