• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hazendaz / displaytag / 1753

12 Feb 2026 03:17AM UTC coverage: 77.321% (-0.01%) from 77.334%
1753

push

github

web-flow
Merge pull request #1102 from hazendaz/renovate/javax-support-logback-monorepo

Update dependency ch.qos.logback:logback-classic to v1.5.29 (javax-support)

1438 of 2003 branches covered (71.79%)

Branch coverage included in aggregate %.

4034 of 5074 relevant lines covered (79.5%)

0.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.83
/displaytag/src/main/java/org/displaytag/export/DefaultPdfExportView.java
1
/*
2
 * SPDX-License-Identifier: MIT
3
 * See LICENSE file for details.
4
 *
5
 * Copyright 2002-2026 Fabrizio Giustina, the Displaytag team
6
 */
7
package org.displaytag.export;
8

9
import com.itextpdf.text.Document;
10
import com.itextpdf.text.DocumentException;
11
import com.itextpdf.text.pdf.BaseFont;
12
import com.itextpdf.text.pdf.PdfContentByte;
13
import com.itextpdf.text.pdf.PdfPTable;
14
import com.itextpdf.text.pdf.PdfPageEventHelper;
15
import com.itextpdf.text.pdf.PdfTemplate;
16
import com.itextpdf.text.pdf.PdfWriter;
17

18
import java.io.IOException;
19
import java.io.OutputStream;
20

21
/**
22
 * PDF exporter using iText.
23
 */
24
public class DefaultPdfExportView extends DefaultItextExportView {
1✔
25

26
    /**
27
     * Gets the mime type.
28
     *
29
     * @return "application/pdf"
30
     *
31
     * @see org.displaytag.export.BaseExportView#getMimeType()
32
     */
33
    @Override
34
    public String getMimeType() {
35
        return "application/pdf"; //$NON-NLS-1$
1✔
36
    }
37

38
    /**
39
     * Initializes the PDF writer this export view uses to write the table document.
40
     *
41
     * @param document
42
     *            The iText document to be written.
43
     * @param out
44
     *            The output stream to which the document is written.
45
     *
46
     * @throws DocumentException
47
     *             If something goes wrong during initialization.
48
     */
49
    @Override
50
    protected void initItextWriter(final Document document, final OutputStream out) throws DocumentException {
51
        PdfWriter.getInstance(document, out).setPageEvent(new PageNumber());
1✔
52
    }
1✔
53

54
    /**
55
     * Prints a page number at the bottom of each page. Based on
56
     * http://itextdocs.lowagie.com/examples/com/lowagie/examples/directcontent/pageevents/PageNumbersWatermark.java
57
     */
58
    private static class PageNumber extends PdfPageEventHelper {
59

60
        /**
61
         * On end page.
62
         *
63
         * @param writer
64
         *            the writer
65
         * @param document
66
         *            the document
67
         *
68
         * @see com.lowagie.text.pdf.PdfPageEventHelper#onEndPage(com.lowagie.text.pdf.PdfWriter,
69
         *      com.lowagie.text.Document)
70
         */
71
        @Override
72
        public void onEndPage(final PdfWriter writer, final Document document) {
73
            // The header table
74
            final PdfPTable table = new PdfPTable(2);
1✔
75
            // A template that will hold the total number of pages.
76
            final PdfTemplate tpl = writer.getDirectContent().createTemplate(100, 100);
1✔
77
            // The font that will be used.
78
            BaseFont helv = null;
1✔
79
            try {
80
                helv = BaseFont.createFont("Helvetica", BaseFont.WINANSI, false);
1✔
81
            } catch (DocumentException | IOException e) {
×
82
            }
1✔
83
            final PdfContentByte cb = writer.getDirectContent();
1✔
84
            // write the headertable
85
            table.setTotalWidth(document.right() - document.left());
1✔
86
            table.writeSelectedRows(0, -1, document.left(), document.getPageSize().getHeight() - 50, cb);
1✔
87
            // compose the footer
88
            final String text = "Page " + writer.getPageNumber();
1✔
89
            final float textSize = helv.getWidthPoint(text, 12);
1✔
90
            final float textBase = document.bottom() - 20;
1✔
91
            cb.beginText();
1✔
92
            cb.setFontAndSize(helv, 12);
1✔
93
            final float adjust = helv.getWidthPoint("0", 12);
1✔
94
            cb.setTextMatrix(document.right() - textSize - adjust, textBase);
1✔
95
            cb.showText(text);
1✔
96
            cb.endText();
1✔
97
            cb.addTemplate(tpl, document.right() - adjust, textBase);
1✔
98
        }
1✔
99
    }
100
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc