added mutli font support

This commit is contained in:
jomu
2016-05-03 23:10:08 +00:00
parent 4837c4b810
commit 238d46c118
10 changed files with 147 additions and 111 deletions

View File

@ -1,24 +0,0 @@
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

@ -1,18 +1,8 @@
/*
* 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.*;
/**
*
@ -31,21 +21,27 @@ public class PDFDocumentTest {
public void testToJson() {
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.setPaperSize(PaperSize.A4);
TextContent addressContent = new TextContent(40, 692, "Max Mustermann")
TextContent addressContent = new TextContent(doc, 40, 692, "Max Mustermann")
.addLine("Musterstraße 123")
.addLine("12345 Musterhausen");
doc.addContent(addressContent);
TextContent invoiceInfoInformation = new TextContent(40, 442, "Sehr geehrter Anzeigenkunde, ")
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");
doc.addContent(invoiceInfoInformation);
TextContent informationContent = new TextContent(400, 662);
informationContent.addFont("bold", new Font("Helvetica-Bold", 12, 2));
informationContent.addLine ("Anzeigenabrechnung", "bold");
TextContent informationContent = new TextContent(doc, 400, 662);
informationContent.addLine ("Anzeigenabrechnung", "bold");
informationContent.addLine ("Veronika Mühlencord", "helv12");
informationContent.addLine ("Telefon: 05257/940154", "helv12");
informationContent.addLine ("Telefax: 05257/940156", "helv12");
doc.addContent (informationContent);
System.out.println(gson.toJson(doc));
}