pdf及word右上角添加图片(Java实现)

以下代码,如有问题,请大家不吝指出,如有更优实现方案,欢迎一起讨论。

最近在做一个需求:在pdf和word右上角添加一个二维码

其中,pdf可以灵活实现二维码的位置,但是word由于我是在页眉处添加的图片,因此我的方法只能在页眉处添加图片。

首先定义一个接口(先抛出Exception,还没优化)

public interface DocAddQRCodeI {

    int QRCodeLength = 70;

    void addQRCode(String beforePath, String afterPath, String imagePath) throws Exception;
}

1.pdf

Maven中添加如下依赖:

 <dependency>
	<groupId>com.lowagie</groupId>
	<artifactId>itext</artifactId>
	<version>2.1.7</version>
</dependency>
import com.lowagie.text.Image;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;

import java.io.FileOutputStream;


public class PdfAddQRCode implements DocAddQRCodeI {

    private static final int 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值