簡體   English   中英

如何使用WordToHtmlConverter和HWPFDocument限制頁面輸出?

[英]How can I limit the pages output with WordToHtmlConverter and HWPFDocument?

我正在將Word / .doc文件轉換為HTML,我希望能夠獲得部分頁面。 是否可以限制輸出范圍? 我願意只使用頁面的子集或在轉換后限制那里的長度而從原始文件創建新的HWPFDocument。

File localFile = ...
FileInputStream fis = new FileInputStream(localFile);
HWPFDocument wordDoc = new HWPFDocument(fis);
Document newDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(newDoc);
wordToHtmlConverter.processDocument(wordDoc);

StringWriter stringWriter = new StringWriter();

Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
transformer.setOutputProperty(OutputKeys.METHOD, "html");
transformer.transform(
    new DOMSource(wordToHtmlConverter.getDocument()),
                    new StreamResult(stringWriter));

String htmlString = stringWriter.toString();

BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
    new FileOutputStream(htmlFile), "UTF-8"));
out.write(htmlString);
out.close();

不適用於POI。 沒有HWPF格式的頁面的概念。 頁面是消費者的產物。 在使用者渲染頁面之前,沒有頁面,而且每個客戶端可以渲染頁面的方式略有不同,即使在不同版本的Word之間也是如此。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM