记得上下班打卡 | git大法好,push需谨慎
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
liquidnet-bus-v1
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
董敬伟
liquidnet-bus-v1
Commits
39720c3b
Commit
39720c3b
authored
Jul 06, 2021
by
jiangxiulong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
快递展示
parent
7243132f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
320 additions
and
320 deletions
+320
-320
ExpressPrintController.java
...web/controller/zhengzai/kylin/ExpressPrintController.java
+320
-320
No files found.
liquidnet-bus-client/liquidnet-client-admin/liquidnet-client-admin-web/src/main/java/com/liquidnet/client/admin/web/controller/zhengzai/kylin/ExpressPrintController.java
View file @
39720c3b
package
com
.
liquidnet
.
client
.
admin
.
web
.
controller
.
zhengzai
.
kylin
;
//
package com.liquidnet.client.admin.web.controller.zhengzai.kylin;
//
import
org.apache.commons.io.IOUtils
;
//
import org.apache.commons.io.IOUtils;
import
org.slf4j.Logger
;
//
import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
//
import org.slf4j.LoggerFactory;
//
import
java.io.FileInputStream
;
//
import java.io.FileInputStream;
import
java.io.IOException
;
//
import java.io.IOException;
//
import
javax.print.Doc
;
//
import javax.print.Doc;
import
javax.print.DocFlavor
;
//
import javax.print.DocFlavor;
import
javax.print.DocPrintJob
;
//
import javax.print.DocPrintJob;
import
javax.print.PrintException
;
//
import javax.print.PrintException;
import
javax.print.PrintService
;
//
import javax.print.PrintService;
import
javax.print.PrintServiceLookup
;
//
import javax.print.PrintServiceLookup;
import
javax.print.SimpleDoc
;
//
import javax.print.SimpleDoc;
import
javax.print.attribute.DocAttributeSet
;
//
import javax.print.attribute.DocAttributeSet;
import
javax.print.attribute.HashDocAttributeSet
;
//
import javax.print.attribute.HashDocAttributeSet;
import
javax.print.attribute.HashPrintRequestAttributeSet
;
//
import javax.print.attribute.HashPrintRequestAttributeSet;
import
javax.print.attribute.PrintRequestAttributeSet
;
//
import javax.print.attribute.PrintRequestAttributeSet;
import
javax.print.attribute.standard.Copies
;
//
import javax.print.attribute.standard.Copies;
import
javax.print.attribute.standard.MediaPrintableArea
;
//
import javax.print.attribute.standard.MediaPrintableArea;
import
javax.print.attribute.standard.OrientationRequested
;
//
import javax.print.attribute.standard.OrientationRequested;
import
javax.print.attribute.standard.PrintQuality
;
//
import javax.print.attribute.standard.PrintQuality;
//
import
java.awt.Color
;
//
import java.awt.Color;
import
java.awt.Graphics
;
//
import java.awt.Graphics;
import
java.awt.image.BufferedImage
;
//
import java.awt.image.BufferedImage;
import
java.io.File
;
//
import java.io.File;
import
java.io.FileOutputStream
;
//
import java.io.FileOutputStream;
import
java.io.OutputStream
;
//
import java.io.OutputStream;
import
java.util.ArrayList
;
//
import java.util.ArrayList;
import
java.util.List
;
//
import java.util.List;
//
//
import
com.sun.image.codec.jpeg.JPEGCodec
;
//
import com.sun.image.codec.jpeg.JPEGCodec;
import
com.sun.image.codec.jpeg.JPEGImageEncoder
;
//
import com.sun.image.codec.jpeg.JPEGImageEncoder;
//
/**
/
//
**
* <p>
//
* <p>
* xx 服务实现类
//
* xx 服务实现类
* </p>
//
* </p>
*
//
*
* @author jiangxiulong
//
* @author jiangxiulong
* @since 2021-07-05 7:50 下午
//
* @since 2021-07-05 7:50 下午
*/
//
*/
public
class
ExpressPrintController
{
//
public class ExpressPrintController {
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ExpressPrintController
.
class
);
//
private static final Logger logger = LoggerFactory.getLogger(ExpressPrintController.class);
//
private
int
m_nImageHeight
=
40
;
// 条码的高度像素数
//
private int m_nImageHeight = 40; // 条码的高度像素数
//
String
[][]
code128
=
{{
" "
,
" "
,
"00"
,
"212222"
,
"11011001100"
},
//
String[][] code128 = {{" ", " ", "00", "212222", "11011001100"},
{
"!"
,
"!"
,
"01"
,
"222122"
,
"11001101100"
},
//
{"!", "!", "01", "222122", "11001101100"},
{
"\""
,
"\""
,
"02"
,
"222221"
,
"11001100110"
},
//
{"\"", "\"", "02", "222221", "11001100110"},
{
"#"
,
"#"
,
"03"
,
"121223"
,
"10010011000"
},
//
{"#", "#", "03", "121223", "10010011000"},
{
"$"
,
"$"
,
"04"
,
"121322"
,
"10010001100"
},
//
{"$", "$", "04", "121322", "10010001100"},
{
"%"
,
"%"
,
"05"
,
"131222"
,
"10001001100"
},
//
{"%", "%", "05", "131222", "10001001100"},
{
"&"
,
"&"
,
"06"
,
"122213"
,
"10011001000"
},
//
{"&", "&", "06", "122213", "10011001000"},
{
"'"
,
"'"
,
"07"
,
"122312"
,
"10011000100"
,},
//
{"'", "'", "07", "122312", "10011000100",},
{
"("
,
"("
,
"08"
,
"132212"
,
"10001100100"
},
//
{"(", "(", "08", "132212", "10001100100"},
{
")"
,
")"
,
"09"
,
"221213"
,
"11001001000"
},
//
{")", ")", "09", "221213", "11001001000"},
{
"*"
,
"*"
,
"10"
,
"221312"
,
"11001000100"
},
//
{"*", "*", "10", "221312", "11001000100"},
{
"+"
,
"+"
,
"11"
,
"231212"
,
"11000100100"
},
//
{"+", "+", "11", "231212", "11000100100"},
{
","
,
","
,
"12"
,
"112232"
,
"10110011100"
},
//
{",", ",", "12", "112232", "10110011100"},
{
"-"
,
"-"
,
"13"
,
"122132"
,
"10011011100"
},
//
{"-", "-", "13", "122132", "10011011100"},
{
"."
,
"."
,
"14"
,
"122231"
,
"10011001110"
},
//
{".", ".", "14", "122231", "10011001110"},
{
"/"
,
"/"
,
"15"
,
"113222"
,
"10111001100"
},
//
{"/", "/", "15", "113222", "10111001100"},
{
"0"
,
"0"
,
"16"
,
"123122"
,
"10011101100"
},
//
{"0", "0", "16", "123122", "10011101100"},
{
"1"
,
"1"
,
"17"
,
"123221"
,
"10011100110"
},
//
{"1", "1", "17", "123221", "10011100110"},
{
"2"
,
"2"
,
"18"
,
"223211"
,
"11001110010"
,},
//
{"2", "2", "18", "223211", "11001110010",},
{
"3"
,
"3"
,
"19"
,
"221132"
,
"11001011100"
},
//
{"3", "3", "19", "221132", "11001011100"},
{
"4"
,
"4"
,
"20"
,
"221231"
,
"11001001110"
,},
//
{"4", "4", "20", "221231", "11001001110",},
{
"5"
,
"5"
,
"21"
,
"213212"
,
"11011100100"
},
//
{"5", "5", "21", "213212", "11011100100"},
{
"6"
,
"6"
,
"22"
,
"223112"
,
"11001110100"
},
//
{"6", "6", "22", "223112", "11001110100"},
{
"7"
,
"7"
,
"23"
,
"312131"
,
"11101101110"
},
//
{"7", "7", "23", "312131", "11101101110"},
{
"8"
,
"8"
,
"24"
,
"311222"
,
"11101001100"
},
//
{"8", "8", "24", "311222", "11101001100"},
{
"9"
,
"9"
,
"25"
,
"321122"
,
"11100101100"
},
//
{"9", "9", "25", "321122", "11100101100"},
{
":"
,
":"
,
"26"
,
"321221"
,
"11100100110"
},
//
{":", ":", "26", "321221", "11100100110"},
{
";"
,
";"
,
"27"
,
"312212"
,
"11101100100"
},
//
{";", ";", "27", "312212", "11101100100"},
{
"<"
,
"<"
,
"28"
,
"322112"
,
"11100110100"
},
//
{"<", "<", "28", "322112", "11100110100"},
{
"="
,
"="
,
"29"
,
"322211"
,
"11100110010"
},
//
{"=", "=", "29", "322211", "11100110010"},
{
">"
,
">"
,
"30"
,
"212123"
,
"11011011000"
},
//
{">", ">", "30", "212123", "11011011000"},
{
"?"
,
"?"
,
"31"
,
"212321"
,
"11011000110"
},
//
{"?", "?", "31", "212321", "11011000110"},
{
"@"
,
"@"
,
"32"
,
"232121"
,
"11000110110"
},
//
{"@", "@", "32", "232121", "11000110110"},
{
"A"
,
"A"
,
"33"
,
"111323"
,
"10100011000"
},
//
{"A", "A", "33", "111323", "10100011000"},
{
"B"
,
"B"
,
"34"
,
"131123"
,
"10001011000"
},
//
{"B", "B", "34", "131123", "10001011000"},
{
"C"
,
"C"
,
"35"
,
"131321"
,
"10001000110"
},
//
{"C", "C", "35", "131321", "10001000110"},
{
"D"
,
"D"
,
"36"
,
"112313"
,
"10110001000"
},
//
{"D", "D", "36", "112313", "10110001000"},
{
"E"
,
"E"
,
"37"
,
"132113"
,
"10001101000"
},
//
{"E", "E", "37", "132113", "10001101000"},
{
"F"
,
"F"
,
"38"
,
"132311"
,
"10001100010"
},
//
{"F", "F", "38", "132311", "10001100010"},
{
"G"
,
"G"
,
"39"
,
"211313"
,
"11010001000"
},
//
{"G", "G", "39", "211313", "11010001000"},
{
"H"
,
"H"
,
"40"
,
"231113"
,
"11000101000"
},
//
{"H", "H", "40", "231113", "11000101000"},
{
"I"
,
"I"
,
"41"
,
"231311"
,
"11000100010"
},
//
{"I", "I", "41", "231311", "11000100010"},
{
"J"
,
"J"
,
"42"
,
"112133"
,
"10110111000"
},
//
{"J", "J", "42", "112133", "10110111000"},
{
"K"
,
"K"
,
"43"
,
"112331"
,
"10110001110"
},
//
{"K", "K", "43", "112331", "10110001110"},
{
"L"
,
"L"
,
"44"
,
"132131"
,
"10001101110"
},
//
{"L", "L", "44", "132131", "10001101110"},
{
"M"
,
"M"
,
"45"
,
"113123"
,
"10111011000"
},
//
{"M", "M", "45", "113123", "10111011000"},
{
"N"
,
"N"
,
"46"
,
"113321"
,
"10111000110"
},
//
{"N", "N", "46", "113321", "10111000110"},
{
"O"
,
"O"
,
"47"
,
"133121"
,
"10001110110"
},
//
{"O", "O", "47", "133121", "10001110110"},
{
"P"
,
"P"
,
"48"
,
"313121"
,
"11101110110"
},
//
{"P", "P", "48", "313121", "11101110110"},
{
"Q"
,
"Q"
,
"49"
,
"211331"
,
"11010001110"
},
//
{"Q", "Q", "49", "211331", "11010001110"},
{
"R"
,
"R"
,
"50"
,
"231131"
,
"11000101110"
},
//
{"R", "R", "50", "231131", "11000101110"},
{
"S"
,
"S"
,
"51"
,
"213113"
,
"11011101000"
},
//
{"S", "S", "51", "213113", "11011101000"},
{
"T"
,
"T"
,
"52"
,
"213311"
,
"11011100010"
},
//
{"T", "T", "52", "213311", "11011100010"},
{
"U"
,
"U"
,
"53"
,
"213131"
,
"11011101110"
},
//
{"U", "U", "53", "213131", "11011101110"},
{
"V"
,
"V"
,
"54"
,
"311123"
,
"11101011000"
},
//
{"V", "V", "54", "311123", "11101011000"},
{
"W"
,
"W"
,
"55"
,
"311321"
,
"11101000110"
},
//
{"W", "W", "55", "311321", "11101000110"},
{
"X"
,
"X"
,
"56"
,
"331121"
,
"11100010110"
},
//
{"X", "X", "56", "331121", "11100010110"},
{
"Y"
,
"Y"
,
"57"
,
"312113"
,
"11101101000"
},
//
{"Y", "Y", "57", "312113", "11101101000"},
{
"Z"
,
"Z"
,
"58"
,
"312311"
,
"11101100010"
},
//
{"Z", "Z", "58", "312311", "11101100010"},
{
"["
,
"["
,
"59"
,
"332111"
,
"11100011010"
},
//
{"[", "[", "59", "332111", "11100011010"},
{
"\\"
,
"\\"
,
"60"
,
"314111"
,
"11101111010"
},
//
{"\\", "\\", "60", "314111", "11101111010"},
{
"]"
,
"]"
,
"61"
,
"221411"
,
"11001000010"
},
//
{"]", "]", "61", "221411", "11001000010"},
{
"^"
,
"^"
,
"62"
,
"431111"
,
"11110001010"
},
//
{"^", "^", "62", "431111", "11110001010"},
{
"_"
,
"_"
,
"63"
,
"111224"
,
"10100110000"
},
//
{"_", "_", "63", "111224", "10100110000"},
{
"NUL"
,
"`"
,
"64"
,
"111422"
,
"10100001100"
},
//
{"NUL", "`", "64", "111422", "10100001100"},
{
"SOH"
,
"a"
,
"65"
,
"121124"
,
"10010110000"
},
//
{"SOH", "a", "65", "121124", "10010110000"},
{
"STX"
,
"b"
,
"66"
,
"121421"
,
"10010000110"
},
//
{"STX", "b", "66", "121421", "10010000110"},
{
"ETX"
,
"c"
,
"67"
,
"141122"
,
"10000101100"
},
//
{"ETX", "c", "67", "141122", "10000101100"},
{
"EOT"
,
"d"
,
"68"
,
"141221"
,
"10000100110"
},
//
{"EOT", "d", "68", "141221", "10000100110"},
{
"ENQ"
,
"e"
,
"69"
,
"112214"
,
"10110010000"
},
//
{"ENQ", "e", "69", "112214", "10110010000"},
{
"ACK"
,
"f"
,
"70"
,
"112412"
,
"10110000100"
},
//
{"ACK", "f", "70", "112412", "10110000100"},
{
"BEL"
,
"g"
,
"71"
,
"122114"
,
"10011010000"
},
//
{"BEL", "g", "71", "122114", "10011010000"},
{
"BS"
,
"h"
,
"72"
,
"122411"
,
"10011000010"
},
//
{"BS", "h", "72", "122411", "10011000010"},
{
"HT"
,
"i"
,
"73"
,
"142112"
,
"10000110100"
},
//
{"HT", "i", "73", "142112", "10000110100"},
{
"LF"
,
"j"
,
"74"
,
"142211"
,
"10000110010"
},
//
{"LF", "j", "74", "142211", "10000110010"},
{
"VT"
,
"k"
,
"75"
,
"241211"
,
"11000010010"
},
//
{"VT", "k", "75", "241211", "11000010010"},
{
"FF"
,
"I"
,
"76"
,
"221114"
,
"11001010000"
},
//
{"FF", "I", "76", "221114", "11001010000"},
{
"CR"
,
"m"
,
"77"
,
"413111"
,
"11110111010"
},
//
{"CR", "m", "77", "413111", "11110111010"},
{
"SO"
,
"n"
,
"78"
,
"241112"
,
"11000010100"
},
//
{"SO", "n", "78", "241112", "11000010100"},
{
"SI"
,
"o"
,
"79"
,
"134111"
,
"10001111010"
},
//
{"SI", "o", "79", "134111", "10001111010"},
{
"DLE"
,
"p"
,
"80"
,
"111242"
,
"10100111100"
},
//
{"DLE", "p", "80", "111242", "10100111100"},
{
"DC1"
,
"q"
,
"81"
,
"121142"
,
"10010111100"
},
//
{"DC1", "q", "81", "121142", "10010111100"},
{
"DC2"
,
"r"
,
"82"
,
"121241"
,
"10010011110"
},
//
{"DC2", "r", "82", "121241", "10010011110"},
{
"DC3"
,
"s"
,
"83"
,
"114212"
,
"10111100100"
},
//
{"DC3", "s", "83", "114212", "10111100100"},
{
"DC4"
,
"t"
,
"84"
,
"124112"
,
"10011110100"
},
//
{"DC4", "t", "84", "124112", "10011110100"},
{
"NAK"
,
"u"
,
"85"
,
"124211"
,
"10011110010"
},
//
{"NAK", "u", "85", "124211", "10011110010"},
{
"SYN"
,
"v"
,
"86"
,
"411212"
,
"11110100100"
},
//
{"SYN", "v", "86", "411212", "11110100100"},
{
"ETB"
,
"w"
,
"87"
,
"421112"
,
"11110010100"
},
//
{"ETB", "w", "87", "421112", "11110010100"},
{
"CAN"
,
"x"
,
"88"
,
"421211"
,
"11110010010"
},
//
{"CAN", "x", "88", "421211", "11110010010"},
{
"EM"
,
"y"
,
"89"
,
"212141"
,
"11011011110"
},
//
{"EM", "y", "89", "212141", "11011011110"},
{
"SUB"
,
"z"
,
"90"
,
"214121"
,
"11011110110"
},
//
{"SUB", "z", "90", "214121", "11011110110"},
{
"ESC"
,
"{"
,
"91"
,
"412121"
,
"11110110110"
},
//
{"ESC", "{", "91", "412121", "11110110110"},
{
"FS"
,
"|"
,
"92"
,
"111143"
,
"10101111000"
},
//
{"FS", "|", "92", "111143", "10101111000"},
{
"GS"
,
"},"
,
"93"
,
"111341"
,
"10100011110"
},
//
{"GS", "},", "93", "111341", "10100011110"},
{
"RS"
,
"~"
,
"94"
,
"131141"
,
"10001011110"
},
//
{"RS", "~", "94", "131141", "10001011110"},
{
"US"
,
"DEL"
,
"95"
,
"114113"
,
"10111101000"
},
//
{"US", "DEL", "95", "114113", "10111101000"},
{
"FNC3"
,
"FNC3"
,
"96"
,
"114311"
,
"10111100010"
},
//
{"FNC3", "FNC3", "96", "114311", "10111100010"},
{
"FNC2"
,
"FNC2"
,
"97"
,
"411113"
,
"11110101000"
},
//
{"FNC2", "FNC2", "97", "411113", "11110101000"},
{
"SHIFT"
,
"SHIFT"
,
"98"
,
"411311"
,
"11110100010"
},
//
{"SHIFT", "SHIFT", "98", "411311", "11110100010"},
{
"CODEC"
,
"CODEC"
,
"99"
,
"113141"
,
"10111011110"
},
//
{"CODEC", "CODEC", "99", "113141", "10111011110"},
{
"CODEB"
,
"FNC4"
,
"CODEB"
,
"114131"
,
"10111101110"
},
//
{"CODEB", "FNC4", "CODEB", "114131", "10111101110"},
{
"FNC4"
,
"CODEA"
,
"CODEA"
,
"311141"
,
"11101011110"
},
//
{"FNC4", "CODEA", "CODEA", "311141", "11101011110"},
{
"FNC1"
,
"FNC1"
,
"FNC1"
,
"411131"
,
"11110101110"
},
//
{"FNC1", "FNC1", "FNC1", "411131", "11110101110"},
{
"StartA"
,
"StartA"
,
"StartA"
,
"211412"
,
"11010000100"
},
//
{"StartA", "StartA", "StartA", "211412", "11010000100"},
{
"StartB"
,
"StartB"
,
"StartB"
,
"211214"
,
"11010010000"
},
//
{"StartB", "StartB", "StartB", "211214", "11010010000"},
{
"StartC"
,
"StartC"
,
"StartC"
,
"211232"
,
"11010011100"
},
//
{"StartC", "StartC", "StartC", "211232", "11010011100"},
{
"Stop"
,
"Stop"
,
"Stop"
,
"2331112"
,
"1100011101011"
},};
//
{"Stop", "Stop", "Stop", "2331112", "1100011101011"},};
//
/**
//
/**
* 打印图片
//
* 打印图片
*
//
*
* @param fileName
//
* @param fileName
* @param count
//
* @param count
*/
//
*/
public
static
void
drawImage
(
String
fileName
,
int
count
)
{
//
public static void drawImage(String fileName, int count) {
FileInputStream
fin
=
null
;
//
FileInputStream fin = null;
try
{
//
try {
DocFlavor
dof
=
null
;
//
DocFlavor dof = null;
if
(
fileName
.
endsWith
(
".gif"
))
{
//
if (fileName.endsWith(".gif")) {
dof
=
DocFlavor
.
INPUT_STREAM
.
GIF
;
//
dof = DocFlavor.INPUT_STREAM.GIF;
}
else
if
(
fileName
.
endsWith
(
".jpg"
))
{
//
} else if (fileName.endsWith(".jpg")) {
dof
=
DocFlavor
.
INPUT_STREAM
.
JPEG
;
//
dof = DocFlavor.INPUT_STREAM.JPEG;
}
else
if
(
fileName
.
endsWith
(
".png"
))
{
//
} else if (fileName.endsWith(".png")) {
dof
=
DocFlavor
.
INPUT_STREAM
.
PNG
;
//
dof = DocFlavor.INPUT_STREAM.PNG;
}
//
}
//
PrintService
ps
=
PrintServiceLookup
.
lookupDefaultPrintService
();
//
PrintService ps = PrintServiceLookup.lookupDefaultPrintService();
//
PrintRequestAttributeSet
pras
=
new
HashPrintRequestAttributeSet
();
//
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras
.
add
(
OrientationRequested
.
PORTRAIT
);
//
pras.add(OrientationRequested.PORTRAIT);
//
pras
.
add
(
new
Copies
(
count
));
//
pras.add(new Copies(count));
pras
.
add
(
PrintQuality
.
HIGH
);
//
pras.add(PrintQuality.HIGH);
DocAttributeSet
das
=
new
HashDocAttributeSet
();
//
DocAttributeSet das = new HashDocAttributeSet();
//
// 设置打印纸张的大小(以毫米为单位)
//
// 设置打印纸张的大小(以毫米为单位)
das
.
add
(
new
MediaPrintableArea
(
0
,
0
,
210
,
296
,
MediaPrintableArea
.
MM
));
//
das.add(new MediaPrintableArea(0, 0, 210, 296, MediaPrintableArea.MM));
fin
=
new
FileInputStream
(
fileName
);
//
fin = new FileInputStream(fileName);
//
Doc
doc
=
new
SimpleDoc
(
fin
,
dof
,
das
);
//
Doc doc = new SimpleDoc(fin, dof, das);
//
DocPrintJob
job
=
ps
.
createPrintJob
();
//
DocPrintJob job = ps.createPrintJob();
//
job
.
print
(
doc
,
pras
);
//
job.print(doc, pras);
fin
.
close
();
//
fin.close();
logger
.
info
(
"打印成功!文件:"
+
fileName
+
"数量为:"
+
count
);
//
logger.info("打印成功!文件:" + fileName + "数量为:" + count);
}
catch
(
IOException
ie
)
{
//
} catch (IOException ie) {
ie
.
printStackTrace
();
//
ie.printStackTrace();
}
catch
(
PrintException
pe
)
{
//
} catch (PrintException pe) {
pe
.
printStackTrace
();
//
pe.printStackTrace();
}
finally
{
//
} finally {
IOUtils
.
closeQuietly
(
fin
);
//
IOUtils.closeQuietly(fin);
}
//
}
}
//
}
//
/**
//
/**
* 生产Code128的条形码的code
//
* 生产Code128的条形码的code
*
//
*
* @param barCode
//
* @param barCode
* @param encode
//
* @param encode
* @return
//
* @return
*/
//
*/
public
String
getCode
(
String
barCode
,
String
encode
)
{
//
public String getCode(String barCode, String encode) {
String
_Text
=
""
;
// 返回的参数
//
String _Text = "";// 返回的参数
List
<
Integer
>
_TextNumb
=
new
ArrayList
<
Integer
>();
// 2截取位的组合
//
List<Integer> _TextNumb = new ArrayList<Integer>();// 2截取位的组合
int
_Examine
=
105
;
// 首位
//
int _Examine = 105; // 首位
// 编码不能是奇数
//
// 编码不能是奇数
if
(!((
barCode
.
length
()
&
1
)
==
0
))
//
if (!((barCode.length() & 1) == 0))
return
""
;
//
return "";
while
(
barCode
.
length
()
!=
0
)
{
//
while (barCode.length() != 0) {
int
_Temp
=
0
;
//
int _Temp = 0;
try
{
//
try {
// Code128 编码必须为数字
//
// Code128 编码必须为数字
_Temp
=
Integer
.
valueOf
(
barCode
.
substring
(
0
,
2
));
//
_Temp = Integer.valueOf(barCode.substring(0, 2));
}
catch
(
Exception
e
)
{
//
} catch (Exception e) {
e
.
printStackTrace
();
//
e.printStackTrace();
return
""
;
//
return "";
}
//
}
// 获得条纹
//
// 获得条纹
_Text
+=
getValue
(
barCode
,
barCode
.
substring
(
0
,
2
),
_Temp
);
//
_Text += getValue(barCode, barCode.substring(0, 2), _Temp);
_TextNumb
.
add
(
_Temp
);
//
_TextNumb.add(_Temp);
// 条码截取2个就需要去掉用过的前二位
//
// 条码截取2个就需要去掉用过的前二位
barCode
=
barCode
.
substring
(
2
);
//
barCode = barCode.substring(2);
}
//
}
if
(
_TextNumb
.
size
()
==
0
)
{
//
if (_TextNumb.size() == 0) {
return
""
;
//
return "";
}
//
}
_Text
=
getValue
(
_Examine
)
+
_Text
;
// 获取开始位
//
_Text = getValue(_Examine) + _Text; // 获取开始位
for
(
int
i
=
0
;
i
!=
_TextNumb
.
size
();
i
++)
{
//
for (int i = 0; i != _TextNumb.size(); i++) {
_Examine
+=
_TextNumb
.
get
(
i
)
*
(
i
+
1
);
//
_Examine += _TextNumb.get(i) * (i + 1);
}
//
}
_Examine
=
_Examine
%
103
;
// 获得校验位
//
_Examine = _Examine % 103; // 获得校验位
_Text
+=
getValue
(
_Examine
);
// 获取校验位
//
_Text += getValue(_Examine); // 获取校验位
_Text
+=
"1100011101011"
;
// 结束位
//
_Text += "1100011101011"; // 结束位
return
_Text
;
//
return _Text;
}
//
}
//
/**
//
/**
* 根据编号获得条纹
//
* 根据编号获得条纹
*
//
*
* @param encode
//
* @param encode
* @param p_Value
//
* @param p_Value
* @param p_SetID
//
* @param p_SetID
* @return
//
* @return
*/
//
*/
private
String
getValue
(
String
encode
,
String
p_Value
,
int
p_SetID
)
{
//
private String getValue(String encode, String p_Value, int p_SetID) {
return
code128
[
p_SetID
][
4
];
//
return code128[p_SetID][4];
}
//
}
//
/**
//
/**
* 根据编号获得条纹
//
* 根据编号获得条纹
* @param p_CodeId
//
* @param p_CodeId
* @return
//
* @return
*/
//
*/
private
String
getValue
(
int
p_CodeId
)
{
//
private String getValue(int p_CodeId) {
return
code128
[
p_CodeId
][
4
];
//
return code128[p_CodeId][4];
}
//
}
//
/**
//
/**
* 生成条码
//
* 生成条码
* @param barString 条码模式字符串
//
* @param barString 条码模式字符串
* @param Height 生成的条码高度
//
* @param Height 生成的条码高度
* @param path 条码图形
//
* @param path 条码图形
*/
//
*/
public
void
kiCode128C
(
String
barString
,
int
Height
,
String
path
)
{
//
public void kiCode128C(String barString, int Height, String path) {
try
{
//
try {
File
myPNG
=
new
File
(
path
);
//
File myPNG = new File(path);
OutputStream
out
=
new
FileOutputStream
(
myPNG
);
//
OutputStream out = new FileOutputStream(myPNG);
if
(
null
==
barString
||
null
==
out
||
0
==
barString
.
length
())
//
if (null == barString || null == out || 0 == barString.length())
return
;
//
return;
int
nImageWidth
=
0
;
//
int nImageWidth = 0;
char
[]
cs
=
barString
.
toCharArray
();
//
char[] cs = barString.toCharArray();
for
(
int
i
=
0
;
i
!=
cs
.
length
;
i
++)
{
//
for (int i = 0; i != cs.length; i++) {
nImageWidth
=
cs
.
length
;
//
nImageWidth = cs.length;
}
//
}
BufferedImage
bi
=
new
BufferedImage
(
nImageWidth
,
m_nImageHeight
,
//
BufferedImage bi = new BufferedImage(nImageWidth, m_nImageHeight,
BufferedImage
.
TYPE_INT_RGB
);
//
BufferedImage.TYPE_INT_RGB);
Graphics
g
=
bi
.
getGraphics
();
//
Graphics g = bi.getGraphics();
for
(
int
i
=
0
;
i
<
cs
.
length
;
i
++)
{
//
for (int i = 0; i < cs.length; i++) {
if
(
"1"
.
equals
(
cs
[
i
]
+
""
))
{
//
if ("1".equals(cs[i] + "")) {
g
.
setColor
(
Color
.
BLACK
);
//
g.setColor(Color.BLACK);
g
.
fillRect
(
i
,
0
,
1
,
m_nImageHeight
);
//
g.fillRect(i, 0, 1, m_nImageHeight);
}
else
{
//
} else {
g
.
setColor
(
Color
.
WHITE
);
//
g.setColor(Color.WHITE);
g
.
fillRect
(
i
,
0
,
1
,
m_nImageHeight
);
//
g.fillRect(i, 0, 1, m_nImageHeight);
}
//
}
}
//
}
JPEGImageEncoder
encoder
=
JPEGCodec
.
createJPEGEncoder
(
out
);
//
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder
.
encode
(
bi
);
//
encoder.encode(bi);
}
catch
(
Exception
e
)
{
//
} catch (Exception e) {
e
.
printStackTrace
();
//
e.printStackTrace();
}
//
}
}
//
}
//
/**
//
/**
* test
//
* test
*
//
*
* @param args
//
* @param args
*/
//
*/
public
static
void
main
(
String
[]
args
)
{
//
public static void main(String[] args) {
// 打印图片
//
// 打印图片
// new ExpressPrintController().drawImage("/Users/jiangxiulong/Desktop/图片余篇图片/WX20210705-200856@2x.png", 1);
//
// new ExpressPrintController().drawImage("/Users/jiangxiulong/Desktop/图片余篇图片/WX20210705-200856@2x.png", 1);
// 生成条形码
//
// 生成条形码
String
barCode
=
new
ExpressPrintController
().
getCode
(
"118842807789"
,
""
);
//
String barCode = new ExpressPrintController().getCode("118842807789", "");
new
ExpressPrintController
().
kiCode128C
(
barCode
,
50
,
"/Users/jiangxiulong/Desktop/图片余篇图片/code128C.jpg"
);
//
new ExpressPrintController().kiCode128C(barCode, 50, "/Users/jiangxiulong/Desktop/图片余篇图片/code128C.jpg");
// 生成二维码
//
// 生成二维码
}
//
}
//
}
//
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment