Done ticket

This commit is contained in:
nisha
2024-10-12 15:43:38 +05:30
parent 90aae05fa4
commit b6f16d388e
9 changed files with 833 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
package net.gepafin.tendermanagement.model.request;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.ColumnText;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfPageEventHelper;
import com.itextpdf.text.pdf.PdfWriter;
public class CustomPageEvent extends PdfPageEventHelper {
private String title;
private int totalPages;
public CustomPageEvent(String title, int totalPages) {
this.title = title;
this.totalPages = totalPages;
}
@Override
public void onEndPage(PdfWriter writer, Document document) {
PdfContentByte canvas = writer.getDirectContent();
// Header - Add a title to each page at the top
if (writer.getPageNumber() > 1) {
Font headerFont = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD, new BaseColor(113, 121, 126)); // Gray color for header
ColumnText.showTextAligned(
canvas,
Element.ALIGN_LEFT,
new Phrase(title, headerFont),
document.leftMargin(), // Use left margin to align fully to the left
document.getPageSize().getHeight() - 30, // Positioning header near top
0 // No rotation
);
}
// Footer - Add page number at the bottom
String footerText = String.format("Page %d of %d", writer.getPageNumber(), totalPages);
// Set font for the footer
Font footerFont = new Font(Font.FontFamily.HELVETICA, 10, Font.NORMAL, BaseColor.BLACK);
// Positioning footer near bottom
ColumnText.showTextAligned(writer.getDirectContent(),
Element.ALIGN_LEFT,
new Phrase(footerText, footerFont),
(document.right() + document.left()) / 2,
document.bottomMargin() - 10, // Positioning footer near bottom
0);
// Draw a yellow line below header
if (writer.getPageNumber() > 1) {
canvas.setLineWidth(1.5f);
canvas.setColorStroke(new BaseColor(255, 219, 88)); // Yellow color
float yPos = document.getPageSize().getHeight() - 50f; // Position for the line below header
canvas.moveTo(0, yPos);
canvas.lineTo(document.getPageSize().getWidth(), yPos);
canvas.stroke();
}
// Draw another line 50 points above the bottom of the document
canvas.setLineWidth(1.5f);
canvas.setColorStroke(new BaseColor(255, 219, 88)); // Yellow color
float lineYPos = document.bottomMargin() + 25f; // Position for the line above the bottom margin
canvas.moveTo(0, lineYPos);
canvas.lineTo(document.getPageSize().getWidth(), lineYPos);
canvas.stroke();
}
public void setTotalPages(int totalPages) {
this.totalPages = totalPages;
}
}