String htmlFile) {
try {
File htmlfile = new File (htmlFile);
InputStream htmlFileStream = new FileInputStream (htmlfile);
BaseFont bfCN = BaseFont.createFont ("STSongStd-Light", "UniGB-UCS2-H", false);
/ / Chinese font definitions
Font chFont = new Font (bfCN, 12, Font.NORMAL, BaseColor.BLUE);
Font secFont = new Font (bfCN, 12, Font.NORMAL, new BaseColor (0, 204,
255));
Document document = new Document ();
PdfWriter pdfwriter = PdfWriter.getInstance (document,
new FileOutputStream (pdfFile));
pdfwriter.setViewerPreferences (PdfWriter.HideToolbar);
document.open ();
/ / html file
InputStreamReader isr = new InputStreamReader (htmlFileStream, "UTF-8");
/ / default parameter conversion
XMLWorkerHelper.getInstance (). parseXHtml (pdfwriter, document, isr);
document.close ();
} catch (Exception e) {
e.printStackTrace ();
}
}
com.itextpdf.tool.xml.exceptions.RuntimeWorkerException: Invalid nested tag head found, expected closing tag link.
at com.itextpdf.tool.xml.XMLWorker.endElement (XMLWorker.java: 134)
at com.itextpdf.tool.xml.parser.XMLParser.endElement (XMLParser.java: 393)
at com.itextpdf.tool.xml.parser.state.ClosingTagState.process (ClosingTagState.java: 70)
at com.itextpdf.tool.xml.parser.XMLParser.parseWithReader (XMLParser.java: 235)
at com.itextpdf.tool.xml.parser.XMLParser.parse (XMLParser.java: 213)
at com.itextpdf.tool.xml.XMLWorkerHelper.parseXHtml (XMLWorkerHelper.java: 168)
at com.hoosen.webquery.action.WordToHtml.parseHTML2PDFFile (WordToHtml.java: 128)
at com.hoosen.webquery.action.WordToHtml.main (WordToHtml.java: 156)
------ Solution ---------------- ----------------------------
should be your html does not regulate it, there is no closed tabs !
------ Solution ---------------------------------------- ----
with demand answers. . . . . .
------ For reference this is my only ---------------------------------------
convert the word html method ( refer to someone else's )
public boolean changeFormat (String FileName) {
String FileFormat = "";
FileFormat = FileName.substring (FileName.length () -4, FileName.length ());
System.out.println (FileFormat);
if (FileFormat.equalsIgnoreCase (". doc")) {
String DocFile = FileName;
System.out.println ("word file path :" + DocFile);
/ / word file's full path
String HtmlFile = DocFile.substring (0, (DocFile.length () ; - 4)) + ". htm";
System.out.println ("htm file path :" + HtmlFile);
/ / html file's full path
ActiveXComponent app = new ActiveXComponent ("Word.Application");
/ / start word
try
{
app.setProperty ("Visible", new Variant (false));
/ / set non-visual word program operation
Dispatch docs = app.getProperty ("Documents" ;). toDispatch ();
Dispatch doc = Dispatch.invoke (docs, " ; Open ", Dispatch.Method, new Object [] {DocFile, new Variant (false), new Variant (true)}, new int [1]). toDispatch () ;
/ / open the word document
Dispatch.invoke (doc, "SaveAs", Dispatch.Method , new Object [] {HtmlFile, new Variant (8)}, new int [1]);
/ / Save the file as htm format
Dispatch.call (doc, "Close", new ; Variant (false));
/ / close the file
}
catch (Exception e) {
e.printStackTrace ();
}
finally {
app.invoke ("Quit", new Variant [ ] { } ) ;
/ / exit word program
}
/ / conversion is completed
return true;
}
return false;
}
------ For reference only ------------------------- --------------
this issue is resolved , the reason is : itext html to pdf format more stringent requirements on the html , html pages can be added to this
------ For reference only ---------------------------------------
this plus where is it ?
没有评论:
发表评论