PIXNET Logo登入

程式開發學習之路

跳到主文

本站 程式開發教學學習交流,主要提高開發程式效率同時分享一些開發程式經驗。

深入探討開發程式體驗等技術和教學,相關技術等學習交流: 語言(Languages)及框架(Framework): Java、 JSP/Tag/JSTL/Servlet、 Grails、 jQuery、 JavaScript、 Spring、 SpringMVC、 SpringSecurity、 Hibernate、 Struts、 PHP、 C/C++、 GoogleAppEngine、 HTML5/CSS3、 Android、 Xml、 Ajax、 Json、 Ant、 UML、 ShellScripts、 AngularJS等。
工具(Software)/環境(Environment): Windows7、 Eclipse、 Linux、 Subversion、 maven、 Tomcat、 Weblogic、 Jboss、 Apache 等。
資料庫(Database): MySQL、 Oracle SQL、 PostgerSQL、 SQL Server 等。
本站內容僅供分享學習交流之用,將不對任何資源負法律責任。如有侵犯您的版權,請來信或留言給我們,我們將盡快為您處理。

部落格全站分類:職場甘苦

  • 相簿
  • 部落格
  • 留言
  • 名片
  • 2月 19 週三 201418:16
  • [JAVA]createTempFile產生暫存檔


使用createTempFile產生暫存檔
windows systems 預設檔案位置: C:\Users\USER\AppData\Local\Temp
UNIX systems 預設檔案位置 :"/tmp" or "/var/tmp" 
(繼續閱讀...)
文章標籤

PG Levin Li 發表在 痞客邦 留言(0) 人氣(844)

  • 個人分類:JAVA-程式分享
▲top
  • 7月 15 週日 201221:15
  • [JAVA_程式分享]利用itext來寫出BarCode


相信有很多的程式設計師大都會遇到產生BarCode條碼的問題,這邊就利用itext-5.2.0.jar來幫各位解答一下,程式碼很簡單,等等看到就知道嚕 import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.UnsupportedEncodingException;

import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Image;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.Barcode;
import com.itextpdf.text.pdf.Barcode128;
import com.itextpdf.text.pdf.Barcode39;
import com.itextpdf.text.pdf.BarcodeCodabar;
import com.itextpdf.text.pdf.BarcodeDatamatrix;
import com.itextpdf.text.pdf.BarcodeEAN;
import com.itextpdf.text.pdf.BarcodeEANSUPP;
import com.itextpdf.text.pdf.BarcodeInter25;
import com.itextpdf.text.pdf.BarcodePDF417;
import com.itextpdf.text.pdf.BarcodePostnet;
import com.itextpdf.text.pdf.BarcodeQRCode;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfWriter;


