generalized tests
This commit is contained in:
@ -2,6 +2,8 @@ package de.muehlencord.shared.pdf;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.URL;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -14,10 +16,13 @@ public class PDFImageContentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@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);
|
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));
|
||||||
System.out.println(GsonUtil.getInstance().toJson(logoContent));
|
System.out.println(GsonUtil.getInstance().toJson(logoContent));
|
||||||
|
|||||||
@ -28,7 +28,7 @@ public class GsonSerialisation {
|
|||||||
PDFDocument doc = new PDFDocument(PDFPaperSize.A4);
|
PDFDocument doc = new PDFDocument(PDFPaperSize.A4);
|
||||||
doc.addFont("helv12", new PDFFont("Helvetica", 12, 2));
|
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.addColumn(50, 300);
|
||||||
userList.addListRow("users", "user")
|
userList.addListRow("users", "user")
|
||||||
.setCellValue("${user.firstName}")
|
.setCellValue("${user.firstName}")
|
||||||
@ -38,24 +38,25 @@ public class GsonSerialisation {
|
|||||||
// System.out.println ("*******");
|
// System.out.println ("*******");
|
||||||
// System.out.println (doc.toJson());
|
// System.out.println (doc.toJson());
|
||||||
String jsonString = doc.getTemplateString();
|
String jsonString = doc.getTemplateString();
|
||||||
File file = new File("c:/temp/users.ftlh");
|
String fileName = System.getProperty("java.io.tmpdir") + "/users.ftlh";
|
||||||
|
File file = new File(fileName);
|
||||||
FileUtils.writeStringToFile(file, jsonString, "UTF-8");
|
FileUtils.writeStringToFile(file, jsonString, "UTF-8");
|
||||||
|
|
||||||
System.out.println ("*******");
|
System.out.println("*******");
|
||||||
System.out.println (jsonString);
|
System.out.println(jsonString);
|
||||||
System.out.println ("*******");
|
System.out.println("*******");
|
||||||
|
|
||||||
Configuration cfg = new Configuration(Configuration.VERSION_2_3_24);
|
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.setDefaultEncoding("UTF-8");
|
||||||
Template template = cfg.getTemplate("users.ftlh");
|
Template template = cfg.getTemplate("users.ftlh");
|
||||||
PDFTemplate pdfDoc = new PDFTemplate(template);
|
PDFTemplate pdfDoc = new PDFTemplate(template);
|
||||||
List<User> users = new LinkedList<>();
|
List<User> users = new LinkedList<>();
|
||||||
users.add (new User ("John", "Doe"));
|
users.add(new User("John", "Doe"));
|
||||||
users.add (new User ("Jane", "Roe"));
|
users.add(new User("Jane", "Roe"));
|
||||||
pdfDoc.addToDatamodel("users", users);
|
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.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
@ -36,7 +38,7 @@ public class PDFDocumentTest {
|
|||||||
private String jsonString = null;
|
private String jsonString = null;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToJson() throws FileNotFoundException, IOException, ConfigurationException, TemplateException {
|
public void testToJson() throws FileNotFoundException, IOException, ConfigurationException, TemplateException, URISyntaxException {
|
||||||
System.out.println("testToJson");
|
System.out.println("testToJson");
|
||||||
PDFDocument doc = new PDFDocument(PDFPaperSize.A4);
|
PDFDocument doc = new PDFDocument(PDFPaperSize.A4);
|
||||||
doc.addFont("bold", new PDFFont("Helvetica-Bold", 12, 2));
|
doc.addFont("bold", new PDFFont("Helvetica-Bold", 12, 2));
|
||||||
@ -104,12 +106,13 @@ public class PDFDocumentTest {
|
|||||||
|
|
||||||
jsonString = doc.getTemplateString();
|
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");
|
FileUtils.writeStringToFile(file, jsonString, "UTF-8");
|
||||||
|
|
||||||
// create pdf
|
// create pdf
|
||||||
Configuration cfg = new Configuration(Configuration.VERSION_2_3_24);
|
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.setDefaultEncoding("UTF-8");
|
||||||
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
|
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
|
||||||
cfg.setLogTemplateExceptions(false);
|
cfg.setLogTemplateExceptions(false);
|
||||||
@ -125,12 +128,15 @@ public class PDFDocumentTest {
|
|||||||
invoice.addInvoiceLine(new InvoiceLine("Product 2", "5,00 €", "10", "50,00 €"));
|
invoice.addInvoiceLine(new InvoiceLine("Product 2", "5,00 €", "10", "50,00 €"));
|
||||||
invoice.addInvoiceLine(new InvoiceLine("Product 3", "100,00 €", "20", "2000,00 €"));
|
invoice.addInvoiceLine(new InvoiceLine("Product 3", "100,00 €", "20", "2000,00 €"));
|
||||||
|
|
||||||
String fileName = "c:/temp/logo-verkehrsverein-hoevelh.jpg";
|
URL urlLogo = PDFDocumentTest.class.getResource("logo-verkehrsverein-hoevelh.jpg");
|
||||||
BufferedImage image = ImageIO.read(new File(fileName));
|
File imageFile = new File (urlLogo.toURI());
|
||||||
|
BufferedImage image = ImageIO.read(imageFile);
|
||||||
invoice.setLogo(ImageUtil.getEncodedString(image));
|
invoice.setLogo(ImageUtil.getEncodedString(image));
|
||||||
|
|
||||||
pdfDoc.addToDatamodel("invoice", invoice);
|
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