您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)使用Java怎么在PDF中添加條形碼,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。
方法1:通過E-iceblue中文官網(wǎng) 下載獲取jar包。解壓后將lib文件夾下的Spire.Pdf.jar文件導(dǎo)入Java程序。(如下圖)
方法2:通過maven倉庫安裝導(dǎo)入。具體安裝教程參見 此網(wǎng)頁 。
代碼示例:
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對(duì)象 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"); } }
1.SpringMVC,Spring Web MVC是一種基于Java的實(shí)現(xiàn)了Web MVC設(shè)計(jì)模式的請(qǐng)求驅(qū)動(dòng)類型的輕量級(jí)Web框架。2.Shiro,Apache Shiro是Java的一個(gè)安全框架。3.Mybatis,MyBatis 是支持普通 SQL查詢,存儲(chǔ)過程和高級(jí)映射的優(yōu)秀持久層框架。4.Dubbo,Dubbo是一個(gè)分布式服務(wù)框架。5.Maven,Maven是個(gè)項(xiàng)目管理和構(gòu)建自動(dòng)化工具。6.RabbitMQ,RabbitMQ是用Erlang實(shí)現(xiàn)的一個(gè)高并發(fā)高可靠AMQP消息隊(duì)列服務(wù)器。7.Ehcache,EhCache 是一個(gè)純Java的進(jìn)程內(nèi)緩存框架。
關(guān)于使用Java怎么在PDF中添加條形碼就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。