public class ItextBarCode {

public static void main(String[] args) throws FileNotFoundException,
DocumentException, UnsupportedEncodingException {

String fileName = "C:/Users/"+ System.getenv("COMPUTERNAME")+"/Desktop/barcodes.pdf";

Document document = new Document(new Rectangle(340, 842));

PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(fileName));

document.open();

PdfContentByte cb = writer.getDirectContent();

// EAN 13
document.add(new Paragraph("Barcode EAN.UCC-13"));
BarcodeEAN codeEAN = new BarcodeEAN();
codeEAN.setCode("4512345678906");
document.add(new Paragraph("default:"));
document.add(codeEAN.createImageWithBarcode(cb, null, null));
codeEAN.setGuardBars(false);
document.add(new Paragraph("without guard bars:"));
document.add(codeEAN.createImageWithBarcode(cb, null, null));
codeEAN.setBaseline(-1f);
codeEAN.setGuardBars(true);
document.add(new Paragraph("text above:"));
document.add(codeEAN.createImageWithBarcode(cb, null, null));
codeEAN.setBaseline(codeEAN.getSize());

// UPC A
document.add(new Paragraph("Barcode UCC-12 (UPC-A)"));
codeEAN.setCodeType(Barcode.UPCA);
codeEAN.setCode("785342304749");
document.add(codeEAN.createImageWithBarcode(cb, null, null));

// EAN 8
document.add(new Paragraph("Barcode EAN.UCC-8"));
codeEAN.setCodeType(Barcode.EAN8);
codeEAN.setBarHeight(codeEAN.getSize() * 1.5f);
codeEAN.setCode("34569870");
document.add(codeEAN.createImageWithBarcode(cb, null, null));

// UPC E
document.add(new Paragraph("Barcode UPC-E"));
codeEAN.setCodeType(Barcode.UPCE);
codeEAN.setCode("03456781");
document.add(codeEAN.createImageWithBarcode(cb, null, null));
codeEAN.setBarHeight(codeEAN.getSize() * 3f);

// EANSUPP
document.add(new Paragraph("Bookland"));
document.add(new Paragraph("ISBN 0-321-30474-8"));
codeEAN.setCodeType(Barcode.EAN13);
codeEAN.setCode("9781935182610");
BarcodeEAN codeSUPP = new BarcodeEAN();
codeSUPP.setCodeType(Barcode.SUPP5);
codeSUPP.setCode("55999");
codeSUPP.setBaseline(-2);
BarcodeEANSUPP eanSupp = new BarcodeEANSUPP(codeEAN, codeSUPP);
document.add(eanSupp.createImageWithBarcode(cb, null, BaseColor.BLUE));

// CODE 128
document.add(new Paragraph("Barcode 128"));
Barcode128 code128 = new Barcode128();
code128.setCode("0123456789 hello");
document.add(code128.createImageWithBarcode(cb, null, null));
code128.setCode("0123456789\uffffMy Raw Barcode (0 - 9)");
code128.setCodeType(Barcode.CODE128_RAW);
document.add(code128.createImageWithBarcode(cb, null, null));

// Data for the barcode :
String code402 = "24132399420058289";
String code90 = "3700000050";
String code421 = "422356";
StringBuffer data = new StringBuffer(code402);
data.append(Barcode128.FNC1);
data.append(code90);
data.append(Barcode128.FNC1);
data.append(code421);
Barcode128 shipBarCode = new Barcode128();
shipBarCode.setX(0.75f);
shipBarCode.setN(1.5f);
shipBarCode.setSize(10f);
shipBarCode.setTextAlignment(Element.ALIGN_CENTER);
shipBarCode.setBaseline(10f);
shipBarCode.setBarHeight(50f);
shipBarCode.setCode(data.toString());
document.add(shipBarCode.createImageWithBarcode(cb, BaseColor.BLACK,
BaseColor.BLUE));

// it is composed of 3 blocks whith AI 01, 3101 and 10
Barcode128 uccEan128 = new Barcode128();
uccEan128.setCodeType(Barcode.CODE128_UCC);
uccEan128.setCode("(01)00000090311314(10)ABC123(15)060916");
document.add(uccEan128.createImageWithBarcode(cb, BaseColor.BLUE,
BaseColor.BLACK));
uccEan128.setCode("0191234567890121310100035510ABC123");
document.add(uccEan128.createImageWithBarcode(cb, BaseColor.BLUE,
BaseColor.RED));
uccEan128.setCode("(01)28880123456788");
document.add(uccEan128.createImageWithBarcode(cb, BaseColor.BLUE,
BaseColor.BLACK));

// INTER25
document.add(new Paragraph("Barcode Interleaved 2 of 5"));
BarcodeInter25 code25 = new BarcodeInter25();
code25.setGenerateChecksum(true);
code25.setCode("41-1200076041-001");
document.add(code25.createImageWithBarcode(cb, null, null));
code25.setCode("411200076041001");
document.add(code25.createImageWithBarcode(cb, null, null));
code25.setCode("0611012345678");
code25.setChecksumText(true);
document.add(code25.createImageWithBarcode(cb, null, null));

// POSTNET
document.add(new Paragraph("Barcode Postnet"));
BarcodePostnet codePost = new BarcodePostnet();
document.add(new Paragraph("ZIP"));
codePost.setCode("01234");
document.add(codePost.createImageWithBarcode(cb, null, null));
document.add(new Paragraph("ZIP+4"));
codePost.setCode("012345678");
document.add(codePost.createImageWithBarcode(cb, null, null));
document.add(new Paragraph("ZIP+4 and dp"));
codePost.setCode("01234567890");
document.add(codePost.createImageWithBarcode(cb, null, null));

document.add(new Paragraph("Barcode Planet"));
BarcodePostnet codePlanet = new BarcodePostnet();
codePlanet.setCode("01234567890");
codePlanet.setCodeType(Barcode.PLANET);
document.add(codePlanet.createImageWithBarcode(cb, null, null));

// CODE 39
document.add(new Paragraph("Barcode 3 of 9"));
Barcode39 code39 = new Barcode39();
code39.setCode("ITEXT IN ACTION");
document.add(code39.createImageWithBarcode(cb, null, null));

document.add(new Paragraph("Barcode 3 of 9 extended"));
Barcode39 code39ext = new Barcode39();
code39ext.setCode("iText in Action");
code39ext.setStartStopText(false);
code39ext.setExtended(true);
document.add(code39ext.createImageWithBarcode(cb, null, null));

// CODABAR
document.add(new Paragraph("Codabar"));
BarcodeCodabar codabar = new BarcodeCodabar();
codabar.setCode("A123A");
codabar.setStartStopText(true);
document.add(codabar.createImageWithBarcode(cb, null, null));

// PDF417
document.add(new Paragraph("Barcode PDF417"));
BarcodePDF417 pdf417 = new BarcodePDF417();
String text = "Call me Ishmael. Some years ago--never mind how long "
+ "precisely --having little or no money in my purse, and nothing "
+ "particular to interest me on shore, I thought I would sail about "
+ "a little and see the watery part of the world.";
pdf417.setText(text);
Image img = pdf417.getImage();
img.scalePercent(50, 50 * pdf417.getYHeight());
document.add(img);

document.add(new Paragraph("Barcode Datamatrix"));
BarcodeDatamatrix datamatrix = new BarcodeDatamatrix();
datamatrix.generate(text);
img = datamatrix.createImage();
document.add(img);

document.add(new Paragraph("Barcode QRCode"));
BarcodeQRCode qrcode = new BarcodeQRCode("Moby Dick by Herman Melville", 1, 1, null);
img = qrcode.getImage();
document.add(img);

document.close();

}
}

