Updated code for removing attached document from pdf

This commit is contained in:
nisha
2024-10-29 13:15:36 +05:30
parent 97b9a521da
commit a3e027876e

View File

@@ -211,12 +211,14 @@ public class PdfDao {
// PdfPCell valueCell = new PdfPCell(new Phrase(item, valueFont)); // PdfPCell valueCell = new PdfPCell(new Phrase(item, valueFont));
PdfPCell valueCell = PdfUtils.htmlToPdfPCell(item, valueFont); PdfPCell valueCell = PdfUtils.htmlToPdfPCell(item, valueFont);
valueCell.setPadding(5f); // Increase padding for better spacing valueCell.setFixedHeight(30f); // Set a fixed height for the cell
valueCell.setPaddingLeft(10f); // Adjust left padding as needed
valueCell.setPaddingTop(0f); // Remove padding from top to allow vertical centering
valueCell.setPaddingBottom(6f);
valueCell.setPaddingLeft(leftMargin); // Increase left margin for value valueCell.setPaddingLeft(leftMargin); // Increase left margin for value
valueCell.setBorder(Rectangle.NO_BORDER); // Remove border for value cell valueCell.setBorder(Rectangle.NO_BORDER); // Remove border for value cell
valueCell.setMinimumHeight(30f);
valueCell.setVerticalAlignment(Element.ALIGN_MIDDLE); valueCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
valueCell.setCellEvent(new RoundedCorners()); // Apply rounded corners valueCell.setHorizontalAlignment(Element.ALIGN_LEFT); valueCell.setCellEvent(new RoundedCorners()); // Apply rounded corners
// Add the cell to the table // Add the cell to the table
valueTable.addCell(valueCell); valueTable.addCell(valueCell);
@@ -285,11 +287,14 @@ public class PdfDao {
} }
// PdfPCell valueCell = new PdfPCell(new Phrase(fieldValue1, valueFont)); // PdfPCell valueCell = new PdfPCell(new Phrase(fieldValue1, valueFont));
PdfPCell valueCell = PdfUtils.htmlToPdfPCell(fieldValue1, valueFont); PdfPCell valueCell = PdfUtils.htmlToPdfPCell(fieldValue1, valueFont);
valueCell.setPadding(5f); // Increase padding for better spacing valueCell.setFixedHeight(30f); // Set a fixed height for the cell
valueCell.setPaddingLeft(10f); // Adjust left padding as needed
valueCell.setPaddingTop(0f); // Remove padding from top to allow vertical centering
valueCell.setPaddingBottom(6f);
valueCell.setPaddingLeft(leftMargin); // Increase left margin for value valueCell.setPaddingLeft(leftMargin); // Increase left margin for value
valueCell.setBorder(Rectangle.NO_BORDER); // Remove border for value cell valueCell.setBorder(Rectangle.NO_BORDER); // Remove border for value cell
valueCell.setMinimumHeight(30f);
valueCell.setVerticalAlignment(Element.ALIGN_MIDDLE); valueCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
valueCell.setHorizontalAlignment(Element.ALIGN_LEFT);
valueCell.setCellEvent(new RoundedCorners()); // Apply rounded corners valueCell.setCellEvent(new RoundedCorners()); // Apply rounded corners
valueTable.addCell(valueCell); valueTable.addCell(valueCell);
document.add(valueTable); document.add(valueTable);
@@ -303,6 +308,7 @@ public class PdfDao {
// Create a PdfPTable with dynamic column count based on stateFieldMap size // Create a PdfPTable with dynamic column count based on stateFieldMap size
Map<String, String> stateFieldMap = new HashMap<>(); Map<String, String> stateFieldMap = new HashMap<>();
Map<String, Boolean> stateFieldBoolean = new HashMap<>(); Map<String, Boolean> stateFieldBoolean = new HashMap<>();
// Font textFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new BaseColor(178, 190, 181)); // Gray text
// Populate stateFieldMap from contentResponseBean settings // Populate stateFieldMap from contentResponseBean settings
contentResponseBean.getSettings().stream() contentResponseBean.getSettings().stream()
@@ -364,11 +370,14 @@ public class PdfDao {
for (String key : orderedKeys) { for (String key : orderedKeys) {
String headerValue = stateFieldMap.get(key); // Header text String headerValue = stateFieldMap.get(key); // Header text
// PdfPCell headerCell = new PdfPCell(new Phrase(headerValue)); // Create a new PdfPCell for the header // PdfPCell headerCell = new PdfPCell(new Phrase(headerValue)); // Create a new PdfPCell for the header
PdfPCell headerCell = PdfUtils.htmlToPdfPCell(headerValue, null); PdfPCell headerCell = PdfUtils.htmlToPdfPCell(headerValue, textFont);
headerCell.setHorizontalAlignment(Element.ALIGN_CENTER); // Center align headerCell.setHorizontalAlignment(Element.ALIGN_CENTER); // Center align
headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE); headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
headerCell.setBackgroundColor(new BaseColor(178, 190, 181)); // Light gray background for header headerCell.setBackgroundColor(new BaseColor(178, 190, 181)); // Light gray background for header
headerCell.setFixedHeight(30f); // Set a fixed height for the cell
headerCell.setPaddingLeft(10f); // Adjust left padding as needed
headerCell.setPaddingTop(0f); // Remove padding from top to allow vertical centering
headerCell.setPaddingBottom(6f);
table.addCell(headerCell); // Add the header cell to the table table.addCell(headerCell); // Add the header cell to the table
} }
headersAdded = true; // Prevent headers from being added again headersAdded = true; // Prevent headers from being added again
@@ -385,11 +394,13 @@ public class PdfDao {
fieldValue= String.valueOf(Utils.convertToItalianFormat(fieldValue)); fieldValue= String.valueOf(Utils.convertToItalianFormat(fieldValue));
} }
// PdfPCell dataCell = new PdfPCell(new Phrase(fieldValue != null ?fieldValue: "", textFont)); // PdfPCell dataCell = new PdfPCell(new Phrase(fieldValue != null ?fieldValue: "", textFont));
PdfPCell dataCell = PdfUtils.htmlToPdfPCell(value != null ? value.toString() : "", textFont); PdfPCell dataCell = PdfUtils.htmlToPdfPCell(fieldValue != null ? fieldValue : "", textFont);
dataCell.setBackgroundColor(new BaseColor(239, 243, 248)); // Light blue for the cell dataCell.setBackgroundColor(new BaseColor(239, 243, 248)); // Light blue for the cell
dataCell.setMinimumHeight(rowHeight); dataCell.setPaddingLeft(10f); // Adjust left padding as needed
dataCell.setPadding(7f); dataCell.setPaddingTop(0f); // Remove padding from top to allow vertical centering
dataCell.setPaddingBottom(6f);
dataCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
dataCell.setHorizontalAlignment(Element.ALIGN_LEFT);
table.addCell(dataCell); // Add the cell to the table table.addCell(dataCell); // Add the cell to the table
} }
} }
@@ -472,13 +483,7 @@ public class PdfDao {
// Process 'fileupload' and 'checkboxes' cases as in the original logic // Process 'fileupload' and 'checkboxes' cases as in the original logic
if (name.equals("fileupload")) { if (name.equals("fileupload")) {
if (fieldValue instanceof List<?> && ((List<?>) fieldValue).stream().allMatch(item -> item instanceof DocumentResponseBean)) { continue;
List<DocumentResponseBean> documentList = (List<DocumentResponseBean>) fieldValue;
List<String> names = documentList.stream()
.map(DocumentResponseBean::getName)
.collect(Collectors.toList());
fieldValue = names;
}
} else if (name.equals("checkboxes") && fieldValue instanceof List<?>) { } else if (name.equals("checkboxes") && fieldValue instanceof List<?>) {
List<String> check = (List<String>) fieldValue; List<String> check = (List<String>) fieldValue;
List<SettingResponseBean> settingResponseBeans = content.getSettings(); List<SettingResponseBean> settingResponseBeans = content.getSettings();