大家好,又见面了,我是你们的朋友全栈君。
itextpdf 二维码
***************
相关类与接口
BarcodeQRCode
public class BarcodeQRCode extends Barcode2D {
ByteMatrix bm;
Map<EncodeHintType, Object> hints;
String code;
********
构造方法
public BarcodeQRCode(String code, Map<EncodeHintType, Object> hints) {
public BarcodeQRCode(String content) {
public BarcodeQRCode() {
********
其他方法
public void setCode(String code) {
public void setHints(Map<EncodeHintType, Object> hints) {
public void regenerate() {
public String getCode() {
public Rectangle getBarcodeSize() {
public Map<EncodeHintType, Object> getHints() {
public Rectangle getBarcodeSize(float moduleSize) {
public Rectangle placeBarcode(PdfCanvas canvas, Color foreground) {
public Rectangle placeBarcode(PdfCanvas canvas, Color foreground, float moduleSide) {
public PdfFormXObject createFormXObject(Color foreground, PdfDocument document) {
public PdfFormXObject createFormXObject(Color foreground, float moduleSize, PdfDocument document) {
public Image createAwtImage(java.awt.Color foreground, java.awt.Color background) {
private byte[] getBitMatrix() {
***************
示例
public class Test4 {
private static final String dest = "./qrcode/1.pdf";
private static final String dest2 = "./qrcode/2.pdf";
public static void fun() throws Exception{ //image生成二维码,可调整二维码宽度、高度,扫描二维码会跳转到百度首页
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(dest));
Document document = new Document(pdfDocument);
BarcodeQRCode barcodeQRCode = new BarcodeQRCode();
barcodeQRCode.setCode("http://www.baidu.com");
Image image = new Image(barcodeQRCode.createFormXObject(pdfDocument));
image.setWidth(200);
image.setHeight(200);
image.setFixedPosition(100,600);
document.add(image);
document.close();
}
public static void fun2() throws Exception{ //canvas绘制二维码,扫描二维码会跳转到百度首页
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(dest2));
BarcodeQRCode barcodeQRCode = new BarcodeQRCode();
barcodeQRCode.setCode("http://www.baidu.com");
PdfFormXObject object = barcodeQRCode.createFormXObject(ColorConstants.BLACK,pdfDocument);
float x = 100;
float y = 750;
float width = object.getWidth();
float height = object.getHeight();
PdfCanvas canvas = new PdfCanvas(pdfDocument.addNewPage());
canvas.saveState();
canvas.setFillColor(ColorConstants.WHITE);
canvas.rectangle(x, y, width, height);
canvas.fill();
canvas.restoreState();
canvas.addXObjectAt(object, x, y);
pdfDocument.close();
}
public static void main(String[] args) throws Exception{
fun();
fun2();
}
}
image生成二维码
canas绘制二维码
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/148869.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...