(繼續閱讀...)
文章標籤

PG Levin Li 發表在 痞客邦 留言(0) 人氣(3,173)

  • 個人分類:JAVA-程式分享
▲top
  • 6月 28 週四 201221:04
  • [JAVA_程式分享]使用commons compress套件,使用壓縮檔zip、解壓縮unZip



package com.test;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.apache.commons.compress.utils.IOUtils;

/**
*
(繼續閱讀...)
文章標籤

PG Levin Li 發表在 痞客邦 留言(0) 人氣(389)

  • 個人分類:JAVA-程式分享
▲top
  • 12月 28 週三 201111:00
  • [JAVA]程式分享--多人聊天室簡單版

[JAVA]程式分享--多人聊天室
此程式為SERVER端//--------------------------------------------------------------//
// MyServer.java 2011年04月15日
//--------------------------------------------------------------//
import java.io.*;
import java.net.*;
import java.util.*;
//--------------------------------------------------------------//
//程式流程
//---MyServer --主類別檔
//-1-main --主程式進入點
//-2-go() --方法 --建位連線 --等待請求連線
// --取得連線後往下執行
//-3-Process --內部類別 --處理程序
//-3.1-Process --建構子 --由執行緒呼叫 --建立接收
//-3.2-run() --方法 --執行執行緒
//-3.3-tellApiece() --方法 --告訴每人
//--------------------------------------------------------------//
//MyServer主類別檔
//--------------------------------------------------------------//
public class MyServer{

Vector output;//output
//--------------------------------------------------------------//
//-1-主程式進入點
//--------------------------------------------------------------//
public static void main (String args[]){
new MyServer().go();
}
//--------------------------------------------------------------//
//-2-建位連線
//--------------------------------------------------------------//
public void go() {
//建立物件陣列
output = new Vector();
try{
//產生ServerSocket設定port:5000
ServerSocket serverSock = new ServerSocket(8888);
while(true){
//等待連線的請求--串流
Socket cSocket = serverSock.accept();
//建立I/O管道
PrintStream writer =
//取得Socket的輸出資料流
new PrintStream(cSocket.getOutputStream());
System.out.println(writer);
//元件加入Vector
output.add(writer);
//傳入一個Runnable物件並分派一個新的執行緒
//建立伺服器主執行緒
Thread t = new Thread(new Process(cSocket));
//啟動執行緒
t.start();
//取得連線的ip
System.out.println(cSocket.getLocalSocketAddress()+
//執行緒的在線次數
"有"+(t.activeCount()-1)+
//顯示連線人次
"個連接");
}
}catch(Exception ex){System.out.println("連接失敗");}
}
//--------------------------------------------------------------//
//-3-Process處理程序
//--------------------------------------------------------------//
public class Process implements Runnable{
//暫存資料的Buffered
BufferedReader reader;
//建立一個Socket變數
Socket sock;
//----------------------------------------------------------//
//-3.1-由執行緒呼叫---建立接收
//----------------------------------------------------------//
public Process(Socket cSocket)
{
try{
sock = cSocket;
//取得Socket的輸入資料流
InputStreamReader isReader =
new InputStreamReader(sock.getInputStream());

reader = new BufferedReader(isReader);
}catch(Exception ex){
System.out.println("連接失敗Process");
}
}
//--------------------------------------------------------------//
//-3.2-執行執行緒
//--------------------------------------------------------------//
public void run(){
String message;
try{
//讀取資料
while ((message = reader.readLine())!=null){
System.out.println("收到"+message);
tellApiece(message);
}
}catch(Exception ex){System.out.println("有一個連接離開");}
}
//--------------------------------------------------------------//
//-3.3-告訴每人
//--------------------------------------------------------------//
public void tellApiece(String message){
//產生iterator可以存取集合內的元素資料
Iterator it = output.iterator();
//向下讀取元件
while(it.hasNext()){
try{
//取集合內資料
PrintStream writer = (PrintStream) it.next();
//印出
writer.println(message);
//刷新該串流的緩衝。
writer.flush();
}
catch(Exception ex){
System.out.println("連接失敗Process");
}
}
}
}
}

(繼續閱讀...)
文章標籤

PG Levin Li 發表在 痞客邦 留言(0) 人氣(2,868)

  • 個人分類:JAVA-程式分享
▲top
1

廣告

B 組廣告版面

個人資訊

PG Levin Li
暱稱:
PG Levin Li
分類:
職場甘苦
好友:
累積中
地區:

熱門文章

  • (37,225)Oracle SQL DECODE用法教學
  • (14,872)Oracle SQL INSERT INTO TABLE 基本用法
  • (10,464)Oracle SQL MOD 取餘數
  • (8,966)Oracle SQL to_date的用法
  • (6,026)Oracle SQL full outer join 用法教學
  • (5,110)Oracle SQL AVG GROUP BY 用法教學
  • (4,502)Oracle SQL TRUNC無條件捨去
  • (4,002)Oracle SQL minus 用法教學
  • (677)Oracle SQL next_day用法教學
  • (255)Oracle SQL nonequal join 不對等join

文章分類

toggle ZK (1)
  • ZK (2)
toggle SQLite (2)
  • SQLite for Java (11)
  • SQLite (2)
toggle Java (19)
  • Servlet (4)
  • JAVA-綀習分享 (3)
  • JAVA 7 (1)
  • JAVA-流程控制類 (10)
  • JAVA_IDE (2)
  • JAVA_其它_itext套件 (1)
  • JAVA-WEB (1)
  • JAVA-lang套件 (16)
  • java mail (1)
  • JAVA-OCJP (1)
  • JAVA-問題 (2)
  • JAVA_IO (1)
  • JAVA-OCWCD (7)
  • Joda Time (1)
  • JAVA-程式分享 (4)
  • JAVA.util套件 (6)
  • JAVA-基本類 (19)
  • JAVA (4)
  • JAVA其它 (1)
toggle Android (4)
  • Android NDK (3)
  • Android Studio (7)
  • Android基本類 (2)
  • Android (7)
toggle SSH (12)
  • Struts 2 (1)
  • Spring Mobile (3)
  • Hibernate-基本類 (3)
  • Spring MVC (3)
  • grails-其它類 (1)
  • Spring i18n (2)
  • grails-基本類 (13)
  • Spring Batch (2)
  • SpringHibernate (5)
  • Spring-基本類 (4)
  • Spring (3)
  • Spring AOP (2)
toggle Oracle (10)
  • Oracle join (14)
  • sqldeveloper (9)
  • Oracle_VirtualBox (1)
  • Oracle DDL (4)
  • Oracle Date (17)
  • Oracle (5)
  • Oracle Sub Query (17)
  • Oracle GROUP BY (20)
  • Oracle SQL (49)
  • Oracle DB (16)
toggle SQL Server/MSSQL (1)
  • SQL Server (1)
toggle MySQL (8)
  • MySQL (7)
  • MySQL-語法快速查詢 (2)
  • MySQL-基本系列教學 (10)
  • MySQL-其它類 (1)
  • MySQL-進階系列教學 (15)
  • MySQL-DATE相關 (8)
  • MySQL-函式相關 (11)
  • MySQL DB Toad (9)
toggle PostgreSQL (1)
  • PostgreSQL (5)
toggle Tool (11)
  • TortoiseSVN (1)
  • Subversive (1)
  • Dev-C++ (4)
  • Squid (3)
  • UML (1)
  • Eclipse IDE for C/C++ (3)
  • Tool (1)
  • eclipse (13)
  • Jboss (1)
  • JBoss-問題 (2)
  • SWT (1)
toggle C/C++ (5)
  • c語言綀習題 (2)
  • c/c++ (2)
  • c (4)
  • c++ (2)
  • MinGw (6)
toggle Apache (9)
  • Apache_Tomcat (3)
  • Apache_JMeter (1)
  • Apache套件_BeanUtils (1)
  • Apache套件_StringUtils (1)
  • Apache套件_POI (5)
  • maven (3)
  • Apache (2)
  • apache_Maven (2)
  • Tomcat 8 (2)
toggle jQuery (8)
  • jQuery UI (1)
  • jQuery Datepicker (26)
  • jQuery-事件處理 (2)
  • jQuery-套件類 (3)
  • jQuery-基本類 (3)
  • jQuery-進階 (1)
  • jQuery Mobile (2)
  • jQuery-Selector (11)
toggle JavaScript (8)
  • JavaScript-基本類 (20)
  • JavaScript (14)
  • JavaScript-Date物件 (5)
  • JavaScript-其它類 (3)
  • JavaScript-陣列類 (7)
  • JavaScript HTML DOM (37)
  • JavaScript-String類 (8)
  • JavaScript-數學類 (6)
toggle Web/HTML/CSS/JS/JQ (6)
  • css-基本類 (18)
  • CSS (4)
  • CSS2 (2)
  • CSS3 (1)
  • CSS Selector (42)
  • HTML5 (3)
toggle 其它 (6)
  • 生活其它 (3)
  • PHP (11)
  • 其它類 (3)
  • 基本資訊 (3)
  • 開發資訊 (1)
  • 圖片工具 (1)
toggle Win/OS/linux (4)
  • Linux_其它 (1)
  • Linux (14)
  • Windows (3)
  • WIN7-基本類 (14)
toggle 生活點點 (1)
  • 生活新聞 (29)
  • 未分類文章 (1)

最新文章

  • 生機生技引進營養製劑 產品廣獲好評
  • 【芋頭鮮奶盲測】超狂給料像拌水泥 強者迷客夏輸了
  • 口碑行銷、網紅行銷當道 品牌企業合作首選 達摩媒體BloggerAds
  • 想知道最夯時事分析?邀請你加入BloggerAds市場調查!
  • 日本FSK隔熱紙-居家隔熱、防曬、節能好幫手
  • AROFLY開箱實測、從退貨評價到獲取消費者認同!
  • 五個健康理由讓您考慮吃「有機食品」
  • 美食推薦 新北泰山 霸王櫻桃鴨 聚餐聊天好去處
  • 一心好文,農藥最後會流到這裡
  • 360°康健指數打破生活迷思,掌握美好生活的妙招

最新留言

  • [14/04/11] 匿名 於文章「[Android]Android系統調用...」留言:
    多謝分享,對我有幫助。...
  • [14/02/24] Levin Li 於文章「[JAVA]String-取出字串某個位...」留言:
    使用 subSequence(起始位置,結束位置); Str...
  • [14/02/22] JHANG allen 於文章「[JAVA]String-取出字串某個位...」留言:
    如果我有一串數字1234567890abcdefghihk ...
  • [13/08/19] 洪甫 於文章「[JAVA]OCJP(SCJP)免費的考...」留言:
    太感謝了 我終於看到中文版了!!...
  • [13/06/23] Levin Li 於文章「[Apache_Tomcat] Tomc...」留言:
    (^^) 我不懂你說的「不會過」,是何事 不會過????...
  • [13/06/22] 丁丁 於文章「[Apache_Tomcat] Tomc...」留言:
    第6點有問題,在我的電腦上, rolename和roles填...
  • [13/05/17] 歐兆傑 於文章「強大的JQuery圖表套件...」留言:
    當時我所用的是IE9,是可呈現的,請問你版本是?...
  • [13/05/16] 王暉鈞 於文章「強大的JQuery圖表套件...」留言:
    請問大大,如何能讓此在IE上呈現?...

動態訂閱

文章精選

文章搜尋

參觀人氣

  • 本日人氣:
  • 累積人氣:

C 組廣告版面

留言板