It can easily convert the normal text area content to word document using XWPF or to pdf using iTextpdf, but when I am trying to get data from rich text area, the content is not displaying in word document or pdf
I want to create a word document using XWPF from a rich text area content. But the content not displaying in the word document created. The word document content shows as follows.
</o:OfficeDocumentSettings> </xml>
Normal</w:View> 0</w:Zoom> false</w:SaveIfXMLInvalid> false</w:IgnoreMixedContent> false</w:AlwaysShowPlaceholderText> EN-US</w:LidThemeOther> X-NONE</w:LidThemeAsian> AR-SA</w:LidThemeComplexScript> </w:Compatibility> </m:mathPr></w:WordDocument> </xml>
It displays the correct data in word document created when getting data from normal text area.
New Letter.jsp
<head>
<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
<script>tinymce.init({ selector:'textarea' });</script>
</head>
<s:form action="letter.action" method="post" class="normalform">
<p>
<label style="vertical-align: middle;"></label>
<s:textarea name="letter.removed" label="Content" style=""
cssStyle="vertical-align:top;width: 600px; height: 500px;" />
</p>
<s:submit value="Add Letter" align="center" />
</s:form>
LetterAction.java
XWPFDocument document= new XWPFDocument();
File file=new File("C:\\Myuploads\\createparagraph.docx");
FileOutputStream out = new FileOutputStream(file);
XWPFParagraph paragraph = document.createParagraph();
XWPFRun run=paragraph.createRun();
run.setText(letter.getContent());
document.write(out);
out.close();
System.out.println("createparagraph.docx written successfully");
return file;
Document document = new Document(); File file = new File("C:\Myuploads\" + referenceId + ".pdf");
PdfWriter.getInstance(document, new FileOutputStream(file));
document.open();
Font font = new Font(FontFamily.HELVETICA, 12, Font.BOLD);
Paragraph p = new Paragraph();
toName.setIndentationLeft(56f);
Paragraph p2 = new Paragraph();
// p2.setSpacingBefore(56f);
p2.setIndentationLeft(56f);
p.add(new Chunk("Ref"));
p.setTabSettings(new TabSettings(56f));
p.add(Chunk.TABBING);
p.add(new Chunk(letter.getReferenceId()));
p.add(new Chunk("\nDate"));
p.setTabSettings(new TabSettings(56f));
p.add(Chunk.TABBING);
p.add(new Chunk(letter.getLetterDate()));
p.add(new Chunk("\n\nTo"));
p.setTabSettings(new TabSettings(56f));
p.add(Chunk.TABBING);
p = new Paragraph();
p.add("\n" + letter.getContent());
document.add(p);
document.close();
Please help me, how to create the word document or pdf document from the rich text area content, without changing text format. I have searched in Google for this solution....... Advance thanks for sharing the idea
What I have tried:
I want to generate a letter document. I am developing an struts application in java.
I have used both XWPF and iText classes for generating document such as pdf or msword.
The program taking the letter content from a text area defined in jsp. it is working properly when I am using normal text area, but I want to use rich text area for different font style. I am using the rich text area through
<html>
<head>
<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
<script>tinymce.init({ selector:'textarea' });</script>
</head>
<body>
<textarea>Easy (and free!) You should check out our premium features.</textarea>
</body>
</html>
But its not generating the document while using rich text area