Я пытаюсь сгенерировать документ из HTML в docx. Документ класса AlternativeFormatInputPart генерируется правильно с правильным стилем.Почему существует несоответствие стиля при использовании Xhtmlimporter и AlternativeFormatInputPart при создании документа с использованием docx4j
Но
Когда я использую класс XhtmlImporter для Same HTML документа становится генерироваться по-разному. Я хочу использовать класс XhtmlImporter
Как решить эту проблему?
Ниже приведен код HTML и код, используемый для генерации документа.
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>MonthlyReport</title><style>
table
{
border:double #000;
table-layout:fixed;
vertical-align:top;
border-collapse:collapse;
width:7.25in;
}
.main-title
{
margin-top:5%;
font-size:48pt;
font-family:Century Gothic;
color:#2F5897;
text-align:center;
font-weight:300;
}
.year
{
padding-top:10%;
text-align:center;
font-size:18px;
}
.other-detail
{
padding-top:10%;
padding-bottom:10%;
font-weight:bold;
text-align:center;
font-size:18px;
}
.cont
{
font-family:Palatino Linotype;
margin:0 auto;
margin-top:10px;
}
.cont-table
{
border:double #000;
table-layout:fixed;
vertical-align:top;
border-collapse:collapse;
width:7.25in;
}
.cont h1
{
font-family:Century Gothic;
color:#2F5897;
font-weight:400;
margin-left:.15in;
}
.cont h4
{
font-family:Century Gothic;
font-weight:400;
margin-left:.15in;
}
.cont .school-detail
{
margin-left:.1in;
margin-right:.1in;
}
.cont ol
{
margin-left:1in;
margin-right:1in;
}
.cont li
{
margin-bottom:.25in;
}
.cont-heading
{
margin-left:.5in;
font-weight:bold;
text-decoration:underline;
margin-top:.35in;
}
span
{
display:block;
padding-bottom:10px;
}
.rheight
{
height:3.25in;
}
span.DefaultParagraphFont{
display:inline;
}
.DocDefaults{
display:block;
margin-bottom:4mm;
line-height:115%;
font-size:11.0pt;
}
.Normal{
display:block;
}</style></head>
<body>
<table cellpadding="0" cellspacing="0" align="center">
<tr class="rheight">
<td> </td>
</tr>
<tr>
<td>
<div class="main-title"> Monthly report </div>
</td>
</tr>
<tr>
<td>
<div class="year">2016-2017</div>
</td>
</tr>
<tr>
<td>
<div class="other-detail">MONTH: September<br></br> CITY: BANGALORE<br></br> FACILITATOR:
MANIKANDAN<br></br></div>
</td>
</tr>
<tr class="rheight">
<td> </td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" align="center" class="cont-table">
<tr>
<td>
<div class="cont">
<h1>Monthly Report</h1>
<h4>2016-2017</h4><br></br><p class="school-detail">
<p class="cont-heading">102 INTERNATONAL PUBLIC SCHOOL(ICSE)</p>
<ol>
<li><strong>ACTIVITIES CONDUCTED IN THIS SCHOOL. PLEASE MENTION THE TYPE OF SESSIONS CONDUCTED, ANY SPECIFIC POINT YOU WOULD LIKE TO BRING
TO OUR NOTICE REGARDING THE SCHOOL. ACTIVITIES CONDUCTED IN THIS SCHOOL. PLEASE MENTION THE TYPE OF SESSIONS CONDUCTED, ANY
SPECIFIC POINT YOU WOULD LIKE TO BRING TO OUR NOTICE REGARDING THE SCHOOL. ACTIVITIES CONDUCTED IN THIS SCHOOL. PLEASE MENTION
THE TYPE OF SESSIONS CONDUCTED, ANY SPECIFIC POINT YOU WOULD LIKE TO BRING TO OUR NOTICE REGARDING THE SCHOOL. ACTIVITIES
CONDUCTED IN THIS SCHOOL. PLEASE MENTION THE TYPE OF SESSIONS CONDUCTED, ANY SPECIFIC POINT YOU WOULD LIKE TO BRING TO OUR
NOTICE REGARDING THE SCHOOL.</strong><br></br>z1
</li>
<li><strong>ANY SPECIFIC ACTIVITY WORTH MENTIONING BY THE STUDENTS(ATTACH IMAGES TO SEPARATE LINK). ANY SPECIFIC ACTIVITY WORTH MENTIONING
BY THE STUDENTS(ATTACH IMAGES TO SEPARATE LINK). ANY SPECIFIC ACTIVITY WORTH MENTIONING BY THE STUDENTS(ATTACH IMAGES TO SEPARATE
LINK). ANY SPECIFIC ACTIVITY WORTH MENTIONING BY THE STUDENTS(ATTACH IMAGES TO SEPARATE LINK).</strong><br></br>z2
</li>
<li><strong>AT LEAST ONE TESTIMONIAL FROM ONE SCHOOL. AT LEAST ONE TESTIMONIAL FROM ONE SCHOOL. AT LEAST ONE TESTIMONIAL FROM ONE SCHOOL.
AT LEAST ONE TESTIMONIAL FROM ONE SCHOOL.</strong><br></br>z3
</li>
<li><strong>WHAT WENT RIGHT; WHAT DID NOT GO RIGHT & REASONS FOR THE SAME. WHAT WENT RIGHT; WHAT DID NOT GO RIGHT & REASONS FOR THE SAME.
WHAT WENT RIGHT; WHAT DID NOT GO RIGHT & REASONS FOR THE SAME. WHAT WENT RIGHT; WHAT DID NOT GO RIGHT & REASONS FOR THE SAME.</strong><br></br>z4
</li>
<li><strong>DETAILS OF INTERACTION WITH THE PRINCIPAL AND/OR THE POC. DETAILS OF INTERACTION WITH THE PRINCIPAL AND/OR THE POC. DETAILS
OF INTERACTION WITH THE PRINCIPAL AND/OR THE POC. DETAILS OF INTERACTION WITH THE PRINCIPAL AND/OR THE POC.</strong><br></br>z5
</li>
</ol>
<p class="cont-heading">Photos</p>
<p class="cont-heading">102 INTERNATONAL PUBLIC SCHOOL(ICSE)</p>
<p class="Normal DocDefaults " style="margin-bottom: 0in;"><span class="DefaultParagraphFont " style="font-weight: bold;font-size: 14.0pt;text-decoration: underline;">
<center><img height="355" width="620" src="C:\Oracle\Middleware\Weblogic12.1.3\user_projects\domains\springtutorial\servers\ManagedServer\tmp\_WL_user\FMS\ti01mv\public\Hydrangeas.jpg" alt="C:/Users/Public/Pictures/Sample Pictures/Hydrangeas.jpg"></img><p style="text-align:center">Image-1</p>
</center>I
</span></p>
<p class="cont-heading">102 INTERNATONAL PUBLIC SCHOOL(ICSE)</p>
<p class="Normal DocDefaults " style="margin-bottom: 0in;"><span class="DefaultParagraphFont " style="font-weight: bold;font-size: 14.0pt;text-decoration: underline;">
<center><img height="355" width="620" src="C:\Oracle\Middleware\Weblogic12.1.3\user_projects\domains\springtutorial\servers\ManagedServer\tmp\_WL_user\FMS\ti01mv\public\Hydrangeas.jpg" alt="C:/Users/Public/Pictures/Sample Pictures/Hydrangeas.jpg"></img><p style="text-align:center">Image-1</p>
</center>I
</span></p>
<p class="cont-heading">102 INTERNATONAL PUBLIC SCHOOL(ICSE)</p>
<p class="Normal DocDefaults " style="margin-bottom: 0in;"><span class="DefaultParagraphFont " style="font-weight: bold;font-size: 14.0pt;text-decoration: underline;">
<center><img height="355" width="620" src="C:\Oracle\Middleware\Weblogic12.1.3\user_projects\domains\springtutorial\servers\ManagedServer\tmp\_WL_user\FMS\ti01mv\public\Hydrangeas.jpg" alt="C:/Users/Public/Pictures/Sample Pictures/Hydrangeas.jpg"></img><p style="text-align:center">Image-2</p>
</center>I
</span></p>
<p class="cont-heading">ELITE EDUCATIONAL TRUST</p>
<ol>
<li><strong>ACTIVITIES CONDUCTED IN THIS SCHOOL. PLEASE MENTION THE TYPE OF SESSIONS CONDUCTED, ANY SPECIFIC POINT YOU WOULD LIKE TO BRING
TO OUR NOTICE REGARDING THE SCHOOL. ACTIVITIES CONDUCTED IN THIS SCHOOL. PLEASE MENTION THE TYPE OF SESSIONS CONDUCTED, ANY
SPECIFIC POINT YOU WOULD LIKE TO BRING TO OUR NOTICE REGARDING THE SCHOOL. ACTIVITIES CONDUCTED IN THIS SCHOOL. PLEASE MENTION
THE TYPE OF SESSIONS CONDUCTED, ANY SPECIFIC POINT YOU WOULD LIKE TO BRING TO OUR NOTICE REGARDING THE SCHOOL. ACTIVITIES
CONDUCTED IN THIS SCHOOL. PLEASE MENTION THE TYPE OF SESSIONS CONDUCTED, ANY SPECIFIC POINT YOU WOULD LIKE TO BRING TO OUR
NOTICE REGARDING THE SCHOOL.</strong><br></br>y1
</li>
<li><strong>ANY SPECIFIC ACTIVITY WORTH MENTIONING BY THE STUDENTS(ATTACH IMAGES TO SEPARATE LINK). ANY SPECIFIC ACTIVITY WORTH MENTIONING
BY THE STUDENTS(ATTACH IMAGES TO SEPARATE LINK). ANY SPECIFIC ACTIVITY WORTH MENTIONING BY THE STUDENTS(ATTACH IMAGES TO SEPARATE
LINK). ANY SPECIFIC ACTIVITY WORTH MENTIONING BY THE STUDENTS(ATTACH IMAGES TO SEPARATE LINK).</strong><br></br>y2
</li>
<li><strong>AT LEAST ONE TESTIMONIAL FROM ONE SCHOOL. AT LEAST ONE TESTIMONIAL FROM ONE SCHOOL. AT LEAST ONE TESTIMONIAL FROM ONE SCHOOL.
AT LEAST ONE TESTIMONIAL FROM ONE SCHOOL.</strong><br></br>y3
</li>
<li><strong>WHAT WENT RIGHT; WHAT DID NOT GO RIGHT & REASONS FOR THE SAME. WHAT WENT RIGHT; WHAT DID NOT GO RIGHT & REASONS FOR THE SAME.
WHAT WENT RIGHT; WHAT DID NOT GO RIGHT & REASONS FOR THE SAME. WHAT WENT RIGHT; WHAT DID NOT GO RIGHT & REASONS FOR THE SAME.</strong><br></br>y4
</li>
<li><strong>DETAILS OF INTERACTION WITH THE PRINCIPAL AND/OR THE POC. DETAILS OF INTERACTION WITH THE PRINCIPAL AND/OR THE POC. DETAILS
OF INTERACTION WITH THE PRINCIPAL AND/OR THE POC. DETAILS OF INTERACTION WITH THE PRINCIPAL AND/OR THE POC.</strong><br></br>y5
</li>
</ol>
<p class="cont-heading">Photos</p>
<p class="cont-heading">ACHALA VIDHYA MANDIRA</p>
<ol>
<li><strong>ACTIVITIES CONDUCTED IN THIS SCHOOL. PLEASE MENTION THE TYPE OF SESSIONS CONDUCTED, ANY SPECIFIC POINT YOU WOULD LIKE TO BRING
TO OUR NOTICE REGARDING THE SCHOOL. ACTIVITIES CONDUCTED IN THIS SCHOOL. PLEASE MENTION THE TYPE OF SESSIONS CONDUCTED, ANY
SPECIFIC POINT YOU WOULD LIKE TO BRING TO OUR NOTICE REGARDING THE SCHOOL. ACTIVITIES CONDUCTED IN THIS SCHOOL. PLEASE MENTION
THE TYPE OF SESSIONS CONDUCTED, ANY SPECIFIC POINT YOU WOULD LIKE TO BRING TO OUR NOTICE REGARDING THE SCHOOL. ACTIVITIES
CONDUCTED IN THIS SCHOOL. PLEASE MENTION THE TYPE OF SESSIONS CONDUCTED, ANY SPECIFIC POINT YOU WOULD LIKE TO BRING TO OUR
NOTICE REGARDING THE SCHOOL.</strong><br></br>q1
</li>
<li><strong>ANY SPECIFIC ACTIVITY WORTH MENTIONING BY THE STUDENTS(ATTACH IMAGES TO SEPARATE LINK). ANY SPECIFIC ACTIVITY WORTH MENTIONING
BY THE STUDENTS(ATTACH IMAGES TO SEPARATE LINK). ANY SPECIFIC ACTIVITY WORTH MENTIONING BY THE STUDENTS(ATTACH IMAGES TO SEPARATE
LINK). ANY SPECIFIC ACTIVITY WORTH MENTIONING BY THE STUDENTS(ATTACH IMAGES TO SEPARATE LINK).</strong><br></br>q2
</li>
<li><strong>AT LEAST ONE TESTIMONIAL FROM ONE SCHOOL. AT LEAST ONE TESTIMONIAL FROM ONE SCHOOL. AT LEAST ONE TESTIMONIAL FROM ONE SCHOOL.
AT LEAST ONE TESTIMONIAL FROM ONE SCHOOL.</strong><br></br>q3
</li>
<li><strong>WHAT WENT RIGHT; WHAT DID NOT GO RIGHT & REASONS FOR THE SAME. WHAT WENT RIGHT; WHAT DID NOT GO RIGHT & REASONS FOR THE SAME.
WHAT WENT RIGHT; WHAT DID NOT GO RIGHT & REASONS FOR THE SAME. WHAT WENT RIGHT; WHAT DID NOT GO RIGHT & REASONS FOR THE SAME.</strong><br></br>q4
</li>
<li><strong>DETAILS OF INTERACTION WITH THE PRINCIPAL AND/OR THE POC. DETAILS OF INTERACTION WITH THE PRINCIPAL AND/OR THE POC. DETAILS
OF INTERACTION WITH THE PRINCIPAL AND/OR THE POC. DETAILS OF INTERACTION WITH THE PRINCIPAL AND/OR THE POC.</strong><br></br>q5
</li>
</ol>
<p class="cont-heading">Photos</p>
<p class="cont-heading">ACHALA VIDHYA MANDIRA</p>
<p class="Normal DocDefaults " style="margin-bottom: 0in;"><span class="DefaultParagraphFont " style="font-weight: bold;font-size: 14.0pt;text-decoration: underline;">
<center><img height="355" width="620" src="C:\Oracle\Middleware\Weblogic12.1.3\user_projects\domains\springtutorial\servers\ManagedServer\tmp\_WL_user\FMS\ti01mv\public\Hydrangeas.jpg" alt="C:/Users/Public/Pictures/Sample Pictures/Hydrangeas.jpg"></img><p style="text-align:center">Image-1</p>
</center>I
</span></p>
<p class="cont-heading">ACHALA VIDHYA MANDIRA</p>
<p class="Normal DocDefaults " style="margin-bottom: 0in;"><span class="DefaultParagraphFont " style="font-weight: bold;font-size: 14.0pt;text-decoration: underline;">
<center><img height="355" width="620" src="C:\Oracle\Middleware\Weblogic12.1.3\user_projects\domains\springtutorial\servers\ManagedServer\tmp\_WL_user\FMS\ti01mv\public\Hydrangeas.jpg" alt="C:/Users/Public/Pictures/Sample Pictures/Hydrangeas.jpg"></img><p style="text-align:center">Image-2</p>
</center>I
</span></p>
<p class="cont-heading">CITIZENS HIGH SCHOOL</p>
<ol>
<li><strong>ACTIVITIES CONDUCTED IN THIS SCHOOL. PLEASE MENTION THE TYPE OF SESSIONS CONDUCTED, ANY SPECIFIC POINT YOU WOULD LIKE TO BRING
TO OUR NOTICE REGARDING THE SCHOOL. ACTIVITIES CONDUCTED IN THIS SCHOOL. PLEASE MENTION THE TYPE OF SESSIONS CONDUCTED, ANY
SPECIFIC POINT YOU WOULD LIKE TO BRING TO OUR NOTICE REGARDING THE SCHOOL. ACTIVITIES CONDUCTED IN THIS SCHOOL. PLEASE MENTION
THE TYPE OF SESSIONS CONDUCTED, ANY SPECIFIC POINT YOU WOULD LIKE TO BRING TO OUR NOTICE REGARDING THE SCHOOL. ACTIVITIES
CONDUCTED IN THIS SCHOOL. PLEASE MENTION THE TYPE OF SESSIONS CONDUCTED, ANY SPECIFIC POINT YOU WOULD LIKE TO BRING TO OUR
NOTICE REGARDING THE SCHOOL.</strong><br></br>w1
</li>
<li><strong>ANY SPECIFIC ACTIVITY WORTH MENTIONING BY THE STUDENTS(ATTACH IMAGES TO SEPARATE LINK). ANY SPECIFIC ACTIVITY WORTH MENTIONING
BY THE STUDENTS(ATTACH IMAGES TO SEPARATE LINK). ANY SPECIFIC ACTIVITY WORTH MENTIONING BY THE STUDENTS(ATTACH IMAGES TO SEPARATE
LINK). ANY SPECIFIC ACTIVITY WORTH MENTIONING BY THE STUDENTS(ATTACH IMAGES TO SEPARATE LINK).</strong><br></br>w2
</li>
<li><strong>AT LEAST ONE TESTIMONIAL FROM ONE SCHOOL. AT LEAST ONE TESTIMONIAL FROM ONE SCHOOL. AT LEAST ONE TESTIMONIAL FROM ONE SCHOOL.
AT LEAST ONE TESTIMONIAL FROM ONE SCHOOL.</strong><br></br>w3
</li>
<li><strong>WHAT WENT RIGHT; WHAT DID NOT GO RIGHT & REASONS FOR THE SAME. WHAT WENT RIGHT; WHAT DID NOT GO RIGHT & REASONS FOR THE SAME.
WHAT WENT RIGHT; WHAT DID NOT GO RIGHT & REASONS FOR THE SAME. WHAT WENT RIGHT; WHAT DID NOT GO RIGHT & REASONS FOR THE SAME.</strong><br></br>w4
</li>
<li><strong>DETAILS OF INTERACTION WITH THE PRINCIPAL AND/OR THE POC. DETAILS OF INTERACTION WITH THE PRINCIPAL AND/OR THE POC. DETAILS
OF INTERACTION WITH THE PRINCIPAL AND/OR THE POC. DETAILS OF INTERACTION WITH THE PRINCIPAL AND/OR THE POC.</strong><br></br>w5
</li>
</ol>
<p class="cont-heading">Photos</p>
<p class="cont-heading">CITIZENS HIGH SCHOOL</p>
<p class="Normal DocDefaults " style="margin-bottom: 0in;"><span class="DefaultParagraphFont " style="font-weight: bold;font-size: 14.0pt;text-decoration: underline;">
<center><img height="355" width="620" src="C:\Oracle\Middleware\Weblogic12.1.3\user_projects\domains\springtutorial\servers\ManagedServer\tmp\_WL_user\FMS\ti01mv\public\Hydrangeas.jpg" alt="C:/Users/Public/Pictures/Sample Pictures/Hydrangeas.jpg"></img><p style="text-align:center">Image-1</p>
</center>I
</span></p>
<p class="cont-heading">CITIZENS HIGH SCHOOL</p>
<p class="Normal DocDefaults " style="margin-bottom: 0in;"><span class="DefaultParagraphFont " style="font-weight: bold;font-size: 14.0pt;text-decoration: underline;">
<center><img height="355" width="620" src="C:\Oracle\Middleware\Weblogic12.1.3\user_projects\domains\springtutorial\servers\ManagedServer\tmp\_WL_user\FMS\ti01mv\public\Hydrangeas.jpg" alt="C:/Users/Public/Pictures/Sample Pictures/Hydrangeas.jpg"></img><p style="text-align:center">Image-2</p>
</center>I
</span></p>
</p>
</div>
</td>
</tr>
</table>
</body>
</html>
метод AlternativeFormatInputPart
private static void documentGenerator(String html, File file) throws Docx4JException, JAXBException {
//Word Processing Package
WordprocessingMLPackage wordMLPackage = getWordMLPackage();
NumberingDefinitionsPart ndp = new NumberingDefinitionsPart();
wordMLPackage.getMainDocumentPart().addTargetPart(ndp);
ndp.unmarshalDefaultNumbering();
AlternativeFormatInputPart inputPart = new AlternativeFormatInputPart(AltChunkType.Xhtml);
inputPart.setContentType(new ContentType("text/html"));
inputPart.setBinaryData(html.getBytes());
Relationship altChunkRel = wordMLPackage.getMainDocumentPart().addTargetPart(inputPart);
// .. the bit in document body
CTAltChunk ac = Context.getWmlObjectFactory().createCTAltChunk();
ac.setId(altChunkRel.getId());
wordMLPackage.getMainDocumentPart().addObject(ac);
// .. content type
wordMLPackage.getContentTypeManager().addDefaultContentType("html", "text/html");
//Saving the Document
wordMLPackage.save(file);
}
XHtmlImporter
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
NumberingDefinitionsPart ndp = new NumberingDefinitionsPart();
wordMLPackage.getMainDocumentPart().addTargetPart(ndp);
ndp.unmarshalDefaultNumbering();
// Convert the XHTML, and add it into the empty docx we made
XHTMLImporterImpl XHTMLImporter = new XHTMLImporterImpl(wordMLPackage);
XHTMLImporter.setRunFormatting(FormattingOption.CLASS_PLUS_OTHER);
XHTMLImporter.setHyperlinkStyle("Hyperlink");
wordMLPackage.getMainDocumentPart().getContent().addAll(XHTMLImporter.convert(unescaped, null));
wordMLPackage.save(new java.io.File("C:/OUT_from_XHTML.docx"));