Skip to content

Commit d3a9ea3

Browse files
Replace {{pages}} template with actual page number (#928)
(cherry picked from commit f13ac58)
1 parent 090cc1e commit d3a9ea3

File tree

1 file changed

+9
-35
lines changed

1 file changed

+9
-35
lines changed

java/src/main/java/com/genexus/reports/PDFReportPDFBox.java

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ public class PDFReportPDFBox extends GXReportPDFCommons{
5353
private String barcodeType = null;
5454
private PDDocument document;
5555
private PDDocumentCatalog writer;
56-
private PDPageContentStream template;
57-
private PDFormXObject formXObjecttemplate;
58-
private PDType0Font templateFont;
56+
private PDFont templateFont;
57+
private float templateX;
58+
private float templateY;
5959
public boolean lineCapProjectingSquare = true;
6060
public boolean barcode128AsImage = true;
6161
ConcurrentHashMap<String, PDImageXObject> documentImages;
@@ -813,21 +813,14 @@ else if (valign == PDFReportPDFBox.VerticalAlign.BOTTOM.value())
813813

814814
if(sTxt.trim().equalsIgnoreCase("{{Pages}}")) {
815815
if (!templateCreated) {
816-
formXObjecttemplate = new PDFormXObject(document);
817-
template = new PDPageContentStream(document, formXObjecttemplate, outputStream);
818-
formXObjecttemplate.setResources(new PDResources());
819-
formXObjecttemplate.setBBox(new PDRectangle(right - left, bottom - top));
816+
templateFont = baseFont;
817+
templateFontSize = fontSize;
818+
templateColorFill = foreColor;
819+
templateX = leftAux + leftMargin;
820+
templateY = this.pageSize.getUpperRightY() - bottomAux - topMargin - bottomMargin;
820821
templateCreated = true;
821822
}
822-
PDFormXObject form = new PDFormXObject(document);
823-
PDPageContentStream contentStream = getNewPDPageContentStream();
824-
contentStream.transform(Matrix.getTranslateInstance(leftAux + leftMargin, leftAux + leftMargin));
825-
contentStream.drawForm(form);
826-
contentStream.close();
827-
templateFont = new PDType0Font(baseFont.getCOSObject());
828-
templateFontSize = fontSize;
829-
templateColorFill = foreColor;
830-
return;
823+
sTxt = String.valueOf(this.page);
831824
}
832825

833826
float textBlockWidth = rightAux - leftAux;
@@ -1240,25 +1233,6 @@ public void GxEndDocument() {
12401233
document.addPage(new PDPage(this.pageSize));
12411234
pages++;
12421235
}
1243-
if (template != null) {
1244-
try{
1245-
template.beginText();
1246-
template.setFont(baseFont, fontSize);
1247-
template.setTextMatrix(new Matrix());
1248-
template.setNonStrokingColor(templateColorFill);
1249-
template.showText(String.valueOf(pages));
1250-
template.endText();
1251-
template.close();
1252-
for (PDPage page : document.getPages()){
1253-
try (PDPageContentStream templatePainter = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.APPEND,false)) {
1254-
templatePainter.drawForm(formXObjecttemplate);
1255-
}
1256-
}
1257-
template.close();
1258-
} catch (IOException e){
1259-
log.error("GxEndDocument: failed to apply template" , e);;
1260-
}
1261-
}
12621236
int copies = 1;
12631237
try {
12641238
copies = Integer.parseInt(printerSettings.getProperty(form, Const.COPIES));

0 commit comments

Comments
 (0)