Merge pull request #342 from Kitzanos/pdf-spacing-issue-prod

Cherry-pick (Fixed PDF spacing issue)
This commit is contained in:
Rinaldo
2025-09-12 12:14:35 +02:00
committed by GitHub
2 changed files with 33 additions and 15 deletions

View File

@@ -40,7 +40,7 @@ import java.util.stream.Collectors;
@Component
public class PdfDao {
@Value("${default.hub.pdf.banner}")
@Value("${default.pdf.banner}")
private String defaultLogoUrl;
@Autowired
@@ -77,16 +77,20 @@ public class PdfDao {
// CustomPageEvent pageEvent = new CustomPageEvent(call.getName(), 0);
// writer.setPageEvent(pageEvent);
document.open();
String logoUrl=defaultLogoUrl;
String logoUrl=null;
Optional<HubEntity> hubEntity=hubRepository.findById(applicationEntity.getHubId());
if(hubEntity.isPresent()) {
if (Boolean.TRUE.equals(validator.isProductionProfileActivated()) && applicationEntity.getCall().getId().equals(23l)) {
logoUrl=defaultLogoUrl;
}
else if(hubEntity.isPresent()) {
if (hubEntity.get().getUniqueUuid().equals("p4lk3bcx1RStqTaIVVbXs")) {
defaultLogoUrl = hubEntity.get().getPdfBanner();
}
if (hubEntity.get().getUniqueUuid().equals("t7jh5wfg9QXylNaTZkPoE")) {
defaultLogoUrl = hubEntity.get().getPdfBanner();
}
logoUrl=defaultLogoUrl;
}
// pageEvent.setTotalPages(writer.getPageNumber());
// addLogo(document, "logo.jpg"); // Add your image path here the migration code after cherry-pick
@@ -112,7 +116,7 @@ public class PdfDao {
ApplicationGetResponseBean applicationGetResponseBean=applicationDao.getApplicationByFormId(request, applicationId, null);
for(FormApplicationResponse formApplicationResponse: applicationGetResponseBean.getForm()) {
List<FieldLabelValuePairRequest> fieldLabelValuePairRequests = getFormFieldsToLabels(formApplicationResponse,writer,document);
List<FieldLabelValuePairRequest> fieldLabelValuePairRequests = getFormFieldsToLabels(formApplicationResponse,writer,document,applicationEntity);
addColoredLines(writer,document,greenColor);
document.add(new Paragraph(" ")); // Add line break
}
@@ -132,10 +136,16 @@ public class PdfDao {
return null;
}
private void addLabelValuePair(PdfWriter writer,Document document, String label, Object value, Font labelFont,Font valueFont,ContentResponseBean contentResponseBean) throws DocumentException {
private void addLabelValuePair(PdfWriter writer,Document document, String label, Object value, Font labelFont,Font valueFont,ContentResponseBean contentResponseBean, ApplicationEntity applicationEntity) throws DocumentException {
// Add label
Map<String, Boolean> stateFieldMap= new HashMap<>();
if (Boolean.TRUE.equals(validator.isProductionProfileActivated()) && applicationEntity.getCall().getId().equals(23l)) {
for (SettingResponseBean settingResponseBean : contentResponseBean.getSettings()) {
if (settingResponseBean.getName().equals("isRequestedAmount") && settingResponseBean.getValue().equals(Boolean.TRUE)) {
return;
}
}
}
Paragraph labelParagraph = new Paragraph(label, labelFont);
labelParagraph.setSpacingAfter(-10f);
document.add(labelParagraph);
@@ -151,10 +161,10 @@ public class PdfDao {
// Define start and end points for the line (relative to the page size and margins)
if (yPos <= 140) {
// If xEnd is less than or equal to 200, generate a new page
document.newPage();
} // Add a gap between the label and value
// if (yPos <= 140) {
// // If xEnd is less than or equal to 200, generate a new page
// document.newPage();
// } // Add a gap between the label and value
document.add(new Paragraph(" ")); // Adding an empty paragraph for spacing
// Create value cell with rounded corners
PdfPTable valueTable = new PdfPTable(1);
@@ -268,6 +278,7 @@ public class PdfDao {
document.add(valueTable);
}
else {
if (value instanceof String) {
String fieldValue1 = (String) value;
if (Utils.isValidDateString(fieldValue1)) {
@@ -503,7 +514,7 @@ public class PdfDao {
canvas.stroke();
}
}
public List<FieldLabelValuePairRequest> getFormFieldsToLabels(FormApplicationResponse responseBean,PdfWriter writer,Document document) {
public List<FieldLabelValuePairRequest> getFormFieldsToLabels(FormApplicationResponse responseBean,PdfWriter writer,Document document,ApplicationEntity applicationEntity) {
List<FieldLabelValuePairRequest> labelValuePairs = new ArrayList<>();
Font labelFont = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12,new BaseColor(113,121,126)); // Light grey);
@@ -547,13 +558,20 @@ public class PdfDao {
labelCell.setBorder(Rectangle.NO_BORDER);
labelCell.setGrayFill(7);
labelCell.setPadding(5);
labelParagraph.setSpacingAfter(-10f);
labelCell.setNoWrap(false); // wrap long text
labelCell.setUseAscender(true);
labelCell.setUseDescender(true); // allow text wrapping
// Create a PdfPTable with 1 column and add the PdfPCell to it
PdfPTable table = new PdfPTable(1);
table.setWidthPercentage(100);
table.addCell(labelCell);
table.setSplitLate(false);
table.setSplitRows(true);
table.setKeepTogether(false);
labelCell.setMinimumHeight(0);
labelParagraph.add(table);
try {
document.add(labelParagraph);
@@ -618,7 +636,7 @@ public class PdfDao {
if((contentLabel==null || StringUtils.isEmpty(contentLabel)) && (fieldValue==null || StringUtils.isEmpty(fieldValue.toString()))) {
continue;
}
addLabelValuePair(writer, document, contentLabel, fieldValue, labelFont, valueFont, content);
addLabelValuePair(writer, document, contentLabel, fieldValue, labelFont, valueFont, content,applicationEntity);
} catch (DocumentException e) {
log.error("Error checking object: " + e.getMessage(), e);

View File

@@ -67,7 +67,7 @@ api.pecUrl=https://ws.pecmassiva.com
application.amendment.expiration.days=30
default.email.signature=Gepafin S.p.a
default.hub.pdf.banner=https://mementoresources.s3.amazonaws.com/gepafin/staging/template/gepafin-logo.jpg
default.pdf.banner=https://mementoresources.s3.amazonaws.com/gepafin/production/template/gepafin-logo-only.jpg
#feign client config
spring.cloud.openfeign.client.config.default.connectTimeout=300000