Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 18 additions & 30 deletions java/src/main/java/com/genexus/reports/PDFReportPDFBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public class PDFReportPDFBox extends GXReportPDFCommons{
private String barcodeType = null;
private PDDocument document;
private PDDocumentCatalog writer;
private PDPageContentStream template;
private PDFormXObject formXObjecttemplate;
private PDType0Font templateFont;
private float templateX;
private float templateY;
public boolean lineCapProjectingSquare = true;
public boolean barcode128AsImage = true;
ConcurrentHashMap<String, PDImageXObject> documentImages;
Expand Down Expand Up @@ -813,20 +813,13 @@ else if (valign == PDFReportPDFBox.VerticalAlign.BOTTOM.value())

if(sTxt.trim().equalsIgnoreCase("{{Pages}}")) {
if (!templateCreated) {
formXObjecttemplate = new PDFormXObject(document);
template = new PDPageContentStream(document, formXObjecttemplate, outputStream);
formXObjecttemplate.setResources(new PDResources());
formXObjecttemplate.setBBox(new PDRectangle(right - left, bottom - top));
templateFont = new PDType0Font(baseFont.getCOSObject());
templateFontSize = fontSize;
templateColorFill = foreColor;
templateX = leftAux + leftMargin;
templateY = this.pageSize.getUpperRightY() - bottomAux - topMargin -bottomMargin;
templateCreated = true;
}
PDFormXObject form = new PDFormXObject(document);
PDPageContentStream contentStream = getNewPDPageContentStream();
contentStream.transform(Matrix.getTranslateInstance(leftAux + leftMargin, leftAux + leftMargin));
contentStream.drawForm(form);
contentStream.close();
templateFont = new PDType0Font(baseFont.getCOSObject());
templateFontSize = fontSize;
templateColorFill = foreColor;
return;
}

Expand Down Expand Up @@ -1240,23 +1233,18 @@ public void GxEndDocument() {
document.addPage(new PDPage(this.pageSize));
pages++;
}
if (template != null) {
try{
template.beginText();
template.setFont(baseFont, fontSize);
template.setTextMatrix(new Matrix());
template.setNonStrokingColor(templateColorFill);
template.showText(String.valueOf(pages));
template.endText();
template.close();
for (PDPage page : document.getPages()){
try (PDPageContentStream templatePainter = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.APPEND,false)) {
templatePainter.drawForm(formXObjecttemplate);
}
if (templateCreated) {
for (PDPage page : document.getPages()){
try (PDPageContentStream templatePainter = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.APPEND,true, true)) {
templatePainter.beginText();
templatePainter.setFont(templateFont, templateFontSize);
templatePainter.setNonStrokingColor(templateColorFill);
templatePainter.newLineAtOffset(templateX, templateY);
templatePainter.showText(String.valueOf(pages));
templatePainter.endText();
} catch (IOException e){
log.error("GxEndDocument: failed to apply template" , e);;
}
template.close();
} catch (IOException e){
log.error("GxEndDocument: failed to apply template" , e);;
}
}
int copies = 1;
Expand Down
Loading