Updated code for pdf tabel updation

This commit is contained in:
nisha
2024-10-28 18:11:41 +05:30
parent 9dc523a649
commit 1f3a5f8deb
2 changed files with 112 additions and 80 deletions

View File

@@ -16,6 +16,7 @@ import net.gepafin.tendermanagement.model.response.*;
import net.gepafin.tendermanagement.service.CallService;
import net.gepafin.tendermanagement.util.Utils;
import net.gepafin.tendermanagement.util.Validator;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -91,73 +92,73 @@ public class PdfDao {
Font boldSmallFont = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD,new BaseColor(105, 105, 105));
// Adding the "Documenti Allegati" section title
document.add(new Paragraph(" "));
// pageEvent.setTotalPages(writer.getPageNumber());
document.newPage();
// pageEvent.setTotalPages(writer.getPageNumber());
document.add(new Paragraph("Documenti Allegati", sectionFont));
document.add(new Paragraph(" "));
// 1. Autocertificazione possesso Requisiti
Paragraph p1 = new Paragraph();
p1.add(new Chunk("1. ", boldSmallFont));
p1.add(new Chunk("Autocertificazione possesso Requisiti ", boldSmallFont));
p1.add(new Chunk("ai sensi degli artt. 46 e 47 del DPR 445/2000", smallFont));
document.add(p1);
document.add(new Paragraph(" "));
// 2. Informativa Privacy relativa al trattamento dei dati personali
Paragraph p2 = new Paragraph();
p2.add(new Chunk("2. ", boldSmallFont));
p2.add(new Chunk("Informativa Privacy relativa al trattamento dei dati personali", boldSmallFont));
document.add(p2);
document.add(new Paragraph(" "));
// 3. Dati richiesti per la valutazione delladeguatezza dei flussi finanziari
Paragraph p3 = new Paragraph();
p3.add(new Chunk("3. ", boldSmallFont));
p3.add(new Chunk("Dati richiesti per la valutazione delladeguatezza dei flussi finanziari prospettici come da tabella di cui allAppendice 9", boldSmallFont));
document.add(p3);
document.add(new Paragraph(" "));
// 4. Rilevazione Centrale dei Rischi
Paragraph p4 = new Paragraph();
p4.add(new Chunk("4. ", boldSmallFont));
p4.add(new Chunk("Rilevazione Centrale dei Rischi riferita agli ultimi 36 mesi disponibili alla data di presentazione della Domanda", boldSmallFont));
document.add(p4);
document.add(new Paragraph(" "));
// 5. Schema di presentazione dei dati di bilancio
Paragraph p5 = new Paragraph();
p5.add(new Chunk("5. ", boldSmallFont));
p5.add(new Chunk("Schema di presentazione dei dati di bilancio", boldSmallFont));
document.add(p5);
document.add(new Paragraph(" "));
// 6. Dettagli bilanci in forma abbreviata
Paragraph p6 = new Paragraph();
p6.add(new Chunk("6. ", boldSmallFont));
p6.add(new Chunk("Dettagli bilanci in forma abbreviata", boldSmallFont));
document.add(p6);
document.add(new Paragraph(" "));
// 7. Relazione aziendale illustrativa
Paragraph p7 = new Paragraph();
p7.add(new Chunk("7. ", boldSmallFont));
p7.add(new Chunk("Relazione aziendale illustrativa", boldSmallFont));
document.add(p7);
document.add(new Paragraph(" "));
addColoredLines(writer,document,greenColor);
// document.add(new Paragraph(" "));
//
//// pageEvent.setTotalPages(writer.getPageNumber());
// document.newPage();
//// pageEvent.setTotalPages(writer.getPageNumber());
// document.add(new Paragraph("Documenti Allegati", sectionFont));
// document.add(new Paragraph(" "));
//
//
//// 1. Autocertificazione possesso Requisiti
// Paragraph p1 = new Paragraph();
// p1.add(new Chunk("1. ", boldSmallFont));
// p1.add(new Chunk("Autocertificazione possesso Requisiti ", boldSmallFont));
// p1.add(new Chunk("ai sensi degli artt. 46 e 47 del DPR 445/2000", smallFont));
// document.add(p1);
// document.add(new Paragraph(" "));
//
//
//
//// 2. Informativa Privacy relativa al trattamento dei dati personali
// Paragraph p2 = new Paragraph();
// p2.add(new Chunk("2. ", boldSmallFont));
// p2.add(new Chunk("Informativa Privacy relativa al trattamento dei dati personali", boldSmallFont));
// document.add(p2);
// document.add(new Paragraph(" "));
//
//
//// 3. Dati richiesti per la valutazione delladeguatezza dei flussi finanziari
// Paragraph p3 = new Paragraph();
// p3.add(new Chunk("3. ", boldSmallFont));
// p3.add(new Chunk("Dati richiesti per la valutazione delladeguatezza dei flussi finanziari prospettici come da tabella di cui allAppendice 9", boldSmallFont));
// document.add(p3);
// document.add(new Paragraph(" "));
//
//
//// 4. Rilevazione Centrale dei Rischi
// Paragraph p4 = new Paragraph();
// p4.add(new Chunk("4. ", boldSmallFont));
// p4.add(new Chunk("Rilevazione Centrale dei Rischi riferita agli ultimi 36 mesi disponibili alla data di presentazione della Domanda", boldSmallFont));
// document.add(p4);
// document.add(new Paragraph(" "));
//
//
//// 5. Schema di presentazione dei dati di bilancio
// Paragraph p5 = new Paragraph();
// p5.add(new Chunk("5. ", boldSmallFont));
// p5.add(new Chunk("Schema di presentazione dei dati di bilancio", boldSmallFont));
// document.add(p5);
// document.add(new Paragraph(" "));
//
//
//// 6. Dettagli bilanci in forma abbreviata
// Paragraph p6 = new Paragraph();
// p6.add(new Chunk("6. ", boldSmallFont));
// p6.add(new Chunk("Dettagli bilanci in forma abbreviata", boldSmallFont));
// document.add(p6);
// document.add(new Paragraph(" "));
//
//
//// 7. Relazione aziendale illustrativa
// Paragraph p7 = new Paragraph();
// p7.add(new Chunk("7. ", boldSmallFont));
// p7.add(new Chunk("Relazione aziendale illustrativa", boldSmallFont));
// document.add(p7);
// document.add(new Paragraph(" "));
//
// addColoredLines(writer,document,greenColor);
document.close();
@@ -272,14 +273,17 @@ public class PdfDao {
document.add(valueTable);
}
else {
PdfPCell valueCell = new PdfPCell(new Phrase(String.valueOf(value), valueFont));
String fieldValue1= (String) value;
if(Utils.isValidDateString(fieldValue1)){
fieldValue1=Utils.formatDateString(String.valueOf(value));
}
PdfPCell valueCell = new PdfPCell(new Phrase(fieldValue1, valueFont));
valueCell.setPadding(5f); // Increase padding for better spacing
valueCell.setPaddingLeft(leftMargin); // Increase left margin for value
valueCell.setBorder(Rectangle.NO_BORDER); // Remove border for value cell
valueCell.setMinimumHeight(30f);
valueCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
valueCell.setCellEvent(new RoundedCorners()); // Apply rounded corners
valueTable.addCell(valueCell);
document.add(valueTable);
}
@@ -356,6 +360,7 @@ public class PdfDao {
PdfPCell headerCell = new PdfPCell(new Phrase(headerValue)); // Create a new PdfPCell for the header
headerCell.setHorizontalAlignment(Element.ALIGN_CENTER); // Center align
headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
headerCell.setFixedHeight(rowHeight);
headerCell.setBackgroundColor(new BaseColor(178, 190, 181)); // Light gray background for header
table.addCell(headerCell); // Add the header cell to the table
@@ -364,16 +369,15 @@ public class PdfDao {
}
// Add data rows matching stateFieldMap keys
for (Map.Entry<String, String> stateField : stateFieldMap.entrySet()) {
for (String key : orderedKeys) { // Iterate over the ordered keys
for (String key : orderedKeys) {
Object value = row.getOrDefault(key, ""); // Fetch value or use empty string if key not present
PdfPCell dynamicCell = new PdfPCell(new Phrase(value != null ? value.toString() : "", textFont));
dynamicCell.setBackgroundColor(new BaseColor(239, 243, 248)); // Light blue for the cell
dynamicCell.setMinimumHeight(rowHeight);
dynamicCell.setPadding(7f);
PdfPCell dataCell = new PdfPCell(new Phrase(value != null ? value.toString() : "", textFont));
dataCell.setBackgroundColor(new BaseColor(239, 243, 248)); // Light blue for the cell
dataCell.setMinimumHeight(rowHeight);
dataCell.setFixedHeight(rowHeight);
dataCell.setPadding(7f);
table.addCell(dynamicCell); // Add the dynamically created cell to the table
}
table.addCell(dataCell); // Add the cell to the table
}
// Check if adding another row would exceed max height
@@ -494,7 +498,9 @@ public class PdfDao {
}
try {
addLabelValuePair(writer,document, contentLabel, fieldValue, labelFont,valueFont,content);
if((contentLabel!=null && Boolean.FALSE.equals(contentLabel.isEmpty())) || (fieldValue!=null && !StringUtils.isEmpty((CharSequence) fieldValue))) {
addLabelValuePair(writer, document, contentLabel, fieldValue, labelFont, valueFont, content);
}
} catch (DocumentException e) {
log.error("Error checking object: " + e.getMessage(), e);

View File

@@ -4,12 +4,18 @@ import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.security.SecureRandom;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import com.itextpdf.styledxmlparser.jsoup.Jsoup;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.commons.collections4.MapUtils;
import org.slf4j.Logger;
@@ -369,5 +375,25 @@ public class Utils {
throw new RuntimeException("Error converting map to string", e);
}
}
public static boolean isValidDateString(String dateStr) {
Pattern datePattern = Pattern.compile("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}");
return datePattern.matcher(dateStr).matches();
}
// Method to convert a valid date string to the "dd-MM-yyyy" format
public static String formatDateString(String dateStr) {
String originalFormatPattern = "yyyy-MM-dd'T'HH:mm:ss";
String targetFormatPattern = "dd-MM-yyyy";
try {
SimpleDateFormat originalFormat = new SimpleDateFormat(originalFormatPattern);
Date date = originalFormat.parse(dateStr);
SimpleDateFormat targetFormat = new SimpleDateFormat(targetFormatPattern);
return targetFormat.format(date);
} catch (ParseException e) {
log.error("error while prcoessing date formate");
return null;
}
}
}