generalized tests
This commit is contained in:
@ -2,6 +2,8 @@ package de.muehlencord.shared.pdf;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
@ -14,10 +16,13 @@ public class PDFImageContentTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImage() throws IOException {
|
||||
public void testImage() throws IOException, URISyntaxException {
|
||||
|
||||
URL urlLogo = PDFImageContentTest.class.getResource("logo-verkehrsverein-hoevelh.jpg");
|
||||
File imageFile = new File (urlLogo.toURI());
|
||||
|
||||
PDFDocument doc = new PDFDocument(PDFPaperSize.A4);
|
||||
PDFImageContent logoContent = new PDFImageContent(doc, 400F, 700F, 0.6F, new File("c:/temp/logo-verkehrsverein-hoevelh.jpg"));
|
||||
PDFImageContent logoContent = new PDFImageContent(doc, 400F, 700F, 0.6F, imageFile);
|
||||
|
||||
System.out.println(GsonUtil.getInstance().toJson(logoContent));
|
||||
System.out.println(GsonUtil.getInstance().toJson(logoContent));
|
||||
|
||||
@ -28,35 +28,36 @@ public class GsonSerialisation {
|
||||
PDFDocument doc = new PDFDocument(PDFPaperSize.A4);
|
||||
doc.addFont("helv12", new PDFFont("Helvetica", 12, 2));
|
||||
|
||||
PDFTableContent userList = new PDFTableContent(doc, doc.getFontByAlias("helv12"),40F, 692F);
|
||||
PDFTableContent userList = new PDFTableContent(doc, doc.getFontByAlias("helv12"), 40F, 692F);
|
||||
userList.addColumn(50, 300);
|
||||
userList.addListRow("users", "user")
|
||||
.setCellValue("${user.firstName}")
|
||||
.setCellValue("${user.lastName}");
|
||||
doc.addContent(userList);
|
||||
|
||||
doc.addContent(userList);
|
||||
|
||||
// System.out.println ("*******");
|
||||
// System.out.println (doc.toJson());
|
||||
String jsonString = doc.getTemplateString();
|
||||
File file = new File("c:/temp/users.ftlh");
|
||||
FileUtils.writeStringToFile(file, jsonString, "UTF-8");
|
||||
|
||||
System.out.println ("*******");
|
||||
System.out.println (jsonString);
|
||||
System.out.println ("*******");
|
||||
|
||||
String fileName = System.getProperty("java.io.tmpdir") + "/users.ftlh";
|
||||
File file = new File(fileName);
|
||||
FileUtils.writeStringToFile(file, jsonString, "UTF-8");
|
||||
|
||||
System.out.println("*******");
|
||||
System.out.println(jsonString);
|
||||
System.out.println("*******");
|
||||
|
||||
Configuration cfg = new Configuration(Configuration.VERSION_2_3_24);
|
||||
cfg.setDirectoryForTemplateLoading(new File("c:/temp"));
|
||||
cfg.setDirectoryForTemplateLoading(new File(System.getProperty("java.io.tmpdir")));
|
||||
cfg.setDefaultEncoding("UTF-8");
|
||||
Template template = cfg.getTemplate("users.ftlh");
|
||||
PDFTemplate pdfDoc = new PDFTemplate(template);
|
||||
List<User> users = new LinkedList<>();
|
||||
users.add (new User ("John", "Doe"));
|
||||
users.add (new User ("Jane", "Roe"));
|
||||
users.add(new User("John", "Doe"));
|
||||
users.add(new User("Jane", "Roe"));
|
||||
pdfDoc.addToDatamodel("users", users);
|
||||
pdfDoc.create("c:/temp/users.pdf");
|
||||
|
||||
|
||||
fileName = System.getProperty("java.io.tmpdir") + "/users.pdf";
|
||||
pdfDoc.create(fileName);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -20,6 +20,8 @@ import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.Date;
|
||||
import javax.imageio.ImageIO;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
@ -36,7 +38,7 @@ public class PDFDocumentTest {
|
||||
private String jsonString = null;
|
||||
|
||||
@Test
|
||||
public void testToJson() throws FileNotFoundException, IOException, ConfigurationException, TemplateException {
|
||||
public void testToJson() throws FileNotFoundException, IOException, ConfigurationException, TemplateException, URISyntaxException {
|
||||
System.out.println("testToJson");
|
||||
PDFDocument doc = new PDFDocument(PDFPaperSize.A4);
|
||||
doc.addFont("bold", new PDFFont("Helvetica-Bold", 12, 2));
|
||||
@ -104,12 +106,13 @@ public class PDFDocumentTest {
|
||||
|
||||
jsonString = doc.getTemplateString();
|
||||
|
||||
File file = new File("c:/temp/test.ftlh");
|
||||
String fileName = System.getProperty("java.io.tmpdir") + "/test.ftlh";
|
||||
File file = new File(fileName);
|
||||
FileUtils.writeStringToFile(file, jsonString, "UTF-8");
|
||||
|
||||
// create pdf
|
||||
Configuration cfg = new Configuration(Configuration.VERSION_2_3_24);
|
||||
cfg.setDirectoryForTemplateLoading(new File("c:/temp"));
|
||||
cfg.setDirectoryForTemplateLoading(new File(System.getProperty("java.io.tmpdir")));
|
||||
cfg.setDefaultEncoding("UTF-8");
|
||||
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
|
||||
cfg.setLogTemplateExceptions(false);
|
||||
@ -124,13 +127,16 @@ public class PDFDocumentTest {
|
||||
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 €"));
|
||||
|
||||
String fileName = "c:/temp/logo-verkehrsverein-hoevelh.jpg";
|
||||
BufferedImage image = ImageIO.read(new File(fileName));
|
||||
|
||||
URL urlLogo = PDFDocumentTest.class.getResource("logo-verkehrsverein-hoevelh.jpg");
|
||||
File imageFile = new File (urlLogo.toURI());
|
||||
BufferedImage image = ImageIO.read(imageFile);
|
||||
invoice.setLogo(ImageUtil.getEncodedString(image));
|
||||
|
||||
pdfDoc.addToDatamodel("invoice", invoice);
|
||||
pdfDoc.create("c:/temp/test.pdf");
|
||||
|
||||
fileName = System.getProperty("java.io.tmpdir") + "/test.pdf";
|
||||
pdfDoc.create(fileName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 4.9 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.9 KiB |
Reference in New Issue
Block a user