minor api enhancements

This commit is contained in:
jomu
2016-06-20 11:09:47 +00:00
parent b58b3f6906
commit a9113ff882
5 changed files with 11 additions and 17 deletions

View File

@ -17,7 +17,7 @@ import org.apache.pdfbox.pdmodel.font.PDType1Font;
public class PDFDocument { public class PDFDocument {
@Expose @Expose
private PDFPaperSize paperSize; private final PDFPaperSize paperSize;
@Expose @Expose
protected PDFFont standardFont; protected PDFFont standardFont;
@ -30,7 +30,8 @@ public class PDFDocument {
private PDDocument pdDocument; private PDDocument pdDocument;
public PDFDocument() { public PDFDocument(PDFPaperSize ps) {
this.paperSize = ps;
this.contentList = new ArrayList<>(); this.contentList = new ArrayList<>();
this.standardFont = new PDFFont("Helvetica", 11); this.standardFont = new PDFFont("Helvetica", 11);
this.fontMap = null; this.fontMap = null;
@ -79,7 +80,6 @@ public class PDFDocument {
currentStartOfSubelement = posCloseBracket + 1; currentStartOfSubelement = posCloseBracket + 1;
String jsonSubString = templateString.substring(posOpenBracket, posCloseBracket + 1); String jsonSubString = templateString.substring(posOpenBracket, posCloseBracket + 1);
System.out.println(jsonSubString);
// insert the list values into the gson string // insert the list values into the gson string
TableRow element = GsonUtil.getGsonInstance().fromJson(jsonSubString, TableRow.class); TableRow element = GsonUtil.getGsonInstance().fromJson(jsonSubString, TableRow.class);
@ -102,7 +102,6 @@ public class PDFDocument {
templateString = newString; templateString = newString;
currentPosInTemplate += listStartString.length(); currentPosInTemplate += listStartString.length();
currentPosInTemplate += listEndString.length(); currentPosInTemplate += listEndString.length();
System.out.println(templateString.substring(posOpenBracket-10, posCloseBracket + listStartString.length() + listEndString.length()+10));
} }
} }
} }
@ -150,10 +149,6 @@ public class PDFDocument {
return paperSize; return paperSize;
} }
public void setPaperSize(PDFPaperSize paperSize) {
this.paperSize = paperSize;
}
public PDFFont getStandardFont() { public PDFFont getStandardFont() {
return standardFont; return standardFont;
} }

View File

@ -31,7 +31,7 @@ public class PDFTableContent extends Content {
} }
public PDFTableContent(PDFDocument doc, PDFFont hf, int x, int y) { public PDFTableContent(PDFDocument doc, PDFFont hf, float x, float y) {
super(doc, x, y); super(doc, x, y);
this.columSizes = new ArrayList<>(); this.columSizes = new ArrayList<>();
this.data = new ArrayList<>(); this.data = new ArrayList<>();

View File

@ -62,7 +62,7 @@ public class PDFTemplate {
pdfDoc.getPdDocument().addPage(page); pdfDoc.getPdDocument().addPage(page);
PDPageContentStream cos = new PDPageContentStream(pdfDoc.getPdDocument(), page, AppendMode.APPEND, false); PDPageContentStream cos = new PDPageContentStream(pdfDoc.getPdDocument(), page, AppendMode.APPEND, false);
Coordinate coord = null; Coordinate coord = new Coordinate(page.getMediaBox().getLowerLeftX(), page.getMediaBox().getUpperRightY());
for (Content content : pdfDoc.getContentList()) { for (Content content : pdfDoc.getContentList()) {
content.setDocument(pdfDoc); // FIXME move to serialization content.setDocument(pdfDoc); // FIXME move to serialization
content.setRect(page.getMediaBox()); content.setRect(page.getMediaBox());

View File

@ -38,11 +38,10 @@ public class PDFDocumentTest {
@Test @Test
public void testToJson() throws FileNotFoundException, IOException, ConfigurationException, TemplateException { public void testToJson() throws FileNotFoundException, IOException, ConfigurationException, TemplateException {
System.out.println("testToJson"); System.out.println("testToJson");
PDFDocument doc = new PDFDocument(); PDFDocument doc = new PDFDocument(PDFPaperSize.A4);
doc.addFont("bold", new PDFFont("Helvetica-Bold", 12, 2)); doc.addFont("bold", new PDFFont("Helvetica-Bold", 12, 2));
doc.addFont("helv12", new PDFFont("Helvetica", 12, 2)); doc.addFont("helv12", new PDFFont("Helvetica", 12, 2));
doc.setPaperSize(PDFPaperSize.A4);
PDFTextContent addressContent = new PDFTextContent(doc, 40F, 692F, "Max Mustermann") PDFTextContent addressContent = new PDFTextContent(doc, 40F, 692F, "Max Mustermann")
.addLine("Musterstraße 123") .addLine("Musterstraße 123")
.addLine("12345 Musterhausen"); .addLine("12345 Musterhausen");