操作word文档在页脚插入图片

 

操作wod文档在页脚插入图片

 

public static void main(String[] args) {
        try {
            if (!getLicense()) {
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        String path = "D:\\charu1.docx";
        String imageFileName = "D:\\4fa94058-de6d-47c8-a8a0-77b07c739e98.png";
        try {
            Document doc = new Document(path);
            DocumentBuilder builder = new DocumentBuilder(doc);
            // Create footer for pages
            builder.moveToHeaderFooter(HeaderFooterType.FOOTER_PRIMARY);
            // Insert image
            builder.insertImage(imageFileName);
            // Align this text to the right.
            builder.getCurrentParagraph().getParagraphFormat().setAlignment(ParagraphAlignment.RIGHT);
            // Save the resulting document.
            doc.save(path);

//            for (Section section : doc.getSections()) {
//// Up to three different footers are possible in a section (for first, even and odd pages).
//// We check and delete all of them.
//                HeaderFooter footer;
//
//                footer = section.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.FOOTER_FIRST);
//                if (footer != null){
//                    footer.remove();
//                }
//
//// Primary footer is the footer used for odd pages.
//                footer = section.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.FOOTER_PRIMARY);
//                if (footer != null){
//                    footer.remove();
//                }
//                footer = section.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.FOOTER_EVEN);
//                if (footer != null){
//                    footer.remove();
//                }
//            }
            doc.save(path);

            }catch (Exception e) {

        }
    }

 

posted @ 2023-07-12 16:28  我是深水的猫  阅读(199)  评论(0)    收藏  举报