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

@ -19,7 +19,7 @@ abstract class Content {
@Expose
protected Float y;
public Content(PDFDocument document) {
this.document = document;
this.x = null;
@ -63,12 +63,12 @@ abstract class Content {
public void setY(float y) {
this.y = y;
}
protected PDRectangle getRectangle() {
return rect;
}
return rect;
}
protected void setRect(PDRectangle rect) {
this.rect = rect;
}
}
}

View File

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

View File

@ -62,7 +62,7 @@ public class PDFTemplate {
pdfDoc.getPdDocument().addPage(page);
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()) {
content.setDocument(pdfDoc); // FIXME move to serialization
content.setRect(page.getMediaBox());

View File

@ -38,11 +38,10 @@ public class PDFDocumentTest {
@Test
public void testToJson() throws FileNotFoundException, IOException, ConfigurationException, TemplateException {
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("helv12", new PDFFont("Helvetica", 12, 2));
doc.setPaperSize(PDFPaperSize.A4);
PDFTextContent addressContent = new PDFTextContent(doc, 40F, 692F, "Max Mustermann")
.addLine("Musterstraße 123")
.addLine("12345 Musterhausen");