亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

Java 在PDF中添加條形碼的兩種方法

瀏覽:62日期:2022-09-03 16:49:03

條形碼,是由寬度不等的多個黑條和空白所組成,用以表達一組信息的圖形標識符。通過給文檔添加條形碼,可以直觀,快捷地訪問和分享一些重要的信息。本文就將通過使用Java程序來演示如何在PDF文檔中添加Codebar、Code128A和Code39條形碼。除此之外,還可支持創建Code11、Code128B、Code32、Code39 Extended 、Code93和Code93 Extended條形碼。

使用工具:Free Spire.PDF for Java (免費版)

Jar文件獲取及導入:

方法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) { //創建PdfDocument對象 PdfDocument doc = new PdfDocument(); //添加一頁 PdfPageBase page = doc.getPages().add(); //初始化y變量 double y = 15; //創建字體 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 在PDF中添加條形碼的兩種方法

總結

到此這篇關于Java 在PDF中添加條形碼的兩種方法的文章就介紹到這了,更多相關java pdf 條形碼內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Java
相關文章:
主站蜘蛛池模板: 可以免费观看一级毛片黄a 可以免费观看欧美一级毛片 | 香港毛片免费看 | 伊人中文在线 | 国产成人影院在线观看 | 欧美成人免费草草影院视频 | 欧美一级夜夜爽 | 成 年 人 黄 片 大全 | 久久99视频免费 | 成人欧美精品久久久久影院 | 2020国产成人免费视频 | 午夜激情视频在线播放 | 亚洲综合激情另类图片专区 | 99国产精品 | 性色a | 亚洲精品日韩在线一区 | 亚洲欧美二区三区久本道 | 好吊色综合网天天高清 | 狠狠色综合久久丁香婷婷 | 一级做a爱片特黄在线观看免费看 | 国产一级在线现免费观看 | 免费晚上看片www | 一级黄网站 | 亚洲一区在线免费观看 | 一级做a级爰片性色毛片视频 | 手机国产日韩高清免费看片 | 国产精品单位女同事在线 | 国产mm| 1级毛片| 极品欧美人体xxxx图片 | 国产一区二区三区丶四区 | 国产婷婷一区二区在线观看 | 亚洲精品午夜久久久伊人 | 另类国产精品一区二区 | 精品三级在线观看 | 国产精品新婚门 | 国产欧美在线观看精品一区二区 | 美女拍拍拍爽爽爽爽爽爽 | 国产精品黄网站免费观看 | 中国一级毛片欧美一级毛片 | 国产亚洲青色国产 | 色综合久久九月婷婷色综合 |