欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

itextpdf 二维码

发布时间:2023/12/14 37 豆豆
生活随笔 收集整理的这篇文章主要介绍了 itextpdf 二维码 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

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绘制二维码

                

           

                  

总结

以上是生活随笔为你收集整理的itextpdf 二维码的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。