1

.doc ファイルから単語のメタデータを削除したいと考えています。私の.docxファイルは で正常に動作しますXWPFDocumentが、メタデータを削除する次のコードは、大きな (> 1MB) ファイルでは失敗します。たとえば、画像を含む 6MB の .doc ファイルを使用すると、一部の画像が削除された 4.5MB のファイルが出力されます。

public static InputStream removeMetaData(InputStream inputStream) throws IOException {
    POIFSFileSystem fss = new POIFSFileSystem(inputStream);
    HWPFDocument doc = new HWPFDocument(fss);

    // **it even fails on large files if you remove from here to 'until' below**
    SummaryInformation si = doc.getSummaryInformation();
    si.removeAuthor();
    si.removeComments();
    si.removeLastAuthor();
    si.removeKeywords();
    si.removeSubject();
    si.removeTitle();

    doc.getDocumentSummaryInformation().removeCategory();
    doc.getDocumentSummaryInformation().removeCompany();
    doc.getDocumentSummaryInformation().removeManager();
    try {
        doc.getDocumentSummaryInformation().removeCustomProperties();
    } catch (Exception e) {
        // can not remove above
    }
    // until

    ByteArrayOutputStream os = new ByteArrayOutputStream();
    doc.write(os);
    os.flush();
    os.close();
    return new ByteArrayInputStream(os.toByteArray());
}

関連記事:

4

1 に答える 1

1

どのバージョンの Apache POI を使用していますか?

これはBug 46220 - Regression: Some embedded images being lostのようです。

POI (3.8)の最新リリースにアップグレードして、もう一度お試しください。

それが役立つことを願っています。

于 2012-11-13T10:47:49.640 に答える