diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..74c1fb3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,52 @@ +.DS_Store +*/target/** + +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/dictionaries + +# Sensitive or high-churn files: +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.xml +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml + +# Gradle: +.idea/**/gradle.xml +.idea/**/libraries + +# CMake +cmake-build-debug/ + +# Mongo Explorer plugin: +.idea/**/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..4d0fa38 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..f04d21a --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..6742b18 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..d889ffc --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# Shipping Labeler + +This is a simple Java App to convert PDF Files for a 62mm Labelprinter. Currently only a few German carriers are implemented. To change this, Pull-Requests are always welcome :) + + +## Usage + +Java 8 is required. + +Just download the latest release and execute the jar file with the terminal(macOS)/shell(Linux)/cmd(Windows) or whatever :) + +Command: +`java -jar shippinglabeler.jar` + +(Don't worry. A GUI is planned :D ) + +Now you can insert the path of your PDF label and select the carrier of it. After this the converted document will be shown in your default PDF-Viewer. + +Please print the document on a 62 x 184 (sometimes 62 x 209 ) label. Otherwise you risk that the barcodes on the labels aren't readable. \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..0e58e57 --- /dev/null +++ b/pom.xml @@ -0,0 +1,55 @@ + + + 4.0.0 + + de.flecktec + shippinglabeler + 1.0-SNAPSHOT + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.2 + + 1.8 + 1.8 + + + + maven-assembly-plugin + + + + de.flecktec.shippinglabeler.PDFMain + + + + jar-with-dependencies + + + + + make-assembly + package + + single + + + + + + + + + + org.apache.pdfbox + pdfbox + 2.0.4 + + + + \ No newline at end of file diff --git a/shippinglabeler.iml b/shippinglabeler.iml new file mode 100644 index 0000000..4364f22 --- /dev/null +++ b/shippinglabeler.iml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/de/flecktec/shippinglabeler/AmazonRetourLabelCreator.java b/src/main/java/de/flecktec/shippinglabeler/AmazonRetourLabelCreator.java new file mode 100644 index 0000000..7edb233 --- /dev/null +++ b/src/main/java/de/flecktec/shippinglabeler/AmazonRetourLabelCreator.java @@ -0,0 +1,52 @@ +package de.flecktec.shippinglabeler; + +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.PDPage; +import org.apache.pdfbox.pdmodel.PDPageContentStream; +import org.apache.pdfbox.pdmodel.common.PDRectangle; +import org.apache.pdfbox.pdmodel.graphics.image.JPEGFactory; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +/** + * Created by jonas on 01.09.17. + */ +public class AmazonRetourLabelCreator extends LabelCreator { + + @Override + public void createPDF(File path, File source) { + try ( final PDDocument targetdocument = new PDDocument()) { + BufferedImage img = ImageIO.read(source); + img = rotateImage(img, 90); + final PDPage singlePage = new PDPage(new PDRectangle(177f * mm, 56f * mm)); + targetdocument.addPage(singlePage); + final PDPageContentStream contentStream = new PDPageContentStream(targetdocument, singlePage); + + BufferedImage senderLabel = cropImage(img, new Rectangle(mmToPixels(12) , mmToPixels(6), mmToPixels(50) ,mmToPixels(22))); + contentStream.drawImage(JPEGFactory.createFromImage(targetdocument, senderLabel), 0*mm, 34*mm, 50*mm, 22 * mm); + + BufferedImage receiverLabel = cropImage(img, new Rectangle(mmToPixels(6) , mmToPixels(60), mmToPixels(50) ,mmToPixels(28))); + contentStream.drawImage(JPEGFactory.createFromImage(targetdocument, receiverLabel), 0*mm, 0*mm, 50*mm, 28 * mm); + + BufferedImage packetNumberLabel = cropImage(img, new Rectangle(mmToPixels(26) , mmToPixels(38), mmToPixels(46), mmToPixels(20))); + contentStream.drawImage(JPEGFactory.createFromImage(targetdocument, packetNumberLabel), 52*mm, 30*mm, 60*mm, 26 * mm); + + BufferedImage routingCodeLabel = cropImage(img, new Rectangle(mmToPixels(3) , mmToPixels(105), mmToPixels(53) ,mmToPixels(20))); + contentStream.drawImage(JPEGFactory.createFromImage(targetdocument, routingCodeLabel), 113*mm, 30*mm, 69*mm, 26 * mm); + + BufferedImage rmaCodeLabel = cropImage(img, new Rectangle(mmToPixels(15) , mmToPixels(127), mmToPixels(72) ,mmToPixels(19))); + contentStream.drawImage(JPEGFactory.createFromImage(targetdocument, rmaCodeLabel), 62*mm, 0*mm, 93*mm, 25 * mm); + + + contentStream.close(); + targetdocument.save(path); + } catch (IOException e) { + e.printStackTrace(); + } + + } +} diff --git a/src/main/java/de/flecktec/shippinglabeler/Controller/MainViewController.java b/src/main/java/de/flecktec/shippinglabeler/Controller/MainViewController.java new file mode 100644 index 0000000..fc88a78 --- /dev/null +++ b/src/main/java/de/flecktec/shippinglabeler/Controller/MainViewController.java @@ -0,0 +1,7 @@ +package de.flecktec.shippinglabeler.Controller; + +/** + * Created by jonas on 04.10.17. + */ +public class MainViewController { +} diff --git a/src/main/java/de/flecktec/shippinglabeler/DHLLabelCreator.java b/src/main/java/de/flecktec/shippinglabeler/DHLLabelCreator.java new file mode 100644 index 0000000..18eb9fe --- /dev/null +++ b/src/main/java/de/flecktec/shippinglabeler/DHLLabelCreator.java @@ -0,0 +1,85 @@ +package de.flecktec.shippinglabeler; + +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.PDPage; +import org.apache.pdfbox.pdmodel.PDPageContentStream; +import org.apache.pdfbox.pdmodel.PDPageTree; +import org.apache.pdfbox.pdmodel.common.PDRectangle; +import org.apache.pdfbox.pdmodel.graphics.image.JPEGFactory; +import org.apache.pdfbox.rendering.ImageType; +import org.apache.pdfbox.rendering.PDFRenderer; + +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +/** + * Created by jonas on 13.08.17. + */ +public class DHLLabelCreator extends LabelCreator { + + public void createPDF(File path, File source) { + System.out.println("Creating PDF"); + try (PDDocument sourceDocument = PDDocument.load(source); final PDDocument targetdocument = new PDDocument()) + { + PDFRenderer pdfRenderer = new PDFRenderer(sourceDocument); + for (int page = 0; page < sourceDocument.getNumberOfPages(); ++page) + { + System.out.println("Rendering page "+ page); + sourceDocument.getPage(page).setRotation(90); + BufferedImage bim = pdfRenderer.renderImageWithDPI(page, dpi, ImageType.RGB); + System.out.println(bim.getWidth()); + System.out.println(mmToPixels(297)); + System.out.println("Creating new page"); + final PDPage singlePage = new PDPage(new PDRectangle(177f * mm, 56f * mm)); + targetdocument.addPage(singlePage); + final PDPageContentStream contentStream = new PDPageContentStream(targetdocument, singlePage); + /*BufferedImage adressLabel = cropImage(bim, new Rectangle(mmToPixels(160) , mmToPixels(16), mmToPixels(106) ,mmToPixels(53))); + contentStream.drawImage(JPEGFactory.createFromImage(targetdocument, adressLabel), 0*mm, 0*mm, 113*mm, 56.08f * mm); + BufferedImage barcode1 = cropImage(bim, new Rectangle(mmToPixels(185) , mmToPixels(131), mmToPixels(55) ,mmToPixels(25))); + contentStream.drawImage(JPEGFactory.createFromImage(targetdocument, barcode1), 116*mm, 28*mm, 55*mm, 25 * mm); + BufferedImage barcode2 = cropImage(bim, new Rectangle(mmToPixels(185) , mmToPixels(164), mmToPixels(55) ,mmToPixels(25))); + contentStream.drawImage(JPEGFactory.createFromImage(targetdocument, barcode2), 116*mm, 0*mm, 55*mm, 25 * mm);*/ + + BufferedImage adressLabel = cropImage(bim, new Rectangle(mmToPixels(160) , mmToPixels(16), mmToPixels(106) ,mmToPixels(53))); + contentStream.drawImage(JPEGFactory.createFromImage(targetdocument, adressLabel), 0*mm, 0*mm, 113*mm, 56.08f * mm); + + BufferedImage barcode1 = cropImage(bim, new Rectangle(mmToPixels(185) , mmToPixels(131), mmToPixels(55) ,mmToPixels(25))); + contentStream.drawImage(JPEGFactory.createFromImage(targetdocument, barcode1), 116*mm, 30*mm, 55*mm, 25 * mm); + + BufferedImage barcode2 = cropImage(bim, new Rectangle(mmToPixels(185) , mmToPixels(164), mmToPixels(55) ,mmToPixels(25))); + contentStream.drawImage(JPEGFactory.createFromImage(targetdocument, barcode2), 116*mm, 0*mm, 55*mm, 25 * mm); + + contentStream.close(); + + + } + + targetdocument.save(path); + /*for(Smarthomeitem item : smarthomeitems) { + final PDPage singlePage = new PDPage(new PDRectangle(62 * mm, 25 * mm)); + document.addPage(singlePage); + final PDPageContentStream contentStream = new PDPageContentStream(document, singlePage); + String json = new Gson().toJson(item); + BufferedImage qr = createQRImage(json, 250); + contentStream.drawImage(JPEGFactory.createFromImage(document, qr), 2*mm, 3*mm, 19*mm, 19 * mm); + contentStream.beginText(); + contentStream.setFont(PDType1Font.COURIER_BOLD, 8); + contentStream.newLineAtOffset(22* mm, 14* mm); + contentStream.showText(item.getName()); + contentStream.endText(); + contentStream.close(); + } + document.save(path); + System.out.println("Finished"); */ + + } + catch (IOException ioEx) + { + ioEx.printStackTrace(); + } + } + + +} diff --git a/src/main/java/de/flecktec/shippinglabeler/DHLRetoureLabelCreator.java b/src/main/java/de/flecktec/shippinglabeler/DHLRetoureLabelCreator.java new file mode 100644 index 0000000..6c28f3a --- /dev/null +++ b/src/main/java/de/flecktec/shippinglabeler/DHLRetoureLabelCreator.java @@ -0,0 +1,83 @@ +package de.flecktec.shippinglabeler; + +import de.flecktec.shippinglabeler.LabelCreator; +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.PDPage; +import org.apache.pdfbox.pdmodel.PDPageContentStream; +import org.apache.pdfbox.pdmodel.common.PDRectangle; +import org.apache.pdfbox.pdmodel.graphics.image.JPEGFactory; +import org.apache.pdfbox.rendering.ImageType; +import org.apache.pdfbox.rendering.PDFRenderer; + +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +/** + * Created by jonas on 13.08.17. + */ +public class DHLRetoureLabelCreator extends LabelCreator { + + public void createPDF(File path, File source) { + System.out.println("Creating PDF"); + try (PDDocument sourceDocument = PDDocument.load(source); final PDDocument targetdocument = new PDDocument()) + { + PDFRenderer pdfRenderer = new PDFRenderer(sourceDocument); + for (int page = 0; page < sourceDocument.getNumberOfPages(); ++page) + { + System.out.println("Rendering page "+ page); + sourceDocument.getPage(page).setRotation(90); + BufferedImage bim = pdfRenderer.renderImageWithDPI(page, dpi, ImageType.RGB); + System.out.println(bim.getWidth()); + System.out.println(mmToPixels(297)); + System.out.println("Creating new page"); + final PDPage singlePage = new PDPage(new PDRectangle(202f * mm, 56f * mm)); + targetdocument.addPage(singlePage); + final PDPageContentStream contentStream = new PDPageContentStream(targetdocument, singlePage); + + BufferedImage adressLabel = cropImage(bim, new Rectangle(mmToPixels(165) , mmToPixels(16), mmToPixels(106) ,mmToPixels(53))); + contentStream.drawImage(JPEGFactory.createFromImage(targetdocument, adressLabel), 0*mm, 0*mm, 113*mm, 56.08f * mm); + + BufferedImage barcode1 = cropImage(bim, new Rectangle(mmToPixels(190) , mmToPixels(134), mmToPixels(55) ,mmToPixels(25))); + contentStream.drawImage(JPEGFactory.createFromImage(targetdocument, barcode1), 116*mm, 30*mm, 55*mm, 25 * mm); + + BufferedImage barcode2 = cropImage(bim, new Rectangle(mmToPixels(190) , mmToPixels(167), mmToPixels(55) ,mmToPixels(25))); + contentStream.drawImage(JPEGFactory.createFromImage(targetdocument, barcode2), 116*mm, 0*mm, 55*mm, 25 * mm); + + BufferedImage barcode3 = cropImage(bim, new Rectangle(mmToPixels(200) , mmToPixels(90), mmToPixels(35) ,mmToPixels(21))); + barcode3 = rotateImage(barcode3, -90); + contentStream.drawImage(JPEGFactory.createFromImage(targetdocument, barcode3), 181*mm, 10*mm, 21*mm, 35 * mm); + + contentStream.close(); + + + } + + targetdocument.save(path); + /*for(Smarthomeitem item : smarthomeitems) { + final PDPage singlePage = new PDPage(new PDRectangle(62 * mm, 25 * mm)); + document.addPage(singlePage); + final PDPageContentStream contentStream = new PDPageContentStream(document, singlePage); + String json = new Gson().toJson(item); + BufferedImage qr = createQRImage(json, 250); + contentStream.drawImage(JPEGFactory.createFromImage(document, qr), 2*mm, 3*mm, 19*mm, 19 * mm); + contentStream.beginText(); + contentStream.setFont(PDType1Font.COURIER_BOLD, 8); + contentStream.newLineAtOffset(22* mm, 14* mm); + contentStream.showText(item.getName()); + contentStream.endText(); + contentStream.close(); + } + document.save(path); + System.out.println("Finished"); */ + + } + catch (IOException ioEx) + { + ioEx.printStackTrace(); + } + } + + +} diff --git a/src/main/java/de/flecktec/shippinglabeler/DPDLabelCreator.java b/src/main/java/de/flecktec/shippinglabeler/DPDLabelCreator.java new file mode 100644 index 0000000..18a16b1 --- /dev/null +++ b/src/main/java/de/flecktec/shippinglabeler/DPDLabelCreator.java @@ -0,0 +1,60 @@ +package de.flecktec.shippinglabeler; + +import de.flecktec.shippinglabeler.LabelCreator; +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.PDPage; +import org.apache.pdfbox.pdmodel.PDPageContentStream; +import org.apache.pdfbox.pdmodel.PDPageTree; +import org.apache.pdfbox.pdmodel.common.PDRectangle; +import org.apache.pdfbox.pdmodel.graphics.image.JPEGFactory; +import org.apache.pdfbox.rendering.ImageType; +import org.apache.pdfbox.rendering.PDFRenderer; + +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +/** + * Created by jonas on 20.08.17. + */ +public class DPDLabelCreator extends LabelCreator{ + + public void createPDF(File path, File source) { + System.out.println("Creating PDF"); + try (PDDocument sourceDocument = PDDocument.load(source); final PDDocument targetdocument = new PDDocument()) + { + PDPageTree pdPages = sourceDocument.getDocumentCatalog().getPages(); + PDFRenderer pdfRenderer = new PDFRenderer(sourceDocument); + System.out.println("Rendering page "); + BufferedImage bim = pdfRenderer.renderImageWithDPI(0, dpi, ImageType.RGB); + System.out.println(bim.getWidth()); + System.out.println(mmToPixels(297)); + System.out.println("Creating new page"); + final PDPage singlePage = new PDPage(new PDRectangle(202f * mm, 56f * mm)); + targetdocument.addPage(singlePage); + final PDPageContentStream contentStream = new PDPageContentStream(targetdocument, singlePage); + BufferedImage adressLabel = cropImage(bim, new Rectangle(mmToPixels(5) , mmToPixels(5), mmToPixels(99) ,mmToPixels(56))); + contentStream.drawImage(JPEGFactory.createFromImage(targetdocument, adressLabel), 0*mm, 0*mm, 99*mm, 56 * mm); + BufferedImage machineLabel = cropImage(bim, new Rectangle(mmToPixels(5) , mmToPixels(85), mmToPixels(99) ,mmToPixels(61))); + contentStream.drawImage(JPEGFactory.createFromImage(targetdocument, machineLabel), 105*mm, 0*mm, 91*mm, 56 * mm); + /* BufferedImage machineLabel = cropImage(bim, new Rectangle(mmToPixels(7) , mmToPixels(36), mmToPixels(92) ,mmToPixels(53))); + contentStream.drawImage(JPEGFactory.createFromImage(targetdocument, machineLabel), 0*mm, 2*mm, 92*mm, 53 * mm); + BufferedImage sender = cropImage(bim, new Rectangle(mmToPixels(186.5) , mmToPixels(19), mmToPixels(17) ,mmToPixels(80))); + contentStream.drawImage(JPEGFactory.createFromImage(targetdocument, sender), 94*mm, 41*mm, 71*mm, 15 * mm); + BufferedImage receiver = cropImage(bim, new Rectangle(mmToPixels(112) , mmToPixels(56), mmToPixels(75) ,mmToPixels(43))); + contentStream.drawImage(JPEGFactory.createFromImage(targetdocument, receiver), 94*mm, 0*mm, 79*mm, 42 * mm);*/ + contentStream.close(); + + + + targetdocument.save(path); + + + } + catch (IOException ioEx) + { + ioEx.printStackTrace(); + } + } +} diff --git a/src/main/java/de/flecktec/shippinglabeler/GLSLabelCreator.java b/src/main/java/de/flecktec/shippinglabeler/GLSLabelCreator.java new file mode 100644 index 0000000..d32372c --- /dev/null +++ b/src/main/java/de/flecktec/shippinglabeler/GLSLabelCreator.java @@ -0,0 +1,58 @@ +package de.flecktec.shippinglabeler; + +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.PDPage; +import org.apache.pdfbox.pdmodel.PDPageContentStream; +import org.apache.pdfbox.pdmodel.PDPageTree; +import org.apache.pdfbox.pdmodel.common.PDRectangle; +import org.apache.pdfbox.pdmodel.graphics.image.JPEGFactory; +import org.apache.pdfbox.rendering.ImageType; +import org.apache.pdfbox.rendering.PDFRenderer; + +import java.awt.*; +import java.awt.geom.AffineTransform; +import java.awt.image.AffineTransformOp; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +/** + * Created by jonas on 20.08.17. + */ +public class GLSLabelCreator extends LabelCreator{ + + public void createPDF(File path, File source) { + System.out.println("Creating PDF"); + try (PDDocument sourceDocument = PDDocument.load(source); final PDDocument targetdocument = new PDDocument()) + { + PDPageTree pdPages = sourceDocument.getDocumentCatalog().getPages(); + PDFRenderer pdfRenderer = new PDFRenderer(sourceDocument); + System.out.println("Rendering page "); + BufferedImage bim = pdfRenderer.renderImageWithDPI(0, dpi, ImageType.RGB); + System.out.println(bim.getWidth()); + System.out.println(mmToPixels(297)); + System.out.println("Creating new page"); + final PDPage singlePage = new PDPage(new PDRectangle(177f * mm, 56f * mm)); + targetdocument.addPage(singlePage); + final PDPageContentStream contentStream = new PDPageContentStream(targetdocument, singlePage); + BufferedImage machineLabel = cropImage(bim, new Rectangle(mmToPixels(7) , mmToPixels(36), mmToPixels(92) ,mmToPixels(53))); + contentStream.drawImage(JPEGFactory.createFromImage(targetdocument, machineLabel), 0*mm, 2*mm, 92*mm, 53 * mm); + BufferedImage sender = cropImage(bim, new Rectangle(mmToPixels(186.5) , mmToPixels(19), mmToPixels(17) ,mmToPixels(80))); + sender = rotateImage(sender, -90); + contentStream.drawImage(JPEGFactory.createFromImage(targetdocument, sender), 94*mm, 41*mm, 71*mm, 15 * mm); + BufferedImage receiver = cropImage(bim, new Rectangle(mmToPixels(112) , mmToPixels(56), mmToPixels(75) ,mmToPixels(43))); + contentStream.drawImage(JPEGFactory.createFromImage(targetdocument, receiver), 94*mm, 0*mm, 79*mm, 42 * mm); + contentStream.close(); + + + + targetdocument.save(path); + + + } + catch (IOException ioEx) + { + ioEx.printStackTrace(); + } + } +} diff --git a/src/main/java/de/flecktec/shippinglabeler/LabelCreator.java b/src/main/java/de/flecktec/shippinglabeler/LabelCreator.java new file mode 100644 index 0000000..f9addde --- /dev/null +++ b/src/main/java/de/flecktec/shippinglabeler/LabelCreator.java @@ -0,0 +1,51 @@ +package de.flecktec.shippinglabeler; + +import java.awt.*; +import java.awt.geom.AffineTransform; +import java.awt.geom.Point2D; +import java.awt.image.BufferedImage; +import java.io.File; + +/** + * Created by jonas on 19.08.17. + */ +public abstract class LabelCreator { + + final static float mm = 72 / 25.4f; + final static float dpi = 300; + + public abstract void createPDF(File path, File source); + + protected static int mmToPixels(double mm) { + return (int)(mm / 25.4 * dpi); + } + protected static BufferedImage cropImage(BufferedImage src, Rectangle rect) { + BufferedImage dest = src.getSubimage(rect.x, rect.y, rect.width, rect.height); + return dest; + } + public static BufferedImage rotateImage(BufferedImage image, double angle) { + + // Determine the size of the rotated image + double theta = Math.toRadians(angle); + double cos = Math.abs(Math.cos(theta)); + double sin = Math.abs(Math.sin(theta)); + double width = image.getWidth(); + double height = image.getHeight(); + int w = (int)(width * cos + height * sin); + int h = (int)(width * sin + height * cos); + + BufferedImage out = new BufferedImage(w, h, image.getType()); + Graphics2D g2 = out.createGraphics(); + g2.fillRect(0,0,w,h); + double x = w/2; + double y = h/2; + AffineTransform at = AffineTransform.getRotateInstance(theta, x, y); + x = (w - width)/2; + y = (h - height)/2; + at.translate(x, y); + g2.drawRenderedImage(image, at); + g2.dispose(); + return out; + } + +} diff --git a/src/main/java/de/flecktec/shippinglabeler/LabelCreatorFactory.java b/src/main/java/de/flecktec/shippinglabeler/LabelCreatorFactory.java new file mode 100644 index 0000000..99ca1ae --- /dev/null +++ b/src/main/java/de/flecktec/shippinglabeler/LabelCreatorFactory.java @@ -0,0 +1,28 @@ +package de.flecktec.shippinglabeler; + +import javafx.scene.control.Label; +import sun.reflect.generics.reflectiveObjects.NotImplementedException; + +/** + * Created by jonas on 19.08.17. + */ +public class LabelCreatorFactory { + + public static LabelCreator buildCreator(LabelType type) { + assert type != null; + if(type == LabelType.DHL_Private) { + return new DHLLabelCreator(); + } else if(type == LabelType.GLS_Private) { + return new GLSLabelCreator(); + } else if(type == LabelType.DPD_PRIVATE) { + return new DPDLabelCreator(); + } else if(type == LabelType.AmazonDHLRetoure_Private) { + return new AmazonRetourLabelCreator(); + } else if(type == LabelType.DHL_RETOURE) { + return new DHLRetoureLabelCreator(); + } + else { + throw new NotImplementedException(); + } + } +} diff --git a/src/main/java/de/flecktec/shippinglabeler/LabelType.java b/src/main/java/de/flecktec/shippinglabeler/LabelType.java new file mode 100644 index 0000000..97d8290 --- /dev/null +++ b/src/main/java/de/flecktec/shippinglabeler/LabelType.java @@ -0,0 +1,36 @@ +package de.flecktec.shippinglabeler; + +import sun.reflect.generics.reflectiveObjects.NotImplementedException; + +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; + +/** + * Created by jonas on 19.08.17. + */ +public enum LabelType { + DHL_Private(1), GLS_Private(2), DPD_PRIVATE(3), AmazonDHLRetoure_Private(4), DHL_RETOURE(5); + + private static final Map lookup + = new HashMap(); + + static { + for(LabelType w : EnumSet.allOf(LabelType.class)) + lookup.put(w.getCode(), w); + } + + private int code; + + LabelType(int code) { + this.code = code; + } + + private int getCode() { + return code; + } + + public static LabelType get(int code) { + return lookup.get(code); + } +} diff --git a/src/main/java/de/flecktec/shippinglabeler/PDFMain.java b/src/main/java/de/flecktec/shippinglabeler/PDFMain.java new file mode 100644 index 0000000..00f6202 --- /dev/null +++ b/src/main/java/de/flecktec/shippinglabeler/PDFMain.java @@ -0,0 +1,45 @@ +package de.flecktec.shippinglabeler; + + +import java.awt.*; +import java.io.File; +import java.io.IOException; +import java.util.Scanner; + +/** + * Created by Jonas Fleck on 13.08.17. + */ +public class PDFMain +{ + + public static void main (String[] args) throws IOException { + while(true) { + try { + menue(); + } catch (Exception e) { + e.printStackTrace(); + } + + } + + + } + + private static void menue() throws IOException { + File pdfPath = new File(System.getProperty("java.io.tmpdir") + "/shippingLabel.pdf"); + System.out.print("Please enter full path of original label (macOS Drag&Drop into Terminal:"); + Scanner sc = new Scanner(System.in); + File sourePath = new File(sc.next()); + System.out.println("Please select your label type:"); + System.out.println("1: DHL-Private"); + System.out.println("2: GLS-Private"); + System.out.println("3: DPD-Private (62 x 209)"); + System.out.println("4: AmazonDHL-Retoure (Gif File)"); + System.out.println("5: DHL-Retoure (62 x 209)"); + LabelCreator creator = LabelCreatorFactory.buildCreator(LabelType.get(sc.nextInt())); + creator.createPDF(pdfPath, sourePath); + Desktop.getDesktop().open(pdfPath); + + } +} + diff --git a/src/main/resources/view/MainView.fxml b/src/main/resources/view/MainView.fxml new file mode 100644 index 0000000..aa90ab3 --- /dev/null +++ b/src/main/resources/view/MainView.fxml @@ -0,0 +1,14 @@ + + + + + + + + + + + diff --git a/target/classes/de/flecktec/shippinglabeler/AmazonRetourLabelCreator.class b/target/classes/de/flecktec/shippinglabeler/AmazonRetourLabelCreator.class new file mode 100644 index 0000000..bc158d9 Binary files /dev/null and b/target/classes/de/flecktec/shippinglabeler/AmazonRetourLabelCreator.class differ diff --git a/target/classes/de/flecktec/shippinglabeler/Controller/MainViewController.class b/target/classes/de/flecktec/shippinglabeler/Controller/MainViewController.class new file mode 100644 index 0000000..264e3bd Binary files /dev/null and b/target/classes/de/flecktec/shippinglabeler/Controller/MainViewController.class differ diff --git a/target/classes/de/flecktec/shippinglabeler/DHLLabelCreator.class b/target/classes/de/flecktec/shippinglabeler/DHLLabelCreator.class new file mode 100644 index 0000000..b02288a Binary files /dev/null and b/target/classes/de/flecktec/shippinglabeler/DHLLabelCreator.class differ diff --git a/target/classes/de/flecktec/shippinglabeler/DHLRetoureLabelCreator.class b/target/classes/de/flecktec/shippinglabeler/DHLRetoureLabelCreator.class new file mode 100644 index 0000000..e6f97bc Binary files /dev/null and b/target/classes/de/flecktec/shippinglabeler/DHLRetoureLabelCreator.class differ diff --git a/target/classes/de/flecktec/shippinglabeler/DPDLabelCreator.class b/target/classes/de/flecktec/shippinglabeler/DPDLabelCreator.class new file mode 100644 index 0000000..00e76aa Binary files /dev/null and b/target/classes/de/flecktec/shippinglabeler/DPDLabelCreator.class differ diff --git a/target/classes/de/flecktec/shippinglabeler/GLSLabelCreator.class b/target/classes/de/flecktec/shippinglabeler/GLSLabelCreator.class new file mode 100644 index 0000000..da1686b Binary files /dev/null and b/target/classes/de/flecktec/shippinglabeler/GLSLabelCreator.class differ diff --git a/target/classes/de/flecktec/shippinglabeler/LabelCreator.class b/target/classes/de/flecktec/shippinglabeler/LabelCreator.class new file mode 100644 index 0000000..96b9e85 Binary files /dev/null and b/target/classes/de/flecktec/shippinglabeler/LabelCreator.class differ diff --git a/target/classes/de/flecktec/shippinglabeler/LabelCreatorFactory.class b/target/classes/de/flecktec/shippinglabeler/LabelCreatorFactory.class new file mode 100644 index 0000000..b51d8ac Binary files /dev/null and b/target/classes/de/flecktec/shippinglabeler/LabelCreatorFactory.class differ diff --git a/target/classes/de/flecktec/shippinglabeler/LabelType.class b/target/classes/de/flecktec/shippinglabeler/LabelType.class new file mode 100644 index 0000000..f9d8d3c Binary files /dev/null and b/target/classes/de/flecktec/shippinglabeler/LabelType.class differ diff --git a/target/classes/de/flecktec/shippinglabeler/PDFMain.class b/target/classes/de/flecktec/shippinglabeler/PDFMain.class new file mode 100644 index 0000000..6bb2445 Binary files /dev/null and b/target/classes/de/flecktec/shippinglabeler/PDFMain.class differ diff --git a/target/classes/view/MainView.fxml b/target/classes/view/MainView.fxml new file mode 100644 index 0000000..aa90ab3 --- /dev/null +++ b/target/classes/view/MainView.fxml @@ -0,0 +1,14 @@ + + + + + + + + + + + diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties new file mode 100644 index 0000000..18dd65f --- /dev/null +++ b/target/maven-archiver/pom.properties @@ -0,0 +1,5 @@ +#Generated by Maven +#Wed Oct 04 12:30:19 CEST 2017 +version=1.0-SNAPSHOT +groupId=de.flecktec +artifactId=shippinglabeler diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..210d7c0 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,10 @@ +de/flecktec/shippinglabeler/DHLRetoureLabelCreator.class +de/flecktec/shippinglabeler/DPDLabelCreator.class +de/flecktec/shippinglabeler/GLSLabelCreator.class +de/flecktec/shippinglabeler/Controller/MainViewController.class +de/flecktec/shippinglabeler/LabelCreator.class +de/flecktec/shippinglabeler/PDFMain.class +de/flecktec/shippinglabeler/DHLLabelCreator.class +de/flecktec/shippinglabeler/AmazonRetourLabelCreator.class +de/flecktec/shippinglabeler/LabelType.class +de/flecktec/shippinglabeler/LabelCreatorFactory.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..8bc813b --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,10 @@ +/Users/jonas/Developer/shippinglabeler/src/main/java/de/flecktec/shippinglabeler/LabelType.java +/Users/jonas/Developer/shippinglabeler/src/main/java/de/flecktec/shippinglabeler/DPDLabelCreator.java +/Users/jonas/Developer/shippinglabeler/src/main/java/de/flecktec/shippinglabeler/DHLRetoureLabelCreator.java +/Users/jonas/Developer/shippinglabeler/src/main/java/de/flecktec/shippinglabeler/LabelCreator.java +/Users/jonas/Developer/shippinglabeler/src/main/java/de/flecktec/shippinglabeler/DHLLabelCreator.java +/Users/jonas/Developer/shippinglabeler/src/main/java/de/flecktec/shippinglabeler/LabelCreatorFactory.java +/Users/jonas/Developer/shippinglabeler/src/main/java/de/flecktec/shippinglabeler/GLSLabelCreator.java +/Users/jonas/Developer/shippinglabeler/src/main/java/de/flecktec/shippinglabeler/AmazonRetourLabelCreator.java +/Users/jonas/Developer/shippinglabeler/src/main/java/de/flecktec/shippinglabeler/Controller/MainViewController.java +/Users/jonas/Developer/shippinglabeler/src/main/java/de/flecktec/shippinglabeler/PDFMain.java diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..e69de29 diff --git a/target/shippinglabeler-1.0-SNAPSHOT-jar-with-dependencies.jar b/target/shippinglabeler-1.0-SNAPSHOT-jar-with-dependencies.jar new file mode 100644 index 0000000..1791c8b Binary files /dev/null and b/target/shippinglabeler-1.0-SNAPSHOT-jar-with-dependencies.jar differ diff --git a/target/shippinglabeler-1.0-SNAPSHOT.jar b/target/shippinglabeler-1.0-SNAPSHOT.jar new file mode 100644 index 0000000..caf7a88 Binary files /dev/null and b/target/shippinglabeler-1.0-SNAPSHOT.jar differ