minor api enhancements
This commit is contained in:
@ -19,7 +19,7 @@ abstract class Content {
|
|||||||
|
|
||||||
@Expose
|
@Expose
|
||||||
protected Float y;
|
protected Float y;
|
||||||
|
|
||||||
public Content(PDFDocument document) {
|
public Content(PDFDocument document) {
|
||||||
this.document = document;
|
this.document = document;
|
||||||
this.x = null;
|
this.x = null;
|
||||||
@ -63,12 +63,12 @@ abstract class Content {
|
|||||||
public void setY(float y) {
|
public void setY(float y) {
|
||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PDRectangle getRectangle() {
|
protected PDRectangle getRectangle() {
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setRect(PDRectangle rect) {
|
protected void setRect(PDRectangle rect) {
|
||||||
this.rect = rect;
|
this.rect = rect;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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<>();
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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");
|
||||||
|
|||||||
Reference in New Issue
Block a user