使用Java怎么在PDF中添加條形碼

這篇文章將為大家詳細講解有關使用Java怎么在PDF中添加條形碼,文章內容質量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。

專業(yè)領域包括做網站、成都網站制作、商城網站建設、微信營銷、系統(tǒng)平臺開發(fā), 與其他網站設計及系統(tǒng)開發(fā)公司不同,成都創(chuàng)新互聯(lián)公司的整合解決方案結合了幫做網絡品牌建設經驗和互聯(lián)網整合營銷的理念,并將策略和執(zhí)行緊密結合,為客戶提供全網互聯(lián)網整合方案。

方法1:通過E-iceblue中文官網 下載獲取jar包。解壓后將lib文件夾下的Spire.Pdf.jar文件導入Java程序。(如下圖)

使用Java怎么在PDF中添加條形碼

方法2:通過maven倉庫安裝導入。具體安裝教程參見 此網頁 。

代碼示例:

import com.spire.pdf.PdfDocument;
import com.spire.pdf.PdfPageBase;
import com.spire.pdf.barcode.*;
import com.spire.pdf.graphics.*;
import static com.spire.pdf.graphics.PdfFontStyle.Bold;
import java.awt.*;
import java.awt.geom.Point2D;
import java.util.EnumSet;

public class DrawBarcode {
  public static void main(String[] args) {
    //創(chuàng)建PdfDocument對象
    PdfDocument doc = new PdfDocument();

    //添加一頁
    PdfPageBase page = doc.getPages().add();

    //初始化y變量
    double y = 15;

    //創(chuàng)建字體
    PdfFont font= new PdfFont(PdfFontFamily.Helvetica, 12, EnumSet.of(Bold));

    // 繪制文本“Codebar:”到PDF
    PdfTextWidget text = new PdfTextWidget();
    text.setFont(font);
    text.setText("Codebar:");
    PdfLayoutResult result = text.draw(page, 0, y);
    y =(float)(result.getBounds().getY()+ result.getBounds().getHeight() + 2);

    //繪制Codebar條碼到PDF
    PdfCodabarBarcode codebar= new PdfCodabarBarcode("00:12-3456/7890");
    codebar.setBarcodeToTextGapHeight(1f);
    codebar.setBarHeight(50f);
    codebar.setEnableCheckDigit(true);
    codebar.setShowCheckDigit(true);
    codebar.setTextDisplayLocation(TextLocation.Bottom);
    PdfRGBColor blue = new PdfRGBColor(Color.blue);
    codebar.setTextColor(blue);
    Point2D.Float point = new Point2D.Float();
    point.setLocation(0,y);
    codebar.draw(page,point);
    y = codebar.getBounds().getY()+ codebar.getBounds().getHeight() + 5;

    //繪制文本“Code128-A:”到PDF
    text.setText("Code128-A:");
    result = text.draw(page, 0, y);
    page = result.getPage();
    y =result.getBounds().getY()+ result.getBounds().getHeight() + 2;

    //繪制Code128A條碼到PDF
    PdfCode128ABarcode code128 = new PdfCode128ABarcode("HELLO 00-123");
    code128.setBarcodeToTextGapHeight(1f);
    code128.setBarHeight(50f);
    code128.setTextDisplayLocation(TextLocation.Bottom);
    code128.setTextColor(blue);
    point.setLocation(point.x,y);
    code128.draw(page, point);
    y =code128.getBounds().getY()+ code128.getBounds().getHeight() + 5;

    //繪制文本“Code39”到PDF
    text.setText("Code39:");
    result = text.draw(page, 0, y);
    page = result.getPage();
    y =result.getBounds().getY()+ result.getBounds().getHeight() + 2;

    //繪制Code39條形碼到PDF
    PdfCode39Barcode code39 = new PdfCode39Barcode("16-273849");
    code39.setBarcodeToTextGapHeight(1f);
    code39.setBarHeight(50f);
    code39.setTextDisplayLocation(TextLocation.Bottom);
    code39.setTextColor(blue);
    point.setLocation(point.x,y);
    code39.draw(page, point);

    //保存PDF文檔
    doc.saveToFile("output/DrawBarcode.pdf");
  }
}

常用的java框架有哪些

1.SpringMVC,Spring Web MVC是一種基于Java的實現(xiàn)了Web MVC設計模式的請求驅動類型的輕量級Web框架。2.Shiro,Apache Shiro是Java的一個安全框架。3.Mybatis,MyBatis 是支持普通 SQL查詢,存儲過程和高級映射的優(yōu)秀持久層框架。4.Dubbo,Dubbo是一個分布式服務框架。5.Maven,Maven是個項目管理和構建自動化工具。6.RabbitMQ,RabbitMQ是用Erlang實現(xiàn)的一個高并發(fā)高可靠AMQP消息隊列服務器。7.Ehcache,EhCache 是一個純Java的進程內緩存框架。

關于使用Java怎么在PDF中添加條形碼就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

網頁名稱:使用Java怎么在PDF中添加條形碼
當前URL:http://muchs.cn/article46/pdppeg.html

成都網站建設公司_創(chuàng)新互聯(lián),為您提供網頁設計公司、網站收錄、網站營銷定制網站、網站制作、電子商務

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

成都網站建設