识别PDF中二维码
实现步骤:
1.使用icepdf把pdf转化为图片
2.使用google的zxing识别图片中的二维码
包引用
// https://central.sonatype.com/artifact/com.google.zxing/core
implementation 'com.google.zxing:core:3.5.3'
// https://central.sonatype.com/artifact/com.google.zxing/javase
implementation 'com.google.zxing:javase:3.5.3'
// https://central.sonatype.com/artifact/org.icepdf.os/icepdf-core
implementation('org.icepdf.os:icepdf-core:6.2.2') {
exclude group: 'javax.media', module: 'jai_core'
}
代码部分,一个类几个方法就实现了,还是比较简单
import com.google.zxing.BinaryBitmap;
import com.google.zxing.DecodeHintType;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.Result;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer;
import org.icepdf.core.pobjects.Document;
import org.icepdf.core.util.GraphicsRenderingHints;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
public class Test {
//缩放比例

本文介绍了如何使用IcePDF库将PDF转换为图片,然后利用Google的ZXing库识别图片中的二维码,提供了Java代码示例,包括PDF转图片、二维码识别以及文件操作的相关函数。
887

被折叠的 条评论
为什么被折叠?



