basic pdf template lib

This commit is contained in:
jomu
2016-05-01 21:55:04 +00:00
parent 5cf92b57aa
commit 8fe4588555
14 changed files with 675 additions and 0 deletions

View File

@ -0,0 +1,24 @@
package de.muehlencord.shared.pdf;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType1Font;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author jomu
*/
public class ContentTest {
public ContentTest() {
}
@Test
public void testGetFont() throws ConfigurationException {
TextContent textContent = new TextContent(1,1,"Helvetica");
PDFont font = textContent.getFont("Helvetica");
assertEquals (PDType1Font.HELVETICA, font);
}
}

View File

@ -0,0 +1,53 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package de.muehlencord.shared.pdf;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author jomu
*/
public class PDFDocumentTest {
private static Gson gson;
@BeforeClass
public static void setUpClass() {
gson = GsonUtil.getGsonInstance();
}
@Test
public void testToJson() {
System.out.println("testToJson");
PDFDocument doc = new PDFDocument();
doc.setPaperSize(PaperSize.A4);
TextContent addressContent = new TextContent(40, 692, "Max Mustermann")
.addLine("Musterstraße 123")
.addLine("12345 Musterhausen");
doc.addContent(addressContent);
TextContent invoiceInfoInformation = new TextContent(40, 442, "Sehr geehrter Anzeigenkunde, ")
.addLine()
.addLine()
.addLine("Wir danken für den Auftrag und bitten um Erledigung der folgenden Anzeigenabrechnung");
doc.addContent(invoiceInfoInformation);
TextContent informationContent = new TextContent(400, 662);
informationContent.addFont("bold", new Font("Helvetica-Bold", 12, 2));
informationContent.addLine ("Anzeigenabrechnung", "bold");
System.out.println(gson.toJson(doc));
}
}

View File

@ -0,0 +1,31 @@
package de.muehlencord.shared.pdf;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateExceptionHandler;
import java.io.File;
import java.io.IOException;
import org.junit.Test;
/**
*
* @author jomu
*/
public class PDFTemplateTest {
@Test
// @Ignore // TODO get template from test resources
public void testCreate() throws IOException, ConfigurationException {
Configuration cfg = new Configuration(Configuration.VERSION_2_3_24);
cfg.setDirectoryForTemplateLoading(new File("c:/temp"));
cfg.setDefaultEncoding("UTF-8");
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
cfg.setLogTemplateExceptions(false);
Template template = cfg.getTemplate("test.ftlh");
PDFTemplate doc = new PDFTemplate(template);
doc.create ("c:/temp/test.pdf");
}
}

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="true">
<appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-5p [%c] %m%n" />
</layout>
</appender>
<logger name="org.hibernate">
<level value="warn" />
</logger>
<category name="de.muehlencord">
<priority value="DEBUG"/>
</category>
<category name="com.sun">
<priority value="WARN"/>
</category>
<category name="javax.xml">
<priority value="WARN"/>
</category>
<root>
<level value="INFO" />
<appender-ref ref="consoleAppender" />
</root>
</log4j:configuration>