added alignment right to tablecontent
removed obsolete variables from add content to PDF method
This commit is contained in:
@ -17,7 +17,7 @@ import org.junit.Test;
|
||||
*/
|
||||
@FixMethodOrder
|
||||
public class PDFDocumentTest {
|
||||
|
||||
|
||||
private String jsonString = null;
|
||||
|
||||
@Test
|
||||
@ -41,43 +41,55 @@ public class PDFDocumentTest {
|
||||
informationContent.addLine();
|
||||
informationContent.addLine("Hövelhof, den ${invoiceDate?date}", "bold");
|
||||
doc.addContent(informationContent);
|
||||
|
||||
TableContent informationContent2 = new TableContent (doc, doc.getStandardFont());
|
||||
|
||||
TableContent informationContent2 = new TableContent(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}");
|
||||
doc.addContent(informationContent2);
|
||||
|
||||
informationContent2.addLine("Rechnungs-Nr.:", "${invoiceNumber}");
|
||||
informationContent2.addLine("Ausgabe: ", "Dezember");
|
||||
informationContent2.addLine("Rechnungsdatum:", "${invoiceDate?date}");
|
||||
doc.addContent(informationContent2);
|
||||
|
||||
TextContent invoiceInfoInformation = new TextContent(doc, 40, 442, "Sehr geehrter Anzeigenkunde, ")
|
||||
.addLine()
|
||||
.addLine()
|
||||
.addLine("Wir danken für den Auftrag und bitten um Erledigung der folgenden Anzeigenabrechnung", TextAlignment.RIGHT)
|
||||
.addLine();
|
||||
doc.addContent(invoiceInfoInformation);
|
||||
|
||||
|
||||
TableContent invoiceLines = new TableContent(doc, doc.getFontByAlias("bold"));
|
||||
invoiceLines.getHeaders()
|
||||
.add ("Menge", 100)
|
||||
.add ("Beschreibung", 300)
|
||||
.add ("Einzelpreis", 100)
|
||||
.add ("Summe", 100, TextAlignment.RIGHT);
|
||||
invoiceLines.addLine("1","Anzeige Hövelhofer Rundschau", "10", "10");
|
||||
invoiceLines.addLine ("${invoiceline.amount}", "${invoiceline.description}", "${invoiceline.price}", "${invoiceline.total}").createList("invoiceLines", "invoiceline");
|
||||
invoiceLines.addLine("2","Anzeige Hövelhofer Rundschau", "10", "20");
|
||||
doc.addContent(invoiceLines);
|
||||
|
||||
TextContent test = new TextContent (doc)
|
||||
.addLine("Das ist ein Test");
|
||||
doc.addContent (test);
|
||||
|
||||
.add("Menge", 60)
|
||||
.add("Beschreibung", 300)
|
||||
.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));
|
||||
doc.addContent(invoiceLines);
|
||||
|
||||
TextContent test = new TextContent(doc)
|
||||
.addLine("Das ist ein Test");
|
||||
doc.addContent(test);
|
||||
|
||||
jsonString = doc.getTemplateString();
|
||||
|
||||
|
||||
File file = new File("c:/temp/test.ftlh");
|
||||
FileUtils.writeStringToFile(file, jsonString, "UTF-8");
|
||||
|
||||
|
||||
// create pdf
|
||||
Configuration cfg = new Configuration(Configuration.VERSION_2_3_24);
|
||||
cfg.setDirectoryForTemplateLoading(new File("c:/temp"));
|
||||
@ -85,14 +97,14 @@ public class PDFDocumentTest {
|
||||
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
|
||||
cfg.setLogTemplateExceptions(false);
|
||||
|
||||
Template template = cfg.getTemplate("test.ftlh");
|
||||
Template template = cfg.getTemplate("test.ftlh");
|
||||
PDFTemplate pdfDoc = new PDFTemplate(template);
|
||||
|
||||
|
||||
Invoice invoice = new Invoice();
|
||||
invoice.addInvoiceLine(new InvoiceLine ("Product 1", "10", "1", "10"));
|
||||
invoice.addInvoiceLine(new InvoiceLine ("Product 2", "5", "10", "50"));
|
||||
invoice.addInvoiceLine(new InvoiceLine ("Product 3", "100", "20", "2000"));
|
||||
|
||||
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");
|
||||
|
||||
Reference in New Issue
Block a user