started API clean up
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package de.muehlencord.shared.pdf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -11,15 +12,53 @@ public class Invoice {
|
||||
|
||||
private final List<InvoiceLine> invoiceLines;
|
||||
|
||||
private Date invoiceDate;
|
||||
private String customerNumber;
|
||||
private String invoiceNumber;
|
||||
private String logo = null;
|
||||
|
||||
public Invoice() {
|
||||
this.invoiceLines = new ArrayList<>();
|
||||
this.invoiceLines = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addInvoiceLine(InvoiceLine il) {
|
||||
this.invoiceLines.add(il);
|
||||
}
|
||||
|
||||
/* *** getter / setter *** */
|
||||
public List<InvoiceLine> getInvoiceLines() {
|
||||
return invoiceLines;
|
||||
}
|
||||
}
|
||||
|
||||
public String getLogo() {
|
||||
return logo;
|
||||
}
|
||||
|
||||
public void setLogo(String logo) {
|
||||
this.logo = logo;
|
||||
}
|
||||
|
||||
public Date getInvoiceDate() {
|
||||
return invoiceDate;
|
||||
}
|
||||
|
||||
public void setInvoiceDate(Date invoiceDate) {
|
||||
this.invoiceDate = invoiceDate;
|
||||
}
|
||||
|
||||
public String getCustomerNumber() {
|
||||
return customerNumber;
|
||||
}
|
||||
|
||||
public void setCustomerNumber(String customerNumber) {
|
||||
this.customerNumber = customerNumber;
|
||||
}
|
||||
|
||||
public String getInvoiceNumber() {
|
||||
return invoiceNumber;
|
||||
}
|
||||
|
||||
public void setInvoiceNumber(String invoiceNumber) {
|
||||
this.invoiceNumber = invoiceNumber;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package de.muehlencord.shared.pdf;
|
||||
|
||||
import de.muehlencord.shared.pdf.util.ImageUtil;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.Template;
|
||||
import freemarker.template.TemplateExceptionHandler;
|
||||
@ -26,70 +27,67 @@ public class PDFDocumentTest {
|
||||
public void testToJson() throws FileNotFoundException, IOException, ConfigurationException, TemplateException {
|
||||
System.out.println("testToJson");
|
||||
PDFDocument doc = new PDFDocument();
|
||||
doc.addFont("bold", new Font("Helvetica-Bold", 12, 2));
|
||||
doc.addFont("helv12", new Font("Helvetica", 12, 2));
|
||||
doc.addFont("bold", new PDFFont("Helvetica-Bold", 12, 2));
|
||||
doc.addFont("helv12", new PDFFont("Helvetica", 12, 2));
|
||||
|
||||
doc.setPaperSize(PaperSize.A4);
|
||||
TextContent addressContent = new TextContent(doc, 40F, 692F, "Max Mustermann")
|
||||
doc.setPaperSize(PDFPaperSize.A4);
|
||||
PDFTextContent addressContent = new PDFTextContent(doc, 40F, 692F, "Max Mustermann")
|
||||
.addLine("Musterstraße 123")
|
||||
.addLine("12345 Musterhausen");
|
||||
doc.addContent(addressContent);
|
||||
|
||||
String fileName = "c:/temp/logo-verkehrsverein-hoevelh.jpg";
|
||||
BufferedImage image = ImageIO.read(new File(fileName));
|
||||
ImageContent logoContent = new ImageContent(doc, 400F, 700F, 0.6F, image);
|
||||
PDFImageContent logoContent = new PDFImageContent(doc, 400F, 700F, 0.6F, "${invoice.logo}");
|
||||
doc.addContent(logoContent);
|
||||
|
||||
|
||||
TextContent informationContent = new TextContent(doc, 400F, 662F);
|
||||
PDFTextContent informationContent = new PDFTextContent(doc, 400F, 662F);
|
||||
informationContent.addLine("Anzeigenabrechnung", "bold");
|
||||
informationContent.addLine("Veronika Mühlencord", "helv12");
|
||||
informationContent.addLine("Telefon: 05257/940154", "helv12");
|
||||
informationContent.addLine("Telefax: 05257/940156", "helv12");
|
||||
informationContent.addLine();
|
||||
informationContent.addLine("Hövelhof, den ${invoiceDate?date}", "bold");
|
||||
informationContent.addLine("Hövelhof, den ${invoice.invoiceDate?date}", "bold");
|
||||
doc.addContent(informationContent);
|
||||
|
||||
TableContent informationContent2 = new TableContent(doc, doc.getStandardFont());
|
||||
PDFTableContent informationContent2 = new PDFTableContent(doc, doc.getStandardFont());
|
||||
informationContent2.getHeaders()
|
||||
.add("Kunden-Nr", 100)
|
||||
.add("${customerNumber}", 100);
|
||||
informationContent2.addLine("Rechnungs-Nr.:", "${invoiceNumber}");
|
||||
informationContent2.addLine("Ausgabe: ", "Dezember");
|
||||
informationContent2.addLine("Rechnungsdatum:", "${invoiceDate?date}");
|
||||
.add("${invoice.customerNumber}", 100);
|
||||
informationContent2.addRow("Rechnungs-Nr.:", "${invoice.invoiceNumber}")
|
||||
.addRow("Ausgabe: ", "Dezember")
|
||||
.addRow("Rechnungsdatum:", "${invoice.invoiceDate?date}");
|
||||
doc.addContent(informationContent2);
|
||||
|
||||
TextContent invoiceInfoInformation = new TextContent(doc, 40F, 442F, "Sehr geehrter Anzeigenkunde, ")
|
||||
PDFTextContent invoiceInfoInformation = new PDFTextContent(doc, 40F, 442F, "Sehr geehrter Anzeigenkunde, ")
|
||||
.addLine()
|
||||
.addLine()
|
||||
.addLine("Wir danken für den Auftrag und bitten um Erledigung der folgenden Anzeigenabrechnung")
|
||||
.addLine();
|
||||
doc.addContent(invoiceInfoInformation);
|
||||
|
||||
TableContent invoiceLines = new TableContent(doc, doc.getFontByAlias("bold"));
|
||||
PDFTableContent invoiceLines = new PDFTableContent(doc, doc.getFontByAlias("bold"));
|
||||
invoiceLines.getHeaders()
|
||||
.add("Menge", 50, 10F)
|
||||
.add("Beschreibung", 300, 10F)
|
||||
.add(new Text("Einzelpreis", TextAlignment.RIGHT), 80)
|
||||
.add(new Text("Summe", TextAlignment.RIGHT), 80);
|
||||
invoiceLines.addTextLine(
|
||||
new Text("1000", TextAlignment.RIGHT),
|
||||
new Text("Anzeige Hövelhofer Rundschau"),
|
||||
new Text("10,00 €", TextAlignment.RIGHT),
|
||||
new Text("10,00 €", TextAlignment.RIGHT));
|
||||
invoiceLines.addTextLine(
|
||||
new Text("${invoiceline.amount}", TextAlignment.RIGHT),
|
||||
new Text("${invoiceline.description}"),
|
||||
new Text("${invoiceline.price}", TextAlignment.RIGHT),
|
||||
new Text("${invoiceline.total}", TextAlignment.RIGHT)).createList("invoiceLines", "invoiceline");
|
||||
invoiceLines.addTextLine(
|
||||
new Text("2", TextAlignment.RIGHT),
|
||||
new Text("Anzeige Hövelhofer Rundschau"),
|
||||
new Text("10,00 €", TextAlignment.RIGHT),
|
||||
new Text("20,00 €", TextAlignment.RIGHT));
|
||||
.add("Menge", 50)
|
||||
.add("Beschreibung", 300)
|
||||
.add("Einzelpreis", 80, PDFTextAlignment.RIGHT)
|
||||
.add("Summe", 80, PDFTextAlignment.RIGHT);
|
||||
invoiceLines.addRow()
|
||||
.addColumn("1000", PDFTextAlignment.RIGHT, 5F)
|
||||
.addColumn("Anzeige Hövelhofer Rundschau")
|
||||
.addColumn("10,00 €", PDFTextAlignment.RIGHT)
|
||||
.addColumn("10,00 €", PDFTextAlignment.RIGHT);
|
||||
invoiceLines.addListRow("invoice.invoiceLines", "invoiceline")
|
||||
.addColumn("${invoiceline.amount}", PDFTextAlignment.RIGHT, 5F )
|
||||
.addColumn("${invoiceline.description}")
|
||||
.addColumn("${invoiceline.price}", PDFTextAlignment.RIGHT)
|
||||
.addColumn("${invoiceline.total}", PDFTextAlignment.RIGHT);
|
||||
invoiceLines.addRow()
|
||||
.addColumn("2", PDFTextAlignment.RIGHT, 5F)
|
||||
.addColumn("Anzeige Hövelhofer Rundschau")
|
||||
.addColumn("10,00 €", PDFTextAlignment.RIGHT)
|
||||
.addColumn("20,00 €", PDFTextAlignment.RIGHT);
|
||||
doc.addContent(invoiceLines);
|
||||
|
||||
TextContent test = new TextContent(doc)
|
||||
PDFTextContent test = new PDFTextContent(doc)
|
||||
.addLine("Das ist ein Test");
|
||||
doc.addContent(test);
|
||||
|
||||
@ -109,14 +107,18 @@ public class PDFDocumentTest {
|
||||
PDFTemplate pdfDoc = new PDFTemplate(template);
|
||||
|
||||
Invoice invoice = new Invoice();
|
||||
invoice.setInvoiceDate(new Date());
|
||||
invoice.setCustomerNumber("8755");
|
||||
invoice.setInvoiceNumber("1234567");
|
||||
invoice.addInvoiceLine(new InvoiceLine("Product 1", "10,00 €", "1", "10,00 €"));
|
||||
invoice.addInvoiceLine(new InvoiceLine("Product 2", "5,00 €", "10", "50,00 €"));
|
||||
invoice.addInvoiceLine(new InvoiceLine("Product 3", "100,00 €", "20", "2000,00 €"));
|
||||
|
||||
pdfDoc.addToDatamodel("invoiceDate", new Date());
|
||||
pdfDoc.addToDatamodel("customerNumber", "8755");
|
||||
pdfDoc.addToDatamodel("invoiceNumber", "1234567");
|
||||
pdfDoc.addToDatamodel("invoiceLines", invoice.getInvoiceLines());
|
||||
String fileName = "c:/temp/logo-verkehrsverein-hoevelh.jpg";
|
||||
BufferedImage image = ImageIO.read(new File(fileName));
|
||||
invoice.setLogo(ImageUtil.getEncodedString(image));
|
||||
|
||||
pdfDoc.addToDatamodel("invoice", invoice);
|
||||
pdfDoc.create("c:/temp/test.pdf");
|
||||
}
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ public class TextTest {
|
||||
+ "\"text\": \"Rechnungs-Nr.:\"\n"
|
||||
+ "}";
|
||||
|
||||
Text text = GsonUtil.getGsonInstance().fromJson(jsonString, Text.class);
|
||||
TextElement text = GsonUtil.getGsonInstance().fromJson(jsonString, TextElement.class);
|
||||
assertNotNull ("text object", text);
|
||||
assertEquals ("text value", "Rechnungs-Nr.:", text.getText());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user