itextpdf 二维码[通俗易懂]

itextpdf 二维码[通俗易懂]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生成二维码

                 itextpdf 二维码[通俗易懂]

               

canas绘制二维码

                 itextpdf 二维码[通俗易懂]

           

                  

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/148869.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号