簡體   English   中英

Android Docx4j圖片錯誤

[英]Android Docx4j Image error

我嘗試創建一個Word文檔並用數據庫填充它。 我正在使用Docx4j。 在Android上。 沒有圖片,代碼運行良好,但帶有圖片則崩潰。

這是它崩潰的地方:

private static void addImageToPackage(Tc tableCell,
                                      byte[] bytes) throws Exception {
    BinaryPartAbstractImage imagePart =
            BinaryPartAbstractImage.createImagePart(wordMLPackage, bytes);

    int docPrId = 1;
    int cNvPrId = 2;
    Inline inline = imagePart.createImageInline("Filename hint",
            "Alternative text", docPrId, cNvPrId, 500000, 500000, false);

    P paragraph = addInlineImageToParagraph(inline);
    PPr paragraphProperties = factory.createPPr();
    Jc justification = factory.createJc();
    justification.setVal(JcEnumeration.RIGHT);
    paragraphProperties.setJc(justification);
    paragraph.setPPr(paragraphProperties);
    tableCell.getContent().add(paragraph);
}

更新:代碼沒有任何錯誤。 我的問題是Docx4j-Libraries出了問題,而Android Studio的BinaryPartAbstractImage.java出了些問題。 AgustinSivoplás的回答對我有所幫助。

罐子似乎有問題。 我過去曾與docx4j和android進行過激烈的斗爭。

這是帶有jar的libs文件夾。 為我工作。

https://drive.google.com/file/d/1eKnci5RtL9x7D_OSSkWMkOEAEMvhLN-t/view?usp=sharing

嘗試更改docx4j的版本。 它為我工作。

暫無
暫無

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

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