Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.google.zxing.BarcodeFormat;
- import com.google.zxing.Writer;
- import com.google.zxing.WriterException;
- import com.google.zxing.client.j2se.MatrixToImageWriter;
- import com.google.zxing.common.BitMatrix;
- import com.google.zxing.oned.Code128Writer;
- import com.google.zxing.pdf417.encoder.PDF417Writer;
- import com.google.zxing.qrcode.QRCodeWriter;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.FileReader;
- import java.io.IOException;
- //import java.io.FileWriter;
- //import java.io.IOException;
- import java.util.Scanner;
- import javax.imageio.ImageIO;
- import javax.swing.ImageIcon;
- import java.util.ArrayList;
- import java.util.Arrays;
- public class Mich {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- String CR = Character.toString ((char) 13);
- String LF = Character.toString ((char) 10);
- String FS = Character.toString ((char) 28);
- String RS = Character.toString ((char) 30);
- String SP = Character.toString ((char) 32);
- String MI = "@"+LF+RS+CR+"ANSI 636032030002DL00410220ZM02610027DLDCA"+LF+
- "DCB"+LF+"DCD"+LF+"DBA04212017"+LF+"DCSSHAFOU"+LF+"DCTNATHANIELJAMES"+
- LF+"DBD12032013"+LF+"DBB04211994"+LF+"DBC1"+LF+"DAY"+LF+"DAU"+LF+
- "DAG27901 MANHATTAN ST"+LF+"DAIST CLAIR SHORES"+LF+"DAJMI"+LF+"DAK480813516"+
- LF+"DAQS 100 622 367 308"+"DCF"+LF+"DCG"+LF+"DCH"+LF+"DAH"+LF+"DCKS100622367308199604212017"+
- LF+LF;
- String CO2 = "@"+LF+RS+CR+"ANSI 636020070002DL00410223ZC02640014DLDAQ040900832"+LF+
- "DCSDOWDELL"+LF+"DDEU"+LF+"DACCHELSEA"+LF+"DDFU"+LF+"DADANN"+LF+
- "DDGU"+LF+"DCAR"+LF+"DCBNONE"+LF+"DCDNONE"+LF+"DBD05122015"+LF+
- "DBB07281988"+LF+"DBA07282020"+LF+"DBC2"+LF+"DAU064 in"+LF+"DAYBLU"+
- LF+"DAG1755 DAYTON STREET"+LF+"DAIAURORA"+LF+"DAJCO"+LF+"DAK800100000"+
- LF+"DCFNONE"+LF+"DCGUSA"+LF+"DDAM"+LF+"DDB06012013"+CR+"ZCZCA"+LF+
- "ZCB"+LF+"ZCC"+CR;
- //+CR+LF+RS+CR+LF+
- String CO = "@"+CR+LF+RS+CR+LF+"ANSI 636020070002DL00410223ZC02640014DLDAQ040900832"+CR+LF+
- "DCSDOWDELL"+CR+LF+"DDEU"+CR+LF+"DACCHELSEA"+CR+LF+"DDFU"+CR+LF+"DADANN"+CR+LF+"DDGU"+CR+LF+
- "DCAR"+CR+LF+"DCBNONE"+CR+LF+"DCDNONE"+CR+LF+"DBD05122015"+CR+LF+"DBB07281988"+CR+LF+"DBA07282020"
- +CR+LF+"DBC2"+CR+LF+"DAU064 in"+CR+LF+"DAYBLU"+CR+LF+"DAG1755 DAYTON STREET"+CR+LF+"DAIAURORA"+CR+LF+
- "DAJCO"+CR+LF+"DAK800100000"+CR+LF+"DCFNONE"+CR+LF+"DCGUSA"+CR+LF+"DDAM"+CR+LF+"DDB06012013"
- +CR+LF+"ZCZCA"+CR+LF+"ZCB"+CR+LF+"ZCC";
- String ED = "@"+LF+RS+CR+"ANSI 536020050002DL00415223ZC02640014DLDAQ42069000"+LF+
- "DCSLAST"+LF+"DDEU"+LF+"DACFIRST"+LF+"DDFU"+LF+"DADM"+LF+
- "DDGU"+LF+"DCAR"+LF+"DCBNONE"+LF+"DCDNONE"+LF+"DBD05122015"+LF+
- "DBB07281988"+LF+"DBA07282020"+LF+"DBC1"+LF+"DAU064 in"+LF+"DAYBLU"+
- LF+"DAG1738 FETTY WAP WAY"+LF+"DAIREDDIT"+LF+"DAJED"+LF+"DAK123450000"+
- LF+"DCFNONE"+LF+"DCGUSA"+LF+"DDAM"+LF+"DDB06012013"+CR+"ZEZFU"+LF+
- "ZCB"+LF+"ZCC"+CR;
- String ME = "@"+LF+RS+CR+"ANSI 636041040002DL00410242ZM02830007DLDAQ8250093"+CR+LF+"DCSTREFRY"
- +CR+LF+"DDEN"+CR+LF+"DACALFRED"+CR+LF+"DDFN"+CR+LF+"DADWILSON"+CR+LF+"DDGN"+CR+LF+
- "DCAA"+CR+LF+"DCBNONE"+CR+LF+"DCDIN"+CR+LF+"DBD03062013"+CR+LF+"DBB01291959"+CR+LF+
- "DBA01292018"+CR+LF+"DBC1"+CR+LF+"DAU071 in"+CR+LF+"DAYGR"+CR+LF+"DAG1102 ALFRED ROAD"
- +CR+LF+"DAIARUNDEL"+CR+LF+"DAJME"+CR+LF+"DAK040460000"+CR+LF+"DCFNONE"+CR+LF+"DCGUSA"
- +CR+LF+"DCUIV"+CR+LF+"DAW270"+CR+LF+"DAZGY"+CR+LF+"DCKF1307182500930301"+CR+LF+"ZMZMAN";
- String OR = "@"+LF+RS+CR+"ANSI 6360290102DL00390182ZO02210031DLDAQ4305455"+CR+LF+"DAAHUMBERT, RYAN MATTHEW"
- +CR+LF+"DAG"+CR+LF+"DAL4894 HENCEFORTH LN"+CR+LF+"DAIEUGENE"+CR+LF+"DAJOR"+CR+LF+"DAK97402"+CR+LF+
- "DARC"+CR+LF+"DASD"+CR+LF+"DAT"+CR+LF+"DAU509"+CR+LF+"DAW175"+CR+LF+"DBA20221024"+CR+LF+"DBB19941024"
- +CR+LF+"DBC1"+CR+LF+"DBD20140404"+CR+LF+"ZOZOAFIRST LICENSED 04-04-2014"+CR+LF;
- String SC = "@"+LF+FS+CR+"ANSI 6360050101DL00300195DLDAQ934870146"+LF+
- "DAASMTIH,JOHN,J,"+LF+"DAG111 1ST STREET"+LF+"DAISPRINGFIELD"+LF+
- "DAJSC"+LF+"DAK72564 9654 "+LF+"DAR "+LF+"DAS "+LF+"DAT "+
- LF+"DAU073 IN"+LF+"DAW130"+LF+"DAY"+LF+"DAZBRO"+LF+"DBA02192018"+
- LF+"DBB02191996"+LF+"DBC1"+LF+"DBD02242014"+LF+"DBG"+CR+"DDEU"+CR;
- //barcodeGen(MI,"MI_test");
- //barcodeGen(ME,"ME_test");
- //barcodeGen(OR,"OR_test");
- //barcodeGen(CO2, "CO2_test");
- //barcodeGen(ED, "ED_test");
- //barcodeGen(MI, "MI_test");
- // TODO Auto-generated method stub
- ArrayList<String> filenames = new ArrayList<String>();
- //get filenames
- File directory = new File("./csvs");
- //get all the files from a directory
- File[] fList = directory.listFiles();
- for (File file : fList){
- if (file.isFile()){
- filenames.add(file.getName());
- }
- }
- for(int n=0; n<filenames.size(); n++){
- System.out.println(filenames.get(n));
- }
- //cycle through filenames
- for(int b=1; b<filenames.size(); b++){
- String name="./csvs/"+filenames.get(b);
- //pam is a huge bitch
- String filename = name;
- //ArrayList<String> template = textToArr("blank.txt");
- ArrayList<String> lines = getLines(filename);
- ArrayList<String> csv = readCSV(filename);
- //ArrayList<String> header = getHeader(csv);
- //print line by line
- for(int i=0; i<lines.size(); i++){
- System.out.println(i+":"+lines.get(i));
- }
- System.out.println("\n");
- //separated values
- for(int s=1; s<lines.size();s++){
- //template = textToArr("blank.txt");
- ArrayList<String> separated = splitByComma(lines.get(s));
- csv=separated;
- System.out.println("\n"+s+" Separated: \n");
- for(int i=0; i<csv.size(); i++){
- System.out.println(i+":"+csv.get(i));
- }
- System.out.println("\n");
- String data = "";
- String oneddata = "";
- String onedoutputName = "";
- //IF STATE == STATE THEN.... fuck it ill add it later
- if(csv.get(0).equals("MI")){
- data = MIdataCreator(csv, MI);
- oneddata = oneddatacreator(csv);
- //onedoutputName = csv.get(4)+"_"+oneddata+"_"+csv.get(8);
- onedoutputName = csv.get(4)+"_"+oneddata;
- }
- else if(csv.get(0).equals("SC"))
- data = OTCdataCreator(csv, SC);
- //data = MIdataCreator(csv, MI);
- System.out.println("\n\n");
- System.out.println("Data:");
- System.out.println(data);
- String outputName = "";
- if(csv.get(0).equals("MI")){
- outputName = "PDF417"+"_"+csv.get(4);
- }
- else if(csv.get(0).equals("SC")){
- outputName = "PDF417"+"_"+csv.get(4);
- }
- barcodeGen(data, outputName);
- onedbarcodeGen(oneddata,onedoutputName);
- System.out.println("End of loop\n -------");
- }
- }
- //image cropping begin
- System.out.println("Begin cropping images...");
- ArrayList<String> filenames2 = new ArrayList<String>();
- //get filenames2
- File directory2 = new File("./Images");
- //get all the files from a directory2
- File[] fList2 = directory2.listFiles();
- for (File file : fList2){
- if (file.isFile()){
- filenames2.add(file.getName());
- }
- }
- //for(int i=0; i<filenames2.size(); i++){
- // System.out.println(filenames2.get(i));
- // }
- //cycle through filenames2
- for(int i=1; i<filenames2.size(); i++){
- //System.out.println(i);
- Image img = new ImageIcon("./Images/"+filenames2.get(i)).getImage();
- BufferedImage bufferedImage = new BufferedImage(img.getWidth(null), img.getHeight(null),
- BufferedImage.TYPE_INT_RGB);
- Graphics g = bufferedImage.createGraphics();
- g.drawImage(img, 0, 0, null);
- g.dispose();
- bufferedImage = getCroppedImage(bufferedImage, .4);
- try {
- ImageIO.write(bufferedImage, "png", new File("./Output/"+filenames2.get(i)));
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- System.out.println("Exiting!");
- }
- //make 1D info
- public static String oneddatacreator(ArrayList<String> info){
- String data=null;
- /*
- 1) drivers license number
- 2) year of birth (1994)
- 3) month of birth (08)
- 4) day of birth (30)
- 5) last two digits of expiration year, so 2019 would be (19)
- 6) expiration month (08)
- 7) generic "01" that appears at the end of each persons. Idk why but it's always there
- */
- String bd = info.get(8);
- String[] result = bd.split("(?!^)");
- String month = result[0]+result[1];
- String day = result[2]+result[3];
- String year = result[4]+result[5]+result[6]+result[7];
- String exp = info.get(10);
- String[] expiry = exp.split("(?!^)");
- String expYear = expiry[6]+expiry[7];
- String expMonth = expiry[0]+expiry[1];
- String dlno = info.get(1);
- String dlnum = dlno.replaceAll(" ", "");
- data = dlnum + year + month + day + expYear + expMonth + "01";
- return data;
- }
- public static void onedbarcodeGen(String dada, String fn){
- BitMatrix bitMatrix;
- //Writer writer = new QRCodeWriter();
- try {
- // Write Barcode
- bitMatrix = new Code128Writer().encode(dada, BarcodeFormat.CODE_128, 150, 80, null);
- //MatrixToImageWriter.writeToStream(bitMatrix, "png", new FileOutputStream(new File("./1D/"+fn+"_"+dada+".png")));
- MatrixToImageWriter.writeToStream(bitMatrix, "png", new FileOutputStream(new File("./1D/"+fn+".png")));
- System.out.println("Code128 Barcode Generated: " +fn);
- } catch (Exception e) {
- System.out.println("Exception Found." + e.getMessage());
- }
- }
- public static void barcodeGen(String data, String filename){
- BitMatrix bitMatrix;
- Writer writer = new PDF417Writer();
- try {
- writer = new PDF417Writer();
- bitMatrix = writer.encode(data, BarcodeFormat.PDF_417, 80, 150);
- MatrixToImageWriter.writeToStream(bitMatrix, "png", new FileOutputStream(new File("./Images/"+ filename +".png")));
- System.out.println("PDF417 Code Generated: " + filename + ".png");
- }
- catch (Exception e) {
- System.out.println("Exception Found." + e.getMessage());
- }
- }
- public static ArrayList<String> splitByComma(String s){
- String[] items = s.split(",");
- ArrayList<String> itemList = new ArrayList<String>(Arrays.asList(items));
- System.out.println(itemList);
- return itemList;
- }
- public static ArrayList<String> textToArr(String txtName){
- ArrayList<String> template = new ArrayList<String>();
- try {
- Scanner in = new Scanner(new FileReader(txtName));
- while (in.hasNext()) {
- template.add(in.nextLine());
- }
- in.close();
- }
- catch (FileNotFoundException f){
- System.err.println("Could not open the file: " + txtName);
- }
- return template;
- }
- public static ArrayList<String> getLines(String csv){
- ArrayList<String> csvLines = new ArrayList<String>();
- Scanner scanner;
- try {
- scanner = new Scanner(new File(csv));
- while (scanner.hasNextLine())
- {
- csvLines.add(scanner.nextLine().toUpperCase());
- }
- }
- catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return csvLines;
- }
- public static ArrayList<String> readCSV(String csvName){
- ArrayList<String> csv = new ArrayList<String>();
- //Get scanner instance
- Scanner scanner;
- try {
- scanner = new Scanner(new File(csvName));
- scanner.useDelimiter(",");
- while (scanner.hasNext())
- {
- csv.add(scanner.next().toUpperCase());
- }
- scanner.close();
- }
- catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return csv;
- }
- public static ArrayList<String> getHeader(ArrayList<String> csv){
- ArrayList<String> header = new ArrayList<String>();
- for(int i=0; i<28; i++){
- header.add(csv.get(0));
- }
- return header;
- }
- public static BufferedImage getCroppedImage(BufferedImage source, double tolerance) {
- // Get our top-left pixel color as our "baseline" for cropping
- int baseColor = source.getRGB(0, 0);
- int width = source.getWidth();
- int height = source.getHeight();
- int topY = Integer.MAX_VALUE, topX = Integer.MAX_VALUE;
- int bottomY = -1, bottomX = -1;
- for(int y=0; y<height; y++) {
- for(int x=0; x<width; x++) {
- if (colorWithinTolerance(baseColor, source.getRGB(x, y), tolerance)) {
- if (x < topX) topX = x;
- if (y < topY) topY = y;
- if (x > bottomX) bottomX = x;
- if (y > bottomY) bottomY = y;
- }
- }
- }
- BufferedImage destination = new BufferedImage( (bottomX-topX+1),
- (bottomY-topY+1), BufferedImage.TYPE_INT_ARGB);
- destination.getGraphics().drawImage(source, 0, 0,
- destination.getWidth(), destination.getHeight(),
- topX, topY, bottomX, bottomY, null);
- return destination;
- }
- private static boolean colorWithinTolerance(int a, int b, double tolerance) {
- int aAlpha = (int)((a & 0xFF000000) >>> 24); // Alpha level
- int aRed = (int)((a & 0x00FF0000) >>> 16); // Red level
- int aGreen = (int)((a & 0x0000FF00) >>> 8); // Green level
- int aBlue = (int)(a & 0x000000FF); // Blue level
- int bAlpha = (int)((b & 0xFF000000) >>> 24); // Alpha level
- int bRed = (int)((b & 0x00FF0000) >>> 16); // Red level
- int bGreen = (int)((b & 0x0000FF00) >>> 8); // Green level
- int bBlue = (int)(b & 0x000000FF); // Blue level
- double distance = Math.sqrt((aAlpha-bAlpha)*(aAlpha-bAlpha) +
- (aRed-bRed)*(aRed-bRed) +
- (aGreen-bGreen)*(aGreen-bGreen) +
- (aBlue-bBlue)*(aBlue-bBlue));
- // 510.0 is the maximum distance between two colors
- // (0,0,0,0 -> 255,255,255,255)
- double percentAway = distance / 510.0d;
- return (percentAway > tolerance);
- }
- public static String MIdataCreator(ArrayList<String> info, String temp){
- /*
- //ziipcode
- String zipcode = info.get(2);
- zipcode = zipcode.replace("MI ", "");
- zipcode = zipcode.replace("-", " ");
- info.set(2, zipcode);
- //sex bullshit
- String sex="";
- if(info.get(14).equals("M")){
- sex="1";
- }
- else if(info.get(14).equals("F")){
- sex="2";
- }
- //heigh bullshit
- String height=info.get(10);
- char feet = height.charAt(0);
- char inch1 = height.charAt(1);
- char inch2 = height.charAt(2);
- String feetString = new StringBuilder().append(feet).toString();
- String inches = new StringBuilder().append(inch1).append(inch2).toString();
- int f = Integer.parseInt(feetString);
- int i = Integer.parseInt(inches);
- f=f*12;
- int heightTotal = f+i;
- //name shit
- String s = info.get(8);
- String[] names = s.split(" ");
- //date shit
- String bd = info.get(5);
- String[] bday = bd.split("-");
- bday[2] = "19"+bday[2];
- String fullBirthday = bday[0]+bday[1]+bday[2];
- String issue = info.get(12);
- String[] iss = issue.split("-");
- iss[2] = "20"+iss[2];
- String fullIssue = iss[0]+iss[1]+iss[2];
- String expiry = info.get(6);
- String[] exp = expiry.split("-");
- String fullExpire = exp[0]+exp[1]+exp[2];
- String city = info.get(1);
- city = city.replaceAll("\\\\","");
- System.out.println("CITY: " + city);
- */
- String t=temp;
- t=t.replace("DAQS 100 622 367 308", "DAQ"+info.get(1));
- t=t.replace("DCSSHAFOU", "DCS"+info.get(4));
- t=t.replace("DCTNATHANIELJAMES", "DCT"+info.get(2)+" "+info.get(3));
- t=t.replace("DBB04211994", "DBB"+info.get(8));
- t=t.replace("DBA04212017", "DBA"+info.get(10));
- t=t.replace("DBD12032013", "DBD"+info.get(9));
- t=t.replace("DBC1", "DBC"+info.get(15));
- //t=t.replace("DAU073 IN", "DAU"+"0"+heightTotal+" IN");
- //t=t.replace("DAYBLU", "DAY"+info.get(7));
- t=t.replace("DAG27901 MANHATTAN ST", "DAG"+info.get(5));
- t=t.replace("DAIST CLAIR SHORES", "DAI"+info.get(6));
- t=t.replace("DAK480813516", "DAK"+info.get(7));
- return t;
- }
- public static String OTCdataCreator(ArrayList<String> info, String temp){
- //remove all back slashes
- for(int i=0; i<info.size();i++){
- String s = info.get(i);
- s=s.replace("\\","");
- info.set(i, s);
- }
- String t=temp;
- t=t.replace("DAQ934870146", "DAQ"+info.get(5));
- t=t.replace("DAASMTIH,JOHN,J,", "DAA"+info.get(6)+","+info.get(7)+","+info.get(8)+",");
- t=t.replace("DBB02191996", "DBB"+info.get(21));
- t=t.replace("DBD02242014", "DBD"+info.get(23));
- t=t.replace("DBA02192018", "DBA"+info.get(20));
- t=t.replace("DBC1", "DBC"+info.get(22));
- t=t.replace("DAU073 IN", "DAU"+info.get(16).toUpperCase());
- t=t.replace("DAG111 1ST STREET", "DAG"+info.get(9));
- String secondZIP = info.get(12).substring(5,9);
- String firstZIP = info.get(12).substring(0, 5);
- t=t.replace("DAK72564 9654", "DAK"+firstZIP+" "+secondZIP);
- t=t.replace("DAISPRINGFIELD", "DAI"+info.get(10));
- //fuck
- return t;
- }
- public static String SCdataCreator(ArrayList<String> info, String temp){
- //remove all back slashes
- for(int i=0; i<info.size();i++){
- String s = info.get(i);
- s=s.replace("\\","");
- info.set(i, s);
- }
- String t=temp;
- t=t.replace("DAQ934870146", "DAQ"+info.get(1));
- t=t.replace("DAASMTIH,JOHN,J,", "DAA"+info.get(4)+","+info.get(2)+","+info.get(3)+",");
- t=t.replace("DBB02191996", "DBB"+info.get(8));
- t=t.replace("DBD02242014", "DBD"+info.get(9));
- t=t.replace("DBA02192018", "DBA"+info.get(10));
- t=t.replace("DBC1", "DBC"+info.get(15));
- t=t.replace("DAU073 IN", "DAU"+info.get(13).toUpperCase());
- t=t.replace("DAG111 1ST STREET", "DAG"+info.get(5));
- String secondZIP = info.get(7).substring(5,9);
- String firstZIP = info.get(7).substring(0, 5);
- t=t.replace("DAK72564 9654", "DAK"+firstZIP+" "+secondZIP);
- t=t.replace("DAISPRINGFIELD", "DAI"+info.get(6));
- t=t.replace("DAW130", "DAW"+info.get(14));
- //fuck
- return t;